# vazanth/realtime-chat-app architecture

> Architecture diagram of the GitHub repository vazanth/realtime-chat-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vazanth/realtime-chat-app
- Repository: https://github.com/vazanth/realtime-chat-app

## Overview

1. This repository is split into two cooperating applications: a TypeScript/Node.js backend and a React/Vite frontend. The backend exposes REST endpoints and a Socket.IO server; the frontend is a single-page chat UI that talks to both.

2. The backend entry points are `src/server.ts` and `src/app.ts`. `app.ts` wires Express middleware, routing, and response/error handling, while `server.ts` starts the HTTP server and attaches the socket layer.

3. The HTTP API is organized by domain:
   - `authController.ts` for sign-up/sign-in
   - `userController.ts` for user-related retrieval
   - `chatController.ts` for creating chats, fetching chat history, and creating groups
   - `messageController.ts` for fetching/sending chat messages and file uploads

4. Request validation is a first-class boundary. Each domain has a Zod schema in `src/schema`, and `src/middleware/validator.ts` enforces those schemas before controller logic runs. Validation errors are normalized through helper utilities such as `parseSchemaError.ts`.

5. The backend appears intentionally lightweight in persistence: `src/data` plus `helpers/fileOperations.ts` suggest file-based storage rather than a database. The README confirms the project expects local JSON files like `users.json` and `chat.json`, which means the architecture is centered on filesystem-backed state.

6. Real-time chat is handled separately from the REST API in `src/socket`. The backend socket module likely manages room membership and message broadcast for chat sessions, while the frontend keeps a live connection through `frontend/src/context/SocketContext.tsx`.

7. File sharing is a distinct path through the system. The backend has a Multer middleware, a `public` directory for stored assets, and message endpoints for sending files. That makes uploads a separate transport concern from normal message text.

8. The frontend is a route-based SPA. `Routes.tsx` and `pages/` define the login, register, and chat screens, while `App.tsx` acts as the top-level composition layer.

9. The chat screen is built from reusable UI parts in `frontend/src/components`, especially `ChatList`, `ChatBox`, `Header`, `Modal`, and `Popover`. These components split the UI into navigation, conversation selection, message display/composition, and auxiliary dialogs.

10. Data flow on the frontend is straightforward: a user authenticates through the login/register pages, then lands on the chat page, which fetches chat metadata and message history over HTTP and uses Socket.IO for live updates. The socket context centralizes connection state so the UI can react to incoming messages globally.

11. There is a clear boundary between persistent chat state and transient live state. REST endpoints are used for setup and retrieval, while the socket layer handles in-session delivery and notifications.

12. The project is designed to run locally with Node 18+, TypeScript on both sides, and Vite/Tailwind on the frontend. There is no sign of an external database or third-party messaging service; the architecture is mostly self-contained around Express, Socket.IO, local storage, and a browser SPA.

