- Overview
- Features
- Tech Stack
- Architecture
- Project Structure
- Getting Started
- Environment Variables
- API Reference
- Socket Events
- Screenshots
- Roadmap
- Deployment
- Author
ChatApp is a production-ready, full-stack real-time chat application that enables seamless instant messaging between users. Built on a modern JavaScript ecosystem, it demonstrates best practices in:
- ⚡ Real-time WebSocket communication
- 🔐 Secure JWT authentication
- 🏗️ Scalable REST API design
- 🎨 Modern React frontend architecture of website
Whether you're exploring WebSocket-based communication or using this as a foundation for your own project, ChatApp covers the fundamentals with clean, readable, well-structured code.
💡 Key highlight: Every message is delivered instantly via Socket.io — no polling, no delays, no refresh needed in Chats.
|
|
┌─────────────────────────────────────────────────────────┐
│ CLIENT (React) │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────────────────┐ │
│ │AuthContext│ │ChatContext│ │Pages / Components │ │
│ └────┬─────┘ └────┬─────┘ └──────────────────────┘ │
│ │ │ │
│ │ Axios │ Socket.io Client │
└───────┼──────────────┼───────────────────────────────────┘
│ │
▼ ▼
┌───────────────────────────────────────────────┐
│ SERVER (Node + Express) │
│ │
│ ┌──────────┐ ┌──────────┐ ┌────────────┐ │
│ │ Routes │→ │Controllers│→ │ Middleware │ │
│ └──────────┘ └────┬─────┘ └────────────┘ │
│ │ │
│ ┌─────────────┼──────────────┐ │
│ ▼ ▼ ▼ │
│ ┌─────────┐ ┌──────────┐ ┌──────────┐ │
│ │ MongoDB │ │Socket.io │ │Cloudinary│ │
│ │(Mongoose)│ │ Server │ │ CDN │ │
│ └─────────┘ └──────────┘ └──────────┘ │
└───────────────────────────────────────────────┘
Data Flow:
- Client sends HTTP requests via Axios → Express route → Controller → MongoDB
- Real-time events travel over WebSocket (Socket.io) bidirectionally
- Profile images upload to Cloudinary and the URL is stored in MongoDB
ChatApp/
│
├── 📁 client/ # ⚛️ React frontend (Vite)
│ ├── 📁 context/
│ │ ├── AuthContext.jsx # 🔐 Auth state & actions
│ │ └── ChatContext.jsx # 💬 Chat state & socket events
│ │
│ └── 📁 src/
│ ├── 📁 assets/ # 🖼️ Static assets
│ ├── 📁 components/
│ │ ├── ChatContainer.jsx # 💬 Main message window and chats
│ │ ├── Sidebar.jsx # 👥 User list & search bar
│ │ └── RightSidebar.jsx # ℹ️ Selected user info panel
│ │
│ ├── 📁 pages/
│ │ ├── HomePage.jsx # 🏠 Main chat layout
│ │ ├── LoginPage.jsx # 🔑 Auth page (login/signup)
│ │ └── ProfilePage.jsx # 👤 Profile management
│ │
│ ├── App.jsx # 🔀 Routes & context providers
│ ├── main.jsx # 🚀 React entry point
│ └── index.css # 🎨 Global styles
│
├── 📁 server/ # 🟢 Node.js backend
│ ├── 📁 controllers/
│ │ ├── messageController.js # 📨 Message send/get logic
│ │ └── userController.js # 👤 User auth & profile logic
│ │
│ ├── 📁 middleware/
│ │ └── auth.js # 🛡️ JWT verification middleware
│ │
│ ├── 📁 models/
│ │ ├── Message.js # 📄 Message Mongoose schema
│ │ └── User.js # 📄 User Mongoose schema
│ │
│ ├── 📁 routes/
│ │ ├── messageRoutes.js # 📡 /api/messages/* endpoints
│ │ └── userRoutes.js # 📡 /api/users/* endpoints
│ │
│ ├── 📁 lib/
│ │ ├── db.js # 🗄️ MongoDB connection setup
│ │ ├── cloudinary.js # ☁️ Cloudinary config
│ │ └── utils.js # 🔧 Helper utilities
│ │
│ └── server.js # ⚡ Express + Socket.io entry
│
└── README.md
| Tool | Version | Link |
|---|---|---|
v18+ |
nodejs.org | |
v9+ |
npmjs.com | |
| Latest | git-scm.com | |
| Free tier | mongodb.com/atlas | |
| Free tier | cloudinary.com |
① Clone the repository
git clone https://github.com/Riyaban583/ChatApp.git
cd ChatApp② Install dependencies
# Backend
cd server && npm install
# Frontend
cd ../client && npm install③ Configure environment variables
# Create .env in /server (see Environment Variables section)
touch server/.env④ Run the application
# Terminal 1 — Backend
cd server && npm run dev
# Terminal 2 — Frontend
cd client && npm run dev⑤ Open in browser
| Service | URL |
|---|---|
| 🌐 Frontend | http://localhost:5173 |
| ⚙️ Backend API | http://localhost:5000 |
Create a .env file inside the /server folder:
# ┌─────────────────────────────────────┐
# │ SERVER CONFIG │
# └─────────────────────────────────────┘
PORT=5000
# ┌─────────────────────────────────────┐
# │ DATABASE (MongoDB) │
# └─────────────────────────────────────┘
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/chatapp
# ┌─────────────────────────────────────┐
# │ AUTHENTICATION (JWT) │
# └─────────────────────────────────────┘
JWT_SECRET=your_super_secret_key_here_make_it_long_and_random
# ┌─────────────────────────────────────┐
# │ IMAGE STORAGE (Cloudinary) │
# └─────────────────────────────────────┘
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
⚠️ Security Warning: Never commit.envto version control. Add it to.gitignoreand rotate any secrets that are accidentally exposed.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/users/signup |
❌ Public | Register a new user |
POST |
/api/users/login |
❌ Public | Login and receive JWT token |
GET |
/api/users/check |
✅ JWT | Verify current auth token |
PUT |
/api/users/update-profile |
✅ JWT | Update profile name / avatar |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/messages/send |
✅ JWT | Send a new message |
GET |
/api/messages/:id |
✅ JWT | Fetch full conversation history |
✅ Protected routes require
Authorization: Bearer <token>in the request header.
Client ──────────────────────────────────────── Server
│ │
│──── connection ────────────────────────────► │
│ │
│ ◄──── getOnlineUsers [ userId[] ] ────────── │
│ │
│──── sendMessage { to, text } ──────────────► │
│ │
│ ◄──── newMessage { from, text, timestamp } ─ │
│ │
│──── disconnect ─────────────────────────────► │
│ │
│ ◄──── getOnlineUsers (updated) ───────────── │
| Event | Direction | Payload | Description |
|---|---|---|---|
connection |
Client → Server | — | User establishes WebSocket connection |
getOnlineUsers |
Server → Client | userId[] |
Broadcasts updated list of online users |
newMessage |
Server → Client | message |
Delivers incoming message in real time |
disconnect |
Client → Server | — | User disconnects; status updated for all |
Completed ✅
- 💬 Real-time messaging via Socket.io
- 🔐 JWT authentication & protected routes
- 🖼️ Profile image upload (Cloudinary)
- 🟢 Live online/offline status indicators
- 📩 Unread message counters
- 🔍 User search by name
Coming Soon 🚧
- ⌨️ Typing indicators
- ✅ Message read receipts (seen status)
- 👥 Group chat rooms
- 📎 File & media attachment sharing
- 🔔 Browser push notifications
- 🎥 Voice & video calling (WebRTC)
- 🌙 Dark / light mode toggle
- 📱 Progressive Web App (PWA) support
- 🌍 Multi-language support (i18n) in chat app
| Platform | Notes |
|---|---|
| Zero config for Vite, instant deploys, recommended | |
| Great free tier, good alternative |
| Platform | Notes |
|---|---|
| Free tier available, recommended for beginners | |
| Simple deploys, excellent DX | |
| Production-grade, full control |
💡 Pro Tip: Set all environment variables in your hosting provider's settings dashboard — never hardcode secrets in your codebase.
