MyChatApp is a modern, full-stack real-time chat application that brings people together through seamless instant messaging. Built with React and Express.js, it features real-time communication powered by Socket.io, a comprehensive friend management system, and a beautiful, responsive UI. Users can register with OTP email verification, manage their profiles with custom avatars, discover other users globally, send friend requests, and engage in private conversations with real-time typing indicators and online status tracking. Whether you're connecting with friends or meeting new people, MyChatApp delivers a smooth, secure, and engaging chat experience.
- π¬ MyChatApp β Real-time Chat Application
| Layer | Platform | Link |
|---|---|---|
| Web | Vercel | https://chat91169.vercel.app/ |
| Server | Render | https://chat-app-api-59jt.onrender.com |
chat-app/
ββ backend/ # Backend: Express + MongoDB + Socket.io
β ββ server.js # Main server entry point
β ββ package.json # Backend dependencies
β ββ admin/ # Admin utilities
β β ββ deleteAllMessages.js # Script to delete all messages
β β ββ resetDatabase.js # Script to reset the database
β ββ config/
β β ββ cloudinary.js # Cloudinary configuration for image uploads
β β ββ db.js # MongoDB connection setup
β ββ controllers/
β β ββ auth.controller.js # Login, logout, token refresh
β β ββ authOtp.controller.js # OTP-based signup flow
β β ββ friend.controller.js # Friend request management
β β ββ messages.controller.js # Message CRUD operations
β β ββ profile.controller.js # Profile updates and avatar
β β ββ room.controller.js # Chat room management
β β ββ users.controller.js # User discovery
β ββ middleware/
β β ββ authenticate.js # JWT authentication middleware
β β ββ multer.js # File upload middleware
β ββ model/
β β ββ friend.model.js # Friendship schema
β β ββ messages.model.js # Message schema
β β ββ rooms.model.js # Chat room schema
β β ββ signupOtp.model.js # OTP verification schema
β β ββ user.model.js # User schema
β ββ routes/
β β ββ auth.routes.js # /api/auth routes
β β ββ friend.routes.js # /api/friends routes
β β ββ messages.routes.js # /api/messages routes
β β ββ profile.routes.js # /api/profile routes
β β ββ room.routes.js # /api/rooms routes
β β ββ users.routes.js # /api/users routes
β ββ socket/
β β ββ index.js # Socket.io initialization
β β ββ chat.js # Real-time chat handlers
β β ββ friend.js # Real-time friend request handlers
β β ββ userStatus.js # Online/offline status tracking
β β ββ middleware/
β β ββ auth.js # Socket authentication middleware
β ββ uploads/ # Temporary file uploads
β ββ utils/
β ββ createOrGetRoom.js # Room utility functions
β ββ sendEmail.js # Brevo email service for OTP
β ββ uploadImage.js # Cloudinary upload utility
β
ββ frontend/ # Frontend: React + Vite + Tailwind CSS
ββ index.html # HTML entry point
ββ package.json # Frontend dependencies
ββ vite.config.js # Vite configuration
ββ vercel.json # Vercel deployment config
ββ src/
ββ main.jsx # React entry point
ββ App.jsx # App router and routes
ββ App.css # Global styles
ββ index.css # Tailwind imports
ββ api/
β ββ axios.jsx # Axios instance with interceptors
ββ assets/ # Static assets
ββ components/
β ββ ChatSection.jsx # Main chat interface
β ββ ChatSidebar.jsx # Navigation sidebar
β ββ FriendsSection.jsx # Friend management UI
β ββ GlobalSection.jsx # User discovery page
β ββ ProfileSettings.jsx # Profile settings page
β ββ VerifyOtp.jsx # OTP verification component
ββ pages/
β ββ Home.jsx # Main dashboard
β ββ Login.jsx # Login page
β ββ Signup.jsx # Signup page
ββ socket/
β ββ index.js # Socket.io client setup
ββ utils/
ββ ProtectedRoute.jsx # Auth route protection
- Frontend: React 19, JavaScript (ES Modules)
- Backend: Express.js 5, Node.js
- Database: MongoDB with Mongoose ODM
- Real-time: Socket.io
- UI: Tailwind CSS, Lucide Icons
- Notifications: React Hot Toast
- Routing: React Router DOM v7
- HTTP Client: Axios
- Authentication: JSON Web Tokens (JWT), bcryptjs
- File Uploads: Multer, Cloudinary
- Email Service: Brevo (Sendinblue) for OTP emails
- Build Tool: Vite 7
- Development: Nodemon, ESLint
- Deployment: Vercel (frontend), Render (backend)
ββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββ
β React + Vite β HTTP β Express.js API β Mongooseβ MongoDB β
β (Frontend) ββββββββ>β /api/auth βββββββββ>β (Users, β
β β β /api/users β β Messages, β
β Tailwind CSS β Socket β /api/friends β β Rooms, β
β React Router ββββββββ>β /api/messages β β Friendships) β
ββββββββββββββββββββββββ .io β /api/rooms β βββββββββββββββββββ
β /api/profile β
βββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ
β Cloudinary β β Brevo β β Socket.io β
β (Avatars) β β (OTP Email) β β (Real-time) β
ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ
Key Architecture Details:
- Authentication: JWT-based with access tokens (1 hour) and refresh tokens (7 days) stored in httpOnly cookies
- Real-time Communication: Socket.io handles live messaging, online status, and friend request notifications
- Token Refresh: Automatic token rotation with failed request retry queue
- File Storage: Avatar images uploaded to Cloudinary via Multer middleware
- Email Verification: OTP-based signup flow using Brevo SMTP API
- CORS: Configured for frontend origin with credentials enabled
- Email + password registration with OTP verification
- Secure login with JWT access and refresh tokens
- Automatic token refresh with request retry mechanism
- Password hashing with bcryptjs
- Protected routes for authenticated users only
- Custom user profiles with avatar uploads
- Profile name and password updates
- Global user discovery with pagination
- Real-time online/offline status tracking
- Last seen timestamps for offline users
- Send, accept, and reject friend requests
- Cancel outgoing friend requests
- Remove existing friends
- View pending, sent, accepted, and rejected requests
- Real-time friend request notifications
- Private one-on-one chat rooms
- Real-time message delivery via Socket.io
- Unsend messages functionality
- Unread message count tracking
- Mark messages as read
- Message history persistence
- Search and filter conversations
- Sort chats alphabetically or by recent activity
- Filter to show unread chats only
- Online status indicators
- Responsive chat interface
- Toast notifications for actions
- Modern, clean design with Tailwind CSS
- Responsive layout for all screen sizes
- Gradient accents and smooth transitions
- Loading states and error handling
- Navigation sidebar with tab switching
Base URL (local): http://localhost:5000
All authenticated routes require a valid Bearer token in the Authorization header.
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/auth/send-otp |
POST | Send OTP to email for signup | Public |
/api/auth/verify-otp |
POST | Verify OTP and create account | Public |
/api/auth/login |
POST | Login with email and password | Public |
/api/auth/refresh-token |
POST | Refresh access token using cookie | Public |
/api/auth/logout |
POST | Logout and clear refresh token | Public |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/users/all |
GET | Get all users with pagination | Auth required |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/friends/request |
POST | Send a friend request | Auth required |
/api/friends/accept |
POST | Accept a friend request | Auth required |
/api/friends/reject |
POST | Reject a friend request | Auth required |
/api/friends/remove |
POST | Remove an existing friend | Auth required |
/api/friends/cancel |
POST | Cancel a sent friend request | Auth required |
/api/friends/pending |
GET | Get pending friend requests | Auth required |
/api/friends/sent |
GET | Get sent friend requests | Auth required |
/api/friends/list |
GET | Get accepted friends list | Auth required |
/api/friends/rejected |
GET | Get rejected requests | Auth required |
/api/friends/status/:friendId |
GET | Check friendship status | Auth required |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/messages/:roomId |
GET | Get messages for a room | Auth required |
/api/messages |
POST | Send a message | Auth required |
/api/messages/unsend/:messageId |
PUT | Unsend a message | Auth required |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/rooms/my |
GET | Get user's chat rooms | Auth required |
/api/rooms/with/:friendId |
GET | Get or create room with friend | Auth required |
/api/rooms/:roomId/mark-read |
POST | Mark room messages as read | Auth required |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/profile/update |
PUT | Update profile name | Auth required |
/api/profile/avatar |
PUT | Upload/update avatar image | Auth required |
/api/profile/change-password |
PUT | Change account password | Auth required |
- Node.js >= 18.x
- npm or yarn
- MongoDB (local or MongoDB Atlas)
- Cloudinary account (for avatar uploads)
- Brevo account (for OTP emails)
git clone https://github.com/silence91169/chat-app.git
cd chat-appcd backend
npm installCreate a .env file in the backend directory (see Environment Variables).
Start the backend server:
# Development mode with hot reload
npm run dev
# Production mode
npm startThe backend will run on http://localhost:5000.
cd frontend
npm installCreate a .env file in the frontend directory (see Environment Variables).
Start the frontend development server:
npm run devThe frontend will run on http://localhost:5173.
# Server
PORT=5000
NODE_ENV=development
# MongoDB Connection
MONGO_URI=mongodb://localhost:27017/chatapp
# JWT Secrets (use strong random strings)
ACCESS_TOKEN_SECRET=your-access-token-secret
REFRESH_TOKEN_SECRET=your-refresh-token-secret
# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:5173
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
# Brevo Email Configuration
BREVO_API_KEY=your-brevo-api-key
EMAIL=[email protected]# Backend API URL
VITE_API_URL=http://localhost:5000- Start the backend server (from
backend/directory):npm run dev
cd frontend
npm test- Set environment variables in your hosting platform
- Update
FRONTEND_URLto your production URL - Set
NODE_ENV=production - Deploy using Git or CLI
- Build the project:
npm run build- Set
VITE_API_URLto your backend URL - Deploy the
distfolder
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a 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 MIT License - see the LICENSE file for details.
Shitanshu Singh
- GitHub: @silence91169
- Repository: chattingAPP
- React - Frontend framework
- Express - Backend framework
- MongoDB - Database
- Socket.IO - Real-time engine
- Tailwind CSS - Styling
- Cloudinary - Image hosting
- Brevo - Email service
If you have any questions or need help, please:
- Open an issue
- Contact: [email protected]
Made with β€οΈ by Shitanshu Singh
β Star this repository if you found it helpful!