A full-stack real-time chat application built using the MERN stack with Socket.io for instant messaging and live user presence tracking.
This project demonstrates real-world backend architecture, authentication, protected routes, REST APIs, and real-time bidirectional communication.
- 🔐 JWT Authentication (Signup / Login)
- 💬 Real-time messaging with Socket.io
- 🟢 Online / Offline user status
- 📩 Private one-to-one conversations
- 🧠 Persistent chat history (MongoDB)
- 🔒 Protected API routes
- ⚡ Zustand state management (Frontend)
- 📦 Modular backend architecture (MVC pattern)
- React (Vite)
- Zustand (State Management)
- Axios
- Socket.io-client
- CSS
- Node.js
- Express.js
- MongoDB + Mongoose
- Socket.io
- JWT (Authentication)
- Middleware-based architecture
root/
├── backend/
│ └── src/
│ ├── controllers/
│ ├── routes/
│ ├── models/
│ ├── middleware/
│ └── server.js
│
├── frontend/
│ └── src/
│ ├── components/
│ ├── pages/
│ ├── store/
│ └── App.jsx
git clone https://github.com/your-username/chat-app.git
cd chat-app
cd backend
npm install
Create a .env file inside backend folder:
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_key
Start backend server:
npm run dev
Server runs on:
http://localhost:5000
Open a new terminal:
cd frontend
npm install
npm run dev
Frontend runs on:
http://localhost:5173
- User registers → password hashed → JWT generated
- Token stored in HTTP-only cookie
- Protected routes verify JWT
- Socket authentication middleware validates user before connection
- User connects to Socket.io server
- Middleware authenticates socket connection
- Users are stored in online users map
- Messages emitted to specific user socket ID
- Message saved to MongoDB
- Receiver gets real-time update
- Real-time WebSocket communication
- Secure authentication using JWT
- Scalable backend folder architecture
- State management using Zustand
- Middleware chaining in Express
- Linux & Git command practice
- Proper Git workflow (commit, branch, push)
Shakshyam Pandey B.Tech Student | MERN Stack Developer