Full-Stack Real-Time Application · 2024
TalkNest — Real-Time Chat and Peer-to-Peer Video Calls
A web chat application with live messaging, presence and one-to-one video calls. The interesting part is the routing: three kinds of data take three different paths, and the server never carries a single frame of video.
Start Here — a Map You Can Click
Two browsers, one small server and three Firebase services. The arrows follow one message and one call from A to B; the same paths run the other way. Click a box to jump to the part that explains it.
1. Three Kinds of Data, Three Paths
A chat product moves data with very different needs. TalkNest gives each one the transport that fits it instead of pushing everything through one socket.
| Data | Path | Why this path |
|---|---|---|
| Identity | Firebase Auth in the browser: email and password, Google sign-in, password reset, email verification | No passwords ever reach the application server. |
| Profiles and search | REST calls to the Express API, which reads and writes Firestore through the Admin SDK | Writes that change a profile are checked on the server against a verified ID token. |
| Chat messages | The browser writes to Firestore and every open client receives the change through a live listener | Durable history and real-time delivery come from the same write. |
| Presence and call set-up | Socket.IO events, with each user's current socket id kept in the Realtime Database | Signalling is small, short-lived and needs to reach one specific connection. |
| Video and audio | WebRTC, directly between the two browsers | Media is heavy and latency-sensitive; relaying it through the server would add cost and delay. |
Design insight. The server is a matchmaker, not a carrier. It introduces two browsers to each other and steps aside, so call quality does not depend on server bandwidth.
2. Sign-Up and Profiles
Authentication stays with Firebase. The API only stores the profile that goes with an account, and it protects changes to that profile by verifying the caller's ID token.
| Endpoint | Purpose | Protection |
|---|---|---|
POST /api/users |
Create the profile document after Firebase creates the account | Rejects a request without uid or displayName (400) |
GET /api/user/:id |
Read a profile | 404 when the user does not exist |
PATCH / DELETE /api/user/:id |
Update or remove a profile | Firebase ID token verified on the server |
GET /api/users/search |
Find people by name, email or id | Returns only the public fields: id, display name, photo |
3. Real-Time Messaging
A message is one write. The sender appends it to the chat document, and Firestore pushes the new state to every client that is listening, including the sender's own screen. There is no separate “deliver” step to get wrong.
One Id That Both Sides Can Compute
The chat id is the two user ids joined in a fixed order (the larger one first). Either user can derive it without asking the server, and both always arrive at the same document, so two people can never end up with two parallel conversations.
Data Model
- users, chats and userChats live in Firestore.
userChatsis a per-user index of conversations with the last message and its time, so the sidebar loads from one document. - Images go to Firebase Storage first; the message then carries the download URL.
- Presence is the only data in the Realtime Database: it changes on every connect and disconnect and is never needed as history.
4. Video Calls — Signalling Through the Server, Media Around It
The Problem
Two browsers cannot open a WebRTC connection until each has the other's session description, and they have no way to exchange it directly. Something both can already reach has to pass those two messages along, to the right person, on the connection that person is using right now.
The Flow
A Call as a State Machine
The Signalling Contract
| Event | Sent by | Carries | Server action |
|---|---|---|---|
register |
Each client on connect | userId |
Marks the user online and stores the socket id |
callUser |
Caller | Callee id, WebRTC offer, caller id | Looks up the callee's socket and forwards the offer |
answerCall |
Callee | WebRTC answer, caller id | Looks up the caller's socket and emits callAccepted |
hangUp |
The side that ends the call | Peer id | Forwards hangUp to the peer |
disconnect |
Socket.IO | — | Removes the presence record |
Two Decisions Worth Explaining
- Socket ids are looked up, not remembered. A socket id changes on every reconnect, so the server keys presence by user id and resolves the current socket at the moment of the call. A stale id can never receive someone else's offer.
- One offer, one answer. The peers are created with
trickle: false, so each side sends a single message that already contains its network candidates. Set-up takes a little longer, but the whole handshake is two messages and the server needs no per-call state.
Design insight. The offer and the answer are opaque to the server. It routes them by user id and never parses them, which keeps the signalling layer independent of WebRTC itself.
5. CI/CD and Tests
The back end is built and tested by GitHub Actions on every push and pull request to main. The deploy job depends on the test job, so a failing test stops the release.
| Level | Tool | What it covers |
|---|---|---|
| API | Jest + Supertest, run in CI | Root route; validation of a new profile (400 without required fields); 404 for an unknown user; creating or selecting a chat |
| End to end | Cypress, configured in the front end | Target scenarios: start and accept a call, both video streams visible, hang up, chat still working during a call |
| Delivery | Heroku for the API, a Dockerfile for the React build | The server starts from a one-line Procfile; the front end is built once and served as static files |
6. Limits and Next Steps
TalkNest was built in early 2024 as a complete, working product. Reading the code again, these are the changes that would matter most at larger scale:
| Today | Limit | Next step |
|---|---|---|
| Default STUN servers only | Peers behind strict NATs or firewalls may not connect | Add a TURN relay as a fallback path |
| Offer and answer sent whole | Call set-up waits for candidate gathering | Trickle ICE: connect on the first working route |
| No call state on the server | No busy, declined or missed-call handling | A small per-call state machine on the server |
| Search scans the user collection | Cost grows with the number of users | Indexed prefix queries or a search service |
| Messages in one array per chat | A long conversation approaches the document size limit | A message subcollection with pagination |
Technology Stack
| Layer | Technology | Purpose |
|---|---|---|
| Front end | React, React Router, context + reducer | Chat UI, call UI, auth and chat state |
| Calls | WebRTC through simple-peer | Peer-to-peer video and audio |
| Signalling | Socket.IO | Presence and call set-up events |
| Back end | Node.js, Express, Firebase Admin SDK | Profiles, search, token verification, signalling |
| Data | Firestore, Realtime Database, Firebase Storage | Messages and profiles, presence, images |
| Identity | Firebase Auth | Email and password, Google sign-in, password reset |
| Quality and delivery | Jest, Supertest, Cypress, GitHub Actions, Heroku, Docker | API tests, end-to-end setup, automated build and deploy |
Outcome
TalkNest is a small system with clear boundaries: identity delegated to a provider, durable data written once and fanned out by the database, a signalling server that only routes, and media that flows peer to peer. The same habit of matching each kind of data to the right path carries through to the event-driven platforms built later.



Comments