A modern, full-stack real-time chat application built with the MERN stack featuring instant messaging, user authentication, and customizable themes.
Features β’ Tech Stack β’ Installation β’ Usage β’ API Reference β’ Contributing
- User Registration - Create an account with email, full name, and password
- Secure Login - JWT-based authentication with HTTP-only cookies
- Password Encryption - Bcrypt hashing for secure password storage
- Protected Routes - Middleware-based route protection
- Instant Messages - Socket.io powered real-time communication
- Image Sharing - Send and receive images in chat via Cloudinary
- Message History - Persistent message storage in MongoDB
- Online Status - See which users are currently online
- Profile Picture - Upload and update profile pictures via Cloudinary
- User Settings - Customize your profile and preferences
- Cover Picture - Optional cover picture support
- 32 Themes - Choose from a wide variety of DaisyUI themes including:
- Light, Dark, Cupcake, Synthwave, Cyberpunk, Dracula, Nord, and many more!
- Live Preview - Preview themes before applying
- Persistent Settings - Theme preferences saved in local storage
- Responsive Design - Works seamlessly on desktop and mobile
- Beautiful Interface - Clean, modern design with Tailwind CSS & DaisyUI
- Loading States - Smooth loading animations and skeleton components
- Toast Notifications - Real-time feedback with react-hot-toast
| Technology | Purpose |
|---|---|
| React 19 | UI Library |
| Vite | Build Tool & Dev Server |
| React Router v7 | Client-side Routing |
| Zustand | State Management |
| Axios | HTTP Client |
| Socket.io Client | Real-time Communication |
| Tailwind CSS | Styling |
| DaisyUI | UI Components |
| Lucide React | Icons |
| React Hot Toast | Notifications |
| Technology | Purpose |
|---|---|
| Node.js | Runtime Environment |
| Express.js | Web Framework |
| MongoDB | Database |
| Mongoose | ODM |
| Socket.io | Real-time Communication |
| JWT | Authentication |
| Bcrypt.js | Password Hashing |
| Cloudinary | Image Storage |
| Cookie Parser | Cookie Handling |
| CORS | Cross-Origin Requests |
Chat-App/
βββ backend/
β βββ src/
β β βββ controllers/ # Request handlers
β β β βββ auth.controller.js
β β β βββ message.controller.js
β β βββ lib/ # Utilities & configurations
β β β βββ cloudinary.js # Cloudinary config
β β β βββ db.js # MongoDB connection
β β β βββ socket.js # Socket.io setup
β β β βββ utils.js # Helper functions
β β βββ middleware/ # Express middlewares
β β βββ models/ # Mongoose schemas
β β β βββ user.model.js
β β β βββ message.model.js
β β βββ routes/ # API routes
β β β βββ auth.route.js
β β β βββ message.route.js
β β βββ seeds/ # Database seeders
β β βββ index.js # Server entry point
β βββ package.json
βββ frontend/
β βββ src/
β β βββ components/ # Reusable components
β β β βββ ChatContainer.jsx
β β β βββ ChatHeader.jsx
β β β βββ MessageInput.jsx
β β β βββ Navbar.jsx
β β β βββ Sidebar.jsx
β β β βββ skeletons/
β β βββ constants/ # App constants
β β βββ lib/ # Utilities
β β βββ pages/ # Page components
β β β βββ HomePage.jsx
β β β βββ LoginPage.jsx
β β β βββ SignUpPage.jsx
β β β βββ ProfilePage.jsx
β β β βββ SettingsPage.jsx
β β βββ store/ # Zustand stores
β β β βββ useAuthStore.js
β β β βββ useChatStore.js
β β β βββ useThemeStore.js
β β βββ App.jsx
β β βββ main.jsx
β βββ package.json
βββ package.json # Root package.json
- Node.js (v18 or higher)
- MongoDB (local or Atlas)
- Cloudinary Account (for image uploads)
git clone https://github.com/Abdooo2235/MERN-Chat-App.git
cd MERN-Chat-AppCreate a .env file in the backend directory with the following variables:
# Server Configuration
PORT=5001
NODE_ENV=development
# MongoDB Connection
MONGODB_URI=your_mongodb_connection_string
# JWT Secret
JWT_SECRET=your_super_secret_jwt_key
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Client URL (for CORS in production)
CLIENT_URL=http://localhost:5173Install all dependencies (backend + frontend):
npm run buildOr install separately:
# Backend
cd backend
npm install
# Frontend
cd ../frontend
npm installRun Backend (with nodemon):
cd backend
npm run devThe server will start on http://localhost:5001
Run Frontend (with Vite):
cd frontend
npm run devThe app will be available at http://localhost:5173
Build and Start:
# From root directory
npm run build # Installs dependencies and builds frontend
npm start # Starts the backend serverIn production, the backend serves the frontend static files.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/auth/signup |
Register a new user | β |
POST |
/api/auth/login |
Login user | β |
POST |
/api/auth/logout |
Logout user | β |
PUT |
/api/auth/update-profile |
Update profile picture | β |
GET |
/api/auth/check |
Check authentication status | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/messages/users |
Get users for sidebar | β |
GET |
/api/messages/:id |
Get messages with a user | β |
POST |
/api/messages/send/:id |
Send a message | β |
| Event | Direction | Description |
|---|---|---|
connection |
Client β Server | User connects |
disconnect |
Client β Server | User disconnects |
getOnlineUsers |
Server β Client | List of online users |
newMessage |
Server β Client | New message received |
- Go to Cloudinary and create a free account
- Navigate to Dashboard
- Copy your:
- Cloud Name
- API Key
- API Secret
- Add them to your
.envfile
The app supports 32 beautiful themes powered by DaisyUI:
Click to see all themes
| Theme | Theme | Theme | Theme |
|---|---|---|---|
| light | dark | cupcake | bumblebee |
| emerald | corporate | synthwave | retro |
| cyberpunk | valentine | halloween | garden |
| forest | aqua | lofi | pastel |
| fantasy | wireframe | black | luxury |
| dracula | cmyk | autumn | business |
| acid | lemonade | night | coffee |
| winter | dim | nord | sunset |
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
Abdooo2235
- GitHub: @Abdooo2235
β Star this repo if you found it helpful! β