A full-stack real-time chat application built with the MERN ecosystem. The project provides secure user authentication, one-to-one messaging, real-time message delivery, image sharing, profile customization, and a responsive modern interface.
The application is designed as a practical full-stack project demonstrating how a React frontend communicates with a Node.js/Express backend, how authentication is handled with JWT, how chat data is stored in MongoDB, and how real-time communication is implemented using Socket.IO.
- User registration and login
- Password hashing using bcrypt
- JWT-based authentication
- JWT stored in HTTP cookies
- Protected routes using authentication middleware
- Logout functionality
- Persistent authentication state
- One-to-one private conversations
- Send and receive messages in real time
- Message history stored in MongoDB
- Real-time message delivery using Socket.IO
- Automatically identifies connected users
- Sidebar displaying available users for chatting
- Send images inside conversations
- Images are uploaded to Cloudinary
- Secure Cloudinary URLs are stored with messages
- Profile pictures can also be uploaded and updated through Cloudinary
- User profile page
- Custom profile picture
- User information stored in MongoDB
- Profile updates for authenticated users
-
Built with React
-
Responsive chat interface
-
Tailwind CSS styling
-
DaisyUI components
-
Lucide icons
-
Toast notifications
-
Multiple application pages including:
- Login
- Sign Up
- Home / Chat
- Profile
- Settings
Application state is managed using Zustand, with separate stores for:
- Authentication
- Chat state
- Theme/settings
| Technology | Purpose |
|---|---|
| React | UI development |
| Vite | Frontend development/build tool |
| React Router | Client-side routing |
| Tailwind CSS | Styling |
| DaisyUI | UI components |
| Zustand | State management |
| Axios | API requests |
| Socket.IO Client | Real-time communication |
| React Hot Toast | Notifications |
| Lucide React | Icons |
| Technology | Purpose |
|---|---|
| Node.js | Runtime |
| Express.js | REST API |
| MongoDB | Database |
| Mongoose | MongoDB ODM |
| Socket.IO | Real-time communication |
| JWT | Authentication |
| bcryptjs | Password hashing |
| Cloudinary | Image storage |
| Cookie Parser | Cookie handling |
| CORS | Cross-origin requests |
| dotenv | Environment variables |
| Nodemon | Development server |
The backend dependencies and architecture are organized around controllers, models, routes, middleware and supporting libraries.
┌─────────────────────┐
│ React UI │
│ │
│ React + Vite │
│ Tailwind + DaisyUI │
│ Zustand │
└──────────┬──────────┘
│
HTTP / REST API
│
▼
┌─────────────────────┐
│ Express Server │
│ │
│ Authentication │
│ Message APIs │
│ Middleware │
└──────────┬──────────┘
│
┌─────────────────┼─────────────────┐
│ │ │
▼ ▼ ▼
MongoDB Socket.IO Cloudinary
Database Real-time Image Storage
Events
User A
│
│ Send message
▼
React Frontend
│
│ POST request
▼
Express API
│
├── Authenticate user
│
├── Save message
│ │
│ ▼
│ MongoDB
│
└── Socket.IO
│
│ newMessage event
▼
User B
When a message is sent, the backend stores it in MongoDB and uses Socket.IO to immediately emit the new message to the recipient if they are connected.
chat-app/
│
├── backend/
│ ├── src/
│ │ ├── controllers/
│ │ │ ├── auth.controllers.js
│ │ │ └── message.controller.js
│ │ │
│ │ ├── lib/
│ │ │ ├── cloudinary.js
│ │ │ ├── db.js
│ │ │ ├── socket.js
│ │ │ └── utils.js
│ │ │
│ │ ├── middleware/
│ │ │ └── auth.middleware.js
│ │ │
│ │ ├── models/
│ │ │ ├── user.model.js
│ │ │ └── message.model.js
│ │ │
│ │ ├── routes/
│ │ │ ├── auth.route.js
│ │ │ └── message.route.js
│ │ │
│ │ └── index.js
│ │
│ └── package.json
│
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ ├── constants/
│ │ ├── lib/
│ │ ├── pages/
│ │ ├── store/
│ │ ├── App.jsx
│ │ ├── index.css
│ │ └── main.jsx
│ │
│ └── package.json
│
├── package.json
└── README.md
The repository follows a clear frontend/backend separation, while the backend itself is divided into controllers, models, routes, middleware and supporting libraries.
Before running the project, make sure you have:
- Node.js installed
- npm installed
- A MongoDB database
- A Cloudinary account
- Git
git clone https://github.com/kul-91/chat-app.git
cd chat-appYou can install the frontend and backend dependencies from the root directory:
npm run buildThe root build script installs dependencies for both the backend and frontend and then builds the frontend.
Alternatively, install them separately:
cd backend
npm installcd ../frontend
npm installCreate a .env file inside the backend directory.
PORT=5001
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secretImportant: Never commit your
.envfile or expose your API keys and secrets publicly.
Open a terminal:
cd backend
npm run devThe backend development server uses Nodemon for automatic restarts.
Open another terminal:
cd frontend
npm run devVite will start the frontend development server.
Open the URL displayed by Vite in your browser.
npm run buildInstalls backend and frontend dependencies and creates the frontend production build.
npm startStarts the backend application.
npm run devStarts the backend using Nodemon.
npm startStarts the backend using Node.js.
npm run devStarts the Vite development server.
npm run buildCreates a production build.
npm run previewPreviews the production build.
npm run lintRuns ESLint.
The application uses JWT-based authentication.
Sign Up / Login
│
▼
Express Authentication API
│
├── Validate credentials
│
├── Hash / compare password
│
└── Generate JWT
│
▼
Cookie
│
▼
Protected API Requests
│
▼
Authentication Middleware
│
▼
req.user
Passwords are hashed with bcrypt before being stored, while JWT tokens are generated during authentication and stored through cookies.
Users can select another user from the chat sidebar and start a private conversation.
Messages support:
- Text
- Images
When an image is sent, it is uploaded to Cloudinary and the resulting secure URL is associated with the message.
Real-time delivery is handled using Socket.IO:
Sender
│
│ message
▼
Backend
│
├── Save → MongoDB
│
└── Emit → Socket.IO
│
▼
Receiver
MongoDB is used as the primary database.
The project currently uses two main models:
Stores user information such as:
- Name
- Password hash
- Profile picture
Stores conversation information such as:
- Sender
- Receiver
- Text
- Image
- Message data
The backend uses Mongoose to interact with MongoDB.
POST /api/auth/signup
POST /api/auth/login
POST /api/auth/logout
PUT /api/auth/update-profile
GET /api/auth/check
GET /api/messages/users
GET /api/messages/:id
POST /api/messages/send/:id
The exact API base paths should be checked against the route configuration if you modify the backend routing structure.
This project is useful for learning how a production-style full-stack application is structured.
It demonstrates:
- REST API development
- Authentication and authorization
- JWT authentication
- HTTP cookies
- Password hashing
- MongoDB data modeling
- Mongoose
- Express middleware
- React component architecture
- Client-side routing
- Global state management
- Real-time communication with WebSockets
- Socket.IO
- Image upload and cloud storage
- Environment variable management
- Frontend/backend separation
- API integration using Axios
Some possible improvements for future versions:
- Group chats
- Message read receipts
- Typing indicators
- Online/offline status
- Message reactions
- Message editing and deletion
- File/document sharing
- Voice messages
- Video calling
- Push notifications
- Message search
- Pagination / infinite scrolling
- End-to-end encryption
- Deployment with CI/CD
- Automated tests
Contributions are welcome.
- Fork the repository
- Create a feature branch
git checkout -b feature/your-feature- Make your changes
- Commit your changes
git commit -m "Add your feature"- Push the branch
git push origin feature/your-feature- Open a Pull Request
This project is currently licensed under the ISC License.
Kuldeep
GitHub: @kul-91
⭐ If you find this project useful, consider giving the repository a star!