App Link
https://chit-chat-khaki-ten.vercel.app
A modern real-time chat application built with React, Node.js, Express, Socket.IO, and MongoDB Atlas.
Users can exchange messages instantly without refreshing the page while all chat history is persisted in MongoDB and automatically loaded when the application starts.
- ✅ Real-time messaging using Socket.IO
- ✅ Store chat messages in MongoDB Atlas
- ✅ Retrieve previous chat history
- ✅ REST API for sending and fetching messages
- ✅ Instant message broadcasting
- ✅ Auto-scroll to latest message
- ✅ Responsive chat interface
- ✅ Display message timestamps
- ✅ Clean and reusable project architecture
- ✅ Input validation
- ✅ Error handling for API requests
- ✅ Error handling for Socket.IO events
- ✅ Dummy username login (LocalStorage)
- ✅ Typing indicator
- ✅ Online user counter
- ✅ Auto reconnect with Socket.IO
- ✅ Loading state while sending messages
- ✅ Empty chat state
- ✅ Enter key to send message
- ✅ Logout functionality
- React
- TypeScript
- Vite
- Tailwind CSS
- Axios
- Socket.IO Client
- Node.js
- Express.js
- TypeScript
- Socket.IO
- MongoDB Atlas
- Mongoose
ChitChat
│
├── chat-backend
│ ├── src
│ │ ├── config
│ │ ├── controllers
│ │ ├── models
│ │ ├── routes
│ │ ├── services
│ │ ├── sockets
│ │ ├── utils
│ │ ├── app.ts
│ │ └── server.ts
│ │
│ ├── package.json
│ └── .env
│
├── chat-frontend
│ ├── src
│ │ ├── api
│ │ ├── components
│ │ ├── hooks
│ │ ├── pages
│ │ ├── services
│ │ ├── types
│ │ ├── App.tsx
│ │ └── main.tsx
│ │
│ ├── package.json
│ └── .env
│
└── README.md
git clone https://github.com/your-username/chitchat.git
cd chitchatNavigate to backend
cd chat-backendInstall dependencies
npm installCreate a .env
PORT=5000
MONGODB_URI=your_mongodb_connection_string
CLIENT_URL=http://localhost:5173Run development server
npm run devBackend runs on
http://localhost:5000
Navigate to frontend
cd chat-frontendInstall dependencies
npm installCreate .env
VITE_API_URL=http://localhost:5000/api
VITE_SOCKET_URL=http://localhost:5000Run frontend
npm run devFrontend runs on
http://localhost:5173
POST
POST /api/messages
GET
GET /api/messages
socket.emit("user-typing")socket.emit("user-stop-typing")Broadcasts every newly created message.
socket.on("new-message")Broadcasts connected user count.
socket.on("online-users")Broadcasts when another user starts typing.
socket.on("user-typing")Broadcasts when another user stops typing.
socket.on("user-stop-typing")The application follows a modular architecture to improve maintainability and scalability.
- Controller-Service architecture
- Socket events separated into dedicated socket modules
- Environment variables centralized
- Shared API response utility
- MongoDB used for persistent storage
- Reusable components
- Dedicated API layer
- Dedicated Socket service
- Type-safe models using TypeScript
- Local state managed with React Hooks
- Axios instance for API communication
The application gracefully handles:
- Missing username
- Empty messages
- Database connection failures
- Socket disconnections
- Invalid API requests
- Network failures
- Empty chat history
PORT=5000
MONGODB_URI=your_connection_string
CLIENT_URL=http://localhost:5173VITE_API_URL=http://localhost:5000/api
VITE_SOCKET_URL=http://localhost:5000- Private messaging
- User avatars
- Emoji support
- Image sharing
- File uploads
- Read receipts
- Delivered status
- Message reactions
- Group chats
- Infinite scrolling
- Docker support
- Unit & Integration Tests
- CI/CD Pipeline
- Redis Adapter for multi-server Socket.IO deployment
Vercel
Render
MongoDB Atlas
Md Jillur Rahman
md jillur rahman