Skip to content
SuprakasPublic

About

Real-time team chat with channels, DMs, typing indicators, presence and reactions. React 19, React Router, Socket.io, Express, MongoDB.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Relay 💬

A real-time team chat app: public channels, private messages, typing indicators, live presence, emoji reactions and reliable delivery across reconnects.

Live demo: https://relay-chatapp.vercel.app · API: https://relay-api-su3t.onrender.com/api/health  ·  API: https://relay-api.onrender.com/api/health Demo login: priya@relay.dev / Demo@2026 (open a second browser as rahul@relay.dev to watch messages arrive live).

The API runs on Render's free tier, so the first request after a quiet period can take ~30–50 s while the server wakes up.

Relay desktop

Features

  • Channels and private chats. Create, join and leave public channels; start 1:1 private chats with anyone.
  • Live updates over Socket.io. Messages, reactions, joins/leaves and new chats arrive instantly in every open tab.
  • Typing indicators. "Priya is typing…" with throttled events and automatic expiry if a "stop" event is lost.
  • Presence. Online dot and "last seen", correct across several tabs per user.
  • Join/leave notices posted into the channel as system messages.
  • Reliable sending. Optimistic messages (🕒 → ✓✓), acknowledgements with timeout, Retry on failure, no duplicates on resend.
  • Reconnect handling. Connection banner; after reconnecting the app refreshes chats, reloads missed messages and resends anything pending.
  • Unread counts per chat, emoji picker and quick reactions (👍 ❤️ 😂 😮 🙏 🔥).
  • Real accounts with JWT + bcrypt, profile colour, and 5 themes (Aurora, Ocean, Sunset, Forest, Midnight).
  • Responsive. Two-pane layout on desktop; list → chat navigation on mobile.

Tech stack

Layer Choice
Client React 19, Vite, React Router 8 (createBrowserRouter), Context API + useReducer, socket.io-client, plain CSS with CSS variables
Server Node.js, Express 5, Socket.io 4, Mongoose, Zod, JWT, bcrypt, helmet, rate limiting
Database MongoDB Atlas
Tests Jest + React Testing Library (client); Jest, Supertest, socket.io-client and mongodb-memory-server (server)
Hosting Vercel (client) · Render (API + WebSocket server) · MongoDB Atlas

Architecture

Browser (React)                              Render (Node)                   Atlas
┌──────────────────────────────┐   REST     ┌──────────────────────────┐   ┌─────────┐
│ Router: middleware + loaders │──────────▶ │ routes → controllers     │──▶│ users   │
│ ChatContext (useReducer)     │            │        → models          │   │ channels│
│ hooks: useSocketEvent,       │ WebSocket  │ socket/ → socketController│  │ messages│
│        useConnection, ...    │◀─────────▶ │ presence (in memory)     │   │ reads   │
└──────────────────────────────┘            └──────────────────────────┘   └─────────┘

Server: MVC

  • Models (server/src/models): User, Channel (public channel or DM), Message, Read (last-read time per user and chat).
  • Controllers (server/src/controllers): the business rules, shared by HTTP and sockets. socketController treats each socket event like a request: validate with Zod → call a controller → reply through the acknowledgement as { ok, data } or { ok: false, error }.
  • Views: the JSON sent over REST and Socket.io (toJSONPublic, toChannelJSON).
  • Rooms: channel:<id> for every chat, user:<id> for all tabs of one user. On every (re)connect the server joins the socket to its rooms, then sends session:ready.

Client: separation of concerns

client/src
├── router/      routes, middleware (session, auth guard), loaders
├── context/     AuthContext, ThemeContext, ChatContext + chatReducer + selectors
├── hooks/       useSocketEvent, useConnection, useTyping, useAutoScroll
├── lib/         api, socket factory, session store, formatting
├── pages/       route components (lazy loaded)
└── components/  ui, layout, chat, modals, auth
  • Routing: createBrowserRouter with route middleware that restores the session and protects /chat, a loader that fetches chats and users before the page renders, lazy routes and an error element.
  • State: one useReducer for chat state. State and actions are provided by separate contexts so components that only send actions don't re-render on every message.
  • Socket listeners: useSocketEvent subscribes once per event and always calls the latest handler, and removes the listener on unmount. This prevents duplicate listeners (and duplicate messages) under React StrictMode and avoids leaks.

How a message travels

  1. The composer creates a clientId and adds the message as sending (🕒).
  2. message:send is emitted with a 10 s acknowledgement timeout.
  3. The server checks membership and rate limit, then saves it. A unique index on { sender, clientId } makes a resend return the existing message instead of creating a duplicate.
  4. The server broadcasts message:new to channel:<id>; the sender's ack turns 🕒 into ✓✓.
  5. On timeout the message shows Retry. After a reconnect, pending messages are resent automatically.

Run locally

Requirements: Node 22 (see .nvmrc) and a MongoDB connection string (Atlas free tier or local MongoDB).

# 1. API
cd server
cp .env.example .env        # then set MONGO_URI and JWT_SECRET
npm install
npm run seed                # demo users priya / rahul / amit @relay.dev
npm run dev                 # http://localhost:5000

# 2. Client (new terminal)
cd client
npm install
npm run dev                 # http://localhost:5173

Open two different browsers (or one normal + one private window), log in as two demo users and chat.

Tests

cd client && npm test       # reducer, hooks, auth form, router middleware
cd server && npm test       # unit + REST + real Socket.io integration tests

Server tests start an in-memory MongoDB, so the first run downloads a MongoDB binary.

Deployment

  • Server → Render (Web Service, root server, build npm install, start npm start). Environment: MONGO_URI, JWT_SECRET, CLIENT_ORIGIN (the Vercel URL), NODE_ENV=production.
  • Client → Vercel (root client, framework Vite). Environment: VITE_API_URL and VITE_SOCKET_URL (both the Render URL).

The WebSocket server runs on Render rather than Vercel because it is a long-running process that holds connections open; serverless functions are not designed for that.

What I would add next

  • Redis adapter for Socket.io so presence and rooms work across several server instances
  • Message pagination ("load older"), editing and deleting
  • Image attachments (Cloudinary) and read receipts per message
  • Push notifications for offline users

License

MIT

About

Real-time team chat with channels, DMs, typing indicators, presence and reactions. React 19, React Router, Socket.io, Express, MongoDB.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages