A scalable chat app: instant messaging over WebSockets, message history in MongoDB, horizontal scaling via a Redis Socket.io adapter, and AI-powered smart replies (OpenAI, with a heuristic fallback so it works with no API key).
▶ Try the live demo — runs right in your browser, no setup.
- ⚡ Real-time messaging with typing indicators & presence (Socket.io)
- 👥 Live roster — see exactly who's online in each room (cluster-accurate via
fetchSockets()over the Redis adapter) - 💾 Persistent history per room (MongoDB)
- 🧵 Multiple rooms (
general,engineering,random) - ✨ AI smart replies — one click suggests 3 contextual responses
- 📈 Scales across instances via the Redis pub/sub adapter
| Tier | Tech |
|---|---|
| UI + server | Next.js (custom Node server in server.js) |
| Realtime | Socket.io + @socket.io/redis-adapter |
| Store | MongoDB |
| Cache / fan-out | Redis |
| AI | OpenAI gpt-4o-mini (optional; graceful fallback) |
docker compose up --buildOpen http://localhost:3000, pick a username, and start chatting. Open a second browser/incognito window to see real-time delivery, presence, and typing.
To enable real OpenAI replies:
OPENAI_API_KEY=sk-... docker compose up --buildnpm install
# needs a local MongoDB + Redis (or point env at Docker ones):
MONGODB_URI=mongodb://localhost:27017 REDIS_URL=redis://localhost:6379 npm run devBrowser ──socket.io──► server.js (Next.js + Socket.io)
│ └─ Redis adapter (fan-out across instances)
└─ MongoDB (message history)
└─ lib/ai.js → OpenAI (smart replies) | fallback
server.js— custom server wiring Next + Socket.io + Redis adapterlib/mongo.js— connection +saveMessage/recentMessageslib/ai.js—smartReplies(history)with OpenAI + heuristic fallbackpages/index.js— chat client;components/*— message list, composer, smart replies
MIT © Wassim Jebali