A real-time chat application where users can connect with friends and message each other instantly, with support for one-on-one and group conversations — similar in spirit to WhatsApp.
ChatNest lets users find and add friends, then chat with them in real time with instant delivery, typing indicators, online/offline presence, and read receipts. Beyond one-on-one messaging, users can create groups with admins and members, share media (images, videos, PDFs), and personalize their chat experience with custom wallpapers.
What makes the messaging layer interesting under the hood is how it balances real-time speed with database efficiency: active conversations are held in Redis in memory and only flushed to MongoDB in batches — either when a chat room becomes inactive or a user leaves — instead of writing to the database on every single message. This keeps the chat experience fast while avoiding unnecessary database load.
- Real-time one-on-one and group messaging via Socket.IO
- Friend system — send/accept friend requests and explore/discover other users
- Group chats — create groups with dedicated admins and members
- Media sharing — send images, videos, and PDFs (via Cloudinary)
- Typing indicators — see when the other person is typing
- Online/offline presence — real-time status updates broadcast to all connected users
- Read receipts — know when your message has been seen
- Redis-backed message buffering — active chats are held in Redis and batch-written to MongoDB for performance, rather than hitting the database on every message
- User preferences — customizable chat wallpaper per user
- Notification sounds — audio cues for sent/received messages and alerts
- JWT-based authentication with secure password hashing
- When a user opens a chat, their socket joins a room (either a private 1:1 room or a group room).
- Redis tracks which sockets belong to which room and how many participants are currently active in it.
- As messages are sent, they're appended to Redis rather than written straight to MongoDB — this keeps message delivery fast since it avoids a database write on every keystroke-driven event.
- Once a room is left, or drops back down to a single active participant, the buffered messages in Redis for that room are flushed to MongoDB in one batch and the Redis cache for that room is cleared.
- All users also join a global room on connection, used to broadcast presence updates (online/offline) across the app in real time.
| Layer | Technology |
|---|---|
| Framework | Next.js (App Router), custom Node.js server |
| Real-time | Socket.IO |
| Database | MongoDB (Mongoose) |
| Caching / Message Buffer | Redis (ioredis) |
| Media Storage | Cloudinary |
| Auth | JWT, bcrypt |
| State Management | Redux Toolkit |
| UI | Radix UI, Tailwind CSS, React Hook Form, Zod |
| Containerization | Docker, Docker Compose |
src/
├── app/
│ ├── (auth)/ # Login & signup pages
│ ├── (main)/ # Main app — chat, groups, explore, profile
│ └── api/v1/ # REST endpoints — users, friends, groups, chats, preferences
├── models/ # Mongoose schemas — User, Chat, Friend, Group, GroupChat, Preferences
├── redux/ # Redux Toolkit store & slices (user, preferences)
├── helpers/ # DB connection, Cloudinary, socket client, auth helpers
├── components/ # Reusable UI components
└── types/ # TypeScript types
Server.js # Custom Node server — wires up Next.js with Socket.IO
RedisClient.js # Redis helper — room/session/chat-buffer management
- Node.js
- MongoDB
- Redis
- A Cloudinary account (for media uploads)
git clone https://github.com/mdrehan369/ChatNest.git
cd ChatNest
npm installCopy .env.sample to .env and fill in the required values (MongoDB URI, Redis connection, JWT secret, Cloudinary credentials, etc.).
cp .env.sample .envnpm run devThis starts the custom server (Server.js), which runs Next.js and Socket.IO together on http://localhost:3000.
docker compose up| Script | Description |
|---|---|
npm run dev |
Start the development server (Next.js + Socket.IO) |
npm run build |
Build the app for production |
npm start |
Start the production server |
npm run lint |
Run ESLint |
- Message search
- Voice/video calling
- End-to-end encryption
- Message reactions
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to your branch
- Open a Pull Request
This project is licensed under the MIT License.