# krishacodes30/video-chatapp architecture

> Architecture diagram of the GitHub repository krishacodes30/video-chatapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishacodes30/video-chatapp
- Repository: https://github.com/krishacodes30/video-chatapp

## Overview

This is a **full-stack MERN real-time communication app**:
- **Frontend (React + Vite + Tailwind)** in `zoom/`
- **Backend (Node/Express)** in `backend/`
- **Database (MongoDB via Mongoose models)** in `backend/src/models/`
- **Real-time layer (Socket.IO)** in `backend/socket.js` + `backend/src/controllers/socketManager.js`
- **Peer-to-peer media (WebRTC)** implied by `zoom/src/pages/socketio/VideoCallSocket.jsx` (frontend does signaling via Socket.IO; media flows P2P)
- **Authentication** via `backend/src/middleware/authMiddleware.js` and `zoom/src/pages/Auth/*`

- **HTTP REST** is used for auth/users/chat endpoints.
- **Socket.IO** is used for real-time chat + WebRTC signaling.
- **WebRTC media** goes **directly between browsers** (not through your backend).

##### Backend structure (`backend/`)
Key files that imply architectural boundaries:
- `backend/app.js` → Express app composition (middleware, routes, server bootstrap)
- `backend/socket.js` → Socket.IO server setup / binding to HTTP server
- `backend/src/routes/*` → REST API surface
- `chat.routes.js`
- `user.routes.js`
- `backend/src/controllers/*` → business logic & orchestration
- `chat.controller.js` (chat/message operations)
- `user.controller.js` (auth/user operations)
- `socketManager.js` (real-time event handling; likely join/leave rooms, relay signaling, broadcast messages)
- `backend/src/models/*` → persistence layer (MongoDB/Mongoose)
- `user.model.js`
- `message.model.js`
- `backend/src/middleware/authMiddleware.js` → auth boundary (JWT/session/headers)

This is a classic **Express layered structure**:
**Routes → Controllers → Models → MongoDB**, with **Middleware** applied cross-cutting.

##### Frontend structure (`zoom/`)
Key indicators:
- `zoom/src/main.jsx`, `zoom/src/App.jsx` → app bootstrap + routing composition
- `zoom/src/context/UserContextApi.jsx` → global auth/user state (token, current user, login status)
- `zoom/src/pages/Auth/*` → login/logout/isLogin flows
- `zoom/src/pages/Dashboard/Dashboard.jsx` → post-auth landing, likely user list / start call / chat UI
- `zoom/src/pages/socketio/VideoCallSocket.jsx` → Socket.IO client + WebRTC signaling integration

This implies frontend layers:
**UI Pages/Components → Context (auth state) → API client (REST) + Socket.IO client → Backend**

##### REST Routes Layer
- `/users` routes (`user.routes.js`)
- `/chat` routes (`chat.routes.js`)
##### Controllers
- User Controller (`user.controller.js`)
- Chat Controller (`chat.controller.js`)
10. **Auth Middleware** (`authMiddleware.js`) (explicitly drawn as a gate in front of protected endpoints)
##### Socket.IO Server (`socket.js`)
12. **Socket Event Manager** (`socketManager.js`) (the event routing / room management / signaling relay)
##### Data Models
- User model (`user.model.js`)
- Message model (`message.model.js`)

##### Signaling path (through your backend)
Browser A ↔ Socket.IO ↔ Browser B
Events typically: `join room`, `offer`, `answer`, `ice-candidate`, `leave`

##### Media path (peer-to-peer)
Browser A ⇄ Browser B (WebRTC SRTP media)
Backend is *not* in the media plane.

##### Architectural patterns to highlight (derived from structure)
- **Layered backend**: Routes → Controllers → Models (MVC-like separation)
- **Cross-cutting middleware**: authMiddleware as a security boundary
- **Dual-channel communication**:
- REST for CRUD/auth/history
- WebSockets (Socket.IO) for presence, live chat, and signaling
- **Signaling vs media separation** (WebRTC best practice)

##### What “detailed enough” means for this repo
At minimum, include:
- REST vs Socket.IO split
- Controllers/Routes/Models layers
- Auth middleware boundary
- WebRTC signaling vs media plane separation
- Message persistence (Message model) and User persistence (User model)

## Diagram (Mermaid)

```mermaid
flowchart TD

%% ============ Diagram 1: System / Container Context ============
subgraph "Diagram 1 — System Context (MERN + Realtime + WebRTC)"
direction TB

subgraph "Clients (Browsers)"
direction TB
ClientA["Browser Client A"]:::external
ClientB["Browser Client B"]:::external

subgraph "React Frontend (zoom/)"
direction TB
FE_Root["React App (Vite + Tailwind)"]:::frontend
FE_Main["Bootstrap (main.jsx)"]:::frontend
FE_App["Routing/Composition (App.jsx)"]:::frontend

subgraph "Pages"
direction TB
FE_Auth["Auth Page (Auth.jsx)"]:::frontend
FE_Logout["Logout Button (LogoutButton.jsx)"]:::frontend
FE_IsLogin["Login Guard (isLogin.jsx)"]:::frontend
FE_Dashboard["Dashboard (Dashboard.jsx)"]:::frontend
FE_VideoCall["VideoCall + Socket.IO Signaling (VideoCallSocket.jsx)"]:::realtime
end

FE_Context["User Context / Auth State (UserContextApi.jsx)"]:::frontend
end
end

subgraph "Server (Node.js)"
direction TB

subgraph "Backend (backend/)"
direction TB
BE_Express["Express HTTP Server (app.js)"]:::backend
BE_SocketIO["Socket.IO Server (socket.js)"]:::realtime
BE_SocketMgr["Socket Event Manager (socketManager.js)"]:::realtime
end

DB[("MongoDB")]:::db
end

%% Context-level flows
ClientA -->|"LoadsSPA"| FE_Root
ClientB -->|"LoadsSPA"| FE_Root

FE_Main -->|"Bootstraps"| FE_App
FE_App -->|"Renders"| FE_Auth
FE_App -->|"Renders"| FE_Dashboard
FE_App -->|"Renders"| FE_VideoCall
FE_App -->|"Renders"| FE_IsLogin

FE_Auth -->|"Updates"| FE_Context
FE_IsLogin -->|"Reads"| FE_Context
FE_Dashboard -->|"Reads"| FE_Context
FE_VideoCall -->|"Reads"| FE_Context

FE_Root -->|"HTTP/JSON"| BE_Express
FE_Root <-->|"Socket.IO(WebSocket)"| BE_SocketIO

BE_Express <-->|"Queries/CRUD"| DB
BE_SocketMgr <-->|"Presence/rooms/signaling"| BE_SocketIO

%% WebRTC planes (separate signaling vs media)
ClientA <-->|"Socket.IOsignaling(offer/answer/ice/join/leave)"| BE_SocketIO
BE_SocketIO <-->|"Socket.IOsignaling(offer/answer/ice)"| ClientB

ClientA <==>|"WebRTCmedia(SRTP)P2P"| ClientB
end

%% ============ Diagram 2: Backend Component / Code-Accurate ============
subgraph "Diagram 2 — Backend Component Diagram (Express Layers + Socket.IO)"
direction TB

subgraph "HTTP (Express)"
direction TB
B2_App["Express App (backend/app.js)"]:::backend

subgraph "REST Routes"
direction TB
B2_UserRoutes["/users Routes (user.routes.js)"]:::backend
B2_ChatRoutes["/chat Routes (chat.routes.js)"]:::backend
end

B2_AuthMW["Auth Middleware (authMiddleware.js)"]:::security

subgraph "Controllers"
direction TB
B2_UserCtrl["User Controller (user.controller.js)"]:::backend
B2_ChatCtrl["Chat Controller (chat.controller.js)"]:::backend
end

subgraph "Models (Mongoose)"
direction TB
B2_UserModel["User Model (user.model.js)"]:::model
B2_MessageModel["Message Model (message.model.js)"]:::model
end

B2_DB[("MongoDB")]:::db
end

subgraph "Realtime (Socket.IO)"
direction TB
B2_SocketServer["Socket.IO Server (backend/socket.js)"]:::realtime
B2_SocketMgr["Socket Manager (socketManager.js)"]:::realtime
end

%% HTTP layering (Routes -> Middleware -> Controllers -> Models -> DB)
B2_App -->|"mounts"| B2_UserRoutes
B2_App -->|"mounts"| B2_ChatRoutes

B2_UserRoutes -->|"protects"| B2_AuthMW
B2_ChatRoutes -->|"protects"| B2_AuthMW

B2_AuthMW -->|"next()"| B2_UserCtrl
B2_AuthMW -->|"next()"| B2_ChatCtrl

B2_UserCtrl -->|"CRUD"| B2_UserModel
B2_ChatCtrl -->|"CRUD"| B2_MessageModel

B2_UserModel <-->|"Mongoose"| B2_DB
B2_MessageModel <-->|"Mongoose"| B2_DB

%% Socket.IO event path
B2_App -->|"httpServerbind"| B2_SocketServer
B2_SocketServer -->|"routesEventsTo"| B2_SocketMgr
B2_SocketMgr -->|"mayPersistUsers"| B2_UserModel
B2_SocketMgr -->|"mayPersistMessages"| B2_MessageModel
end

%% ---------------- Click Events (from component_mapping) ----------------
click FE_Main "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/main.jsx"
click FE_App "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/App.jsx"
click FE_Context "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/context/UserContextApi.jsx"
click FE_Auth "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/pages/Auth/Auth.jsx"
click FE_Logout "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/pages/Auth/LogoutButton.jsx"
click FE_IsLogin "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/pages/Auth/isLogin.jsx"
click FE_Dashboard "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/pages/Dashboard/Dashboard.jsx"
click FE_VideoCall "https://github.com/krishacodes30/video-chatapp/blob/main/zoom/src/pages/socketio/VideoCallSocket.jsx"

click BE_Express "https://github.com/krishacodes30/video-chatapp/blob/main/backend/app.js"
click BE_SocketIO "https://github.com/krishacodes30/video-chatapp/blob/main/backend/socket.js"
click B2_ChatRoutes "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/routes/chat.routes.js"
click B2_UserRoutes "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/routes/user.routes.js"
click B2_ChatCtrl "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/controllers/chat.controller.js"
click B2_UserCtrl "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/controllers/user.controller.js"
click BE_SocketMgr "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/controllers/socketManager.js"
click B2_SocketMgr "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/controllers/socketManager.js"
click B2_AuthMW "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/middleware/authMiddleware.js"
click B2_UserModel "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/models/user.model.js"
click B2_MessageModel "https://github.com/krishacodes30/video-chatapp/blob/main/backend/src/models/message.model.js"

%% ---------------- Styles ----------------
classDef frontend fill:#1f77ff,stroke:#0b3d91,stroke-width:1px,color:#ffffff;
classDef backend fill:#2ecc71,stroke:#1e8449,stroke-width:1px,color:#0b1b10;
classDef realtime fill:#ff9f1a,stroke:#b86200,stroke-width:1px,color:#1f1200;
classDef security fill:#e74c3c,stroke:#922b21,stroke-width:1px,color:#ffffff;
classDef model fill:#7bdcb5,stroke:#1e8449,stroke-width:1px,color:#0b1b10;
classDef db fill:#95a5a6,stroke:#5d6d7e,stroke-width:1px,color:#111111;
classDef external fill:#34495e,stroke:#1f2d3a,stroke-width:1px,color:#ffffff;

%% Special media-plane styling (thick purple)
linkStyle 18 stroke:#7e3ff2,stroke-width:6px,opacity:0.95
```
