Skip to content

About

Real-time messaging with AI smart replies — Next.js, Socket.io, Redis, MongoDB

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ChatFlow AI — Real-Time Messaging with AI

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).

stack

▶ Try the live demo — runs right in your browser, no setup.

Features

  • ⚡ 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

Stack

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)

Quickstart

docker compose up --build

Open 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 --build

Local development

npm install
# needs a local MongoDB + Redis (or point env at Docker ones):
MONGODB_URI=mongodb://localhost:27017 REDIS_URL=redis://localhost:6379 npm run dev

Architecture

Browser ──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 adapter
  • lib/mongo.js — connection + saveMessage / recentMessages
  • lib/ai.js — smartReplies(history) with OpenAI + heuristic fallback
  • pages/index.js — chat client; components/* — message list, composer, smart replies

License

MIT © Wassim Jebali

About

Real-time messaging with AI smart replies — Next.js, Socket.io, Redis, MongoDB

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages