A full-stack WhatsApp-like chat application built with MongoDB, Express, React, Node.js, and Socket.io featuring real-time messaging, image sharing, and a beautiful dark theme UI.
- π User Authentication - JWT-based signup/login/logout
- π¬ Real-Time Messaging - Instant message delivery with Socket.io
- π· Image Sharing - Send and receive images
- π₯ Private Messaging - One-on-one conversations
- ποΈ Chat Rooms - Group messaging support
- β Read Receipts - See when messages are read
- β¨οΈ Typing Indicators - Real-time typing status
- π’ Online Status - See who's online
- π± Responsive Design - Works on desktop and mobile
- π Dark Theme - Beautiful dark UI with smooth animations
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM for MongoDB
- Socket.io - Real-time communication
- JWT - Authentication
- Bcryptjs - Password hashing
- Multer - File upload handling
- React - UI library
- Vite - Build tool
- React Router - Routing
- Socket.io-client - Real-time client
- Axios - HTTP client
- CSS3 - Styling with custom dark theme
Before running this application, make sure you have:
- Node.js (v14 or higher)
- MongoDB - Either local installation or MongoDB Atlas account
- npm or yarn
git clone <repository-url>
cd mern-chat-app# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env file and add your configuration:
# - MONGO_URI: Your MongoDB connection string
# - JWT_SECRET: A secure random string for JWT signing
# - PORT: 5000 (or your preferred port)
# - CLIENT_URL: http://localhost:5173 (frontend URL)# Navigate to frontend directory (from project root)
cd frontend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# The default values should work, but you can customize:
# - VITE_API_URL: http://localhost:5000/api
# - VITE_SOCKET_URL: http://localhost:5000# From backend directory
npm run devThe backend server will start on http://localhost:5000
# From frontend directory (in a new terminal)
npm run devThe frontend will start on http://localhost:5173
- Sign Up: Create a new account with username, email, and password
- Login: Sign in with your credentials
- Start Chatting:
- Select a user from the list to start a private conversation
- Type your message and hit Send
- Click the π icon to send images
- See real-time online status and typing indicators
- Logout: Click the logout button when done
mern-chat-app/
βββ backend/
β βββ controllers/ # Request handlers
β βββ middleware/ # Auth & error handling
β βββ models/ # MongoDB schemas
β βββ routes/ # API routes
β βββ utils/ # Helper functions
β βββ uploads/ # Uploaded images
β βββ socket.js # Socket.io configuration
β βββ server.js # Server entry point
β βββ package.json
βββ frontend/
β βββ src/
β β βββ components/ # Reusable React components
β β βββ context/ # React Context (Auth, Socket)
β β βββ pages/ # Page components
β β βββ services/ # API services
β β βββ App.jsx # Main App component
β β βββ main.jsx # Entry point
β βββ package.json
βββ README.md
POST /api/auth/signup- Register new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userGET /api/auth/me- Get current user
GET /api/users- Get all usersGET /api/users/:id- Get user by IDGET /api/users/search/:query- Search usersPUT /api/users/profile- Update profile
POST /api/messages- Send messageGET /api/messages/conversations- Get recent conversationsGET /api/messages/conversation/:userId- Get conversation with userGET /api/messages/room/:roomName- Get room messagesPUT /api/messages/:messageId/read- Mark message as read
joinRoom- Join a chat roomleaveRoom- Leave a chat roomprivateMessage- Send private messageroomMessage- Send room messagetyping- Send typing indicatormessageRead- Mark message as read
onlineUsers- List of online usersreceivePrivateMessage- Receive private messagereceiveRoomMessage- Receive room messageuserTyping- User typing notificationmessageReadReceipt- Message read confirmation
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_key
PORT=5000
NODE_ENV=development
CLIENT_URL=http://localhost:5173VITE_API_URL=http://localhost:5000/api
VITE_SOCKET_URL=http://localhost:5000- JWT token-based authentication
- Secure password hashing with bcryptjs
- Protected routes on both frontend and backend
- Automatic logout on token expiration
- Instant message delivery
- Online/offline status updates
- Typing indicators
- Read receipts
- Connection state management
- Image upload with multer
- File size limits (5MB)
- Image type validation
- Secure file storage
- Dark theme optimized for readability
- Smooth animations and transitions
- Responsive design for all screen sizes
- Message grouping by sender
- Timestamps and status indicators
- Check MongoDB connection string
- Ensure port 5000 is not in use
- Verify all environment variables are set
- Ensure backend is running
- Check CORS settings
- Verify API URL in frontend .env
- Check firewall settings
- Verify Socket.io server URL
- Check browser console for errors
Feel free to fork this project and submit pull requests for any improvements.
This project is open source and available under the MIT License.
Built as a demonstration of full-stack real-time chat application development.