Main entry points: [`frontend/src/pages/Chat.tsx`](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/pages/Chat.tsx) (Chat page), [`backend/src/controllers`](https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/controllers) (Controllers), [`frontend/src/Routes.tsx`](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/Routes.tsx) (Routes), [`backend/src/socket/index.ts`](https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/socket/index.ts) (Socket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_server(("Server<br/>HTTP bootstrap<br/>[server.ts]"))
  node_backend_app["App<br/>Express setup<br/>[app.ts]"]
  node_backend_routes["Routes<br/>REST routing"]
  node_backend_controllers["Controllers<br/>domain handlers"]
  node_backend_validator{{"Validator<br/>request guard<br/>[validator.ts]"}}
  node_backend_schemas["Schemas<br/>zod contracts"]
  node_backend_storage[("File state<br/>filesystem store")]
  node_backend_uploads["Uploads<br/>multer assets<br/>[multer.ts]"]
  node_backend_socket(("Socket<br/>[index.ts]"))
  node_backend_chat_socket["Chat socket<br/>room logic<br/>[chat.ts]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["App<br/>SPA shell<br/>[App.tsx]"]
  node_frontend_routes["Routes<br/>screen routing<br/>[Routes.tsx]"]
  node_frontend_socket(("Socket context<br/>live state<br/>[SocketContext.tsx]"))
  node_frontend_login["Login<br/>auth screen<br/>[Login.tsx]"]
  node_frontend_register["Register<br/>auth screen<br/>[Register.tsx]"]
  node_frontend_chat["Chat page<br/>conversation screen<br/>[Chat.tsx]"]
  node_frontend_list["Chat list<br/>navigation UI<br/>[ChatList.tsx]"]
  node_frontend_box["Chat box<br/>message UI<br/>[ChatBox.tsx]"]
  node_frontend_header["Header<br/>shell UI<br/>[Header.tsx]"]
  node_frontend_overlays{{"Overlays<br/>aux UI"}}
end

node_backend_server -->|"boots"| node_backend_app
node_backend_server -->|"attaches"| node_backend_socket
node_backend_app -->|"mounts"| node_backend_routes
node_backend_routes -->|"dispatches"| node_backend_controllers
node_backend_controllers -->|"validates"| node_backend_validator
node_backend_validator -->|"uses"| node_backend_schemas
node_backend_controllers -->|"reads/writes"| node_backend_storage
node_backend_controllers -->|"uploads"| node_backend_uploads
node_backend_socket -->|"delegates"| node_backend_chat_socket
node_frontend_app -->|"composes"| node_frontend_routes
node_frontend_routes -->|"shows"| node_frontend_login
node_frontend_routes -->|"shows"| node_frontend_register
node_frontend_routes -->|"shows"| node_frontend_chat
node_frontend_chat -->|"uses"| node_frontend_list
node_frontend_chat -->|"uses"| node_frontend_box
node_frontend_chat -->|"uses"| node_frontend_header
node_frontend_chat -->|"uses"| node_frontend_overlays
node_frontend_socket -->|"connects"| node_backend_socket
node_frontend_login -->|"auth HTTP"| node_backend_controllers
node_frontend_register -->|"auth HTTP"| node_backend_controllers
node_frontend_chat -->|"chat HTTP"| node_backend_controllers
node_frontend_chat -->|"file upload"| node_backend_uploads

click node_backend_server "https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/server.ts"
click node_backend_app "https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/app.ts"
click node_backend_routes "https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/routes"
click node_backend_controllers "https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/controllers"
click node_backend_validator "https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/middleware/validator.ts"
click node_backend_schemas "https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/schema"
click node_backend_storage "https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/data"
click node_backend_uploads "https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/middleware/multer.ts"
click node_backend_socket "https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/socket/index.ts"
click node_backend_chat_socket "https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/socket/chat.ts"
click node_frontend_app "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/App.tsx"
click node_frontend_routes "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/Routes.tsx"
click node_frontend_socket "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/context/SocketContext.tsx"
click node_frontend_login "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/pages/Login.tsx"
click node_frontend_register "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/pages/Register.tsx"
click node_frontend_chat "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/pages/Chat.tsx"
click node_frontend_list "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/components/ChatList.tsx"
click node_frontend_box "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/components/ChatBox.tsx"
click node_frontend_header "https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/components/Header.tsx"
click node_frontend_overlays "https://github.com/vazanth/realtime-chat-app/tree/main/frontend/src/components"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_backend_server,node_backend_app,node_backend_routes,node_backend_controllers,node_backend_validator,node_backend_schemas,node_backend_storage,node_backend_uploads,node_backend_socket,node_backend_chat_socket toneBlue
class node_frontend_app,node_frontend_routes,node_frontend_socket,node_frontend_login,node_frontend_register,node_frontend_chat,node_frontend_list,node_frontend_box,node_frontend_header,node_frontend_overlays toneAmber
```

## Components

### Backend

Express REST API, validation, filesystem-backed state, and Socket.IO realtime delivery.

- [Server](https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/server.ts): HTTP bootstrap · Starts the Node process, binds HTTP, and attaches realtime sockets. · `backend/src/server.ts`
- [App](https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/app.ts): Express setup · Configures middleware, routing, and response/error handling. · `backend/src/app.ts`
- [Routes](https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/routes): REST routing · Domain route entrypoints for chat, messages, and users. · `backend/src/routes`
- [Controllers](https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/controllers): domain handlers · Auth, chat, message, and user request handlers. · `backend/src/controllers`
- [Validator](https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/middleware/validator.ts): request guard · Runs Zod schemas before controller logic and normalizes validation failures. · `backend/src/middleware/validator.ts`
- [Schemas](https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/schema): zod contracts · Domain validation schemas for chat, message, and user requests. · `backend/src/schema`
- [File state](https://github.com/vazanth/realtime-chat-app/tree/main/backend/src/data): filesystem store · Local JSON-backed persistence and helper operations for app state. · `backend/src/data`
- [Uploads](https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/middleware/multer.ts): multer assets · File upload transport and public asset handling for message attachments. · `backend/src/middleware/multer.ts`
- [Socket](https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/socket/index.ts): Socket.IO server · Realtime messaging layer for rooms, joins, and broadcast updates. · `backend/src/socket/index.ts`
- [Chat socket](https://github.com/vazanth/realtime-chat-app/blob/main/backend/src/socket/chat.ts): room logic · Chat-specific realtime coordination and message fanout. · `backend/src/socket/chat.ts`

### Frontend

React/Vite single-page chat UI with route screens, reusable components, and socket context.

- [App](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/App.tsx): SPA shell · Top-level React composition for the client application. · `frontend/src/App.tsx`
- [Routes](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/Routes.tsx): screen routing · Route map for login, register, and chat screens. · `frontend/src/Routes.tsx`
- [Socket context](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/context/SocketContext.tsx): live state · Centralized Socket.IO connection and incoming message state for the UI. · `frontend/src/context/SocketContext.tsx`
- [Login](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/pages/Login.tsx): auth screen · Sign-in entry screen. · `frontend/src/pages/Login.tsx`
- [Register](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/pages/Register.tsx): auth screen · Sign-up entry screen. · `frontend/src/pages/Register.tsx`
- [Chat page](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/pages/Chat.tsx): conversation screen · Main authenticated chat workspace. · `frontend/src/pages/Chat.tsx`
- [Chat list](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/components/ChatList.tsx): navigation UI · Conversation and contact navigation. · `frontend/src/components/ChatList.tsx`
- [Chat box](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/components/ChatBox.tsx): message UI · Message timeline and composition area. · `frontend/src/components/ChatBox.tsx`
- [Header](https://github.com/vazanth/realtime-chat-app/blob/main/frontend/src/components/Header.tsx): shell UI · Top-level conversation and app controls. · `frontend/src/components/Header.tsx`
- [Overlays](https://github.com/vazanth/realtime-chat-app/tree/main/frontend/src/components): aux UI · Modal, popover, and animated UI helpers. · `frontend/src/components`

## Connections

- Server → App: boots · The server starts the Express app and HTTP listener.
- Server → Socket: attaches · The server also initializes realtime connections.
- App → Routes: mounts · App middleware delegates requests into domain routes.
- Routes → Controllers: dispatches · Routes forward work to domain controllers.
- Controllers → Validator: validates · Requests are checked before controller logic runs.
- Validator → Schemas: uses · Validation is driven by Zod schemas.
- Controllers → File state: reads/writes · Domain handlers persist and retrieve local app state.
- Controllers → Uploads: uploads · Message/file endpoints pass through upload handling.
- Socket → Chat socket: delegates · Socket bootstrap hands chat behavior to chat-specific logic.
- App → Routes: composes · The app shell renders the routed screens.
- Routes → Login: shows · Login screen is one route target.
- Routes → Register: shows · Register screen is one route target.
- Routes → Chat page: shows · Chat screen is the authenticated route target.
- Chat page → Chat list: uses · Conversation navigation is built into the chat screen.
- Chat page → Chat box: uses · Message timeline and composer are built into the chat screen.
- Chat page → Header: uses · Header controls frame the active chat view.
- Chat page → Overlays: uses · Auxiliary dialogs and popovers support chat interactions.
- Socket context → Socket: connects · The client keeps a live Socket.IO connection to the backend.
- Login → Controllers: auth HTTP · Sign-in submits to backend authentication handling.
- Register → Controllers: auth HTTP · Sign-up submits to backend authentication handling.
- Chat page → Controllers: chat HTTP · Chat metadata and message history are fetched over REST.
- Chat page → Uploads: file upload · Attachment flows use the backend upload path.
