# aman6012/realtime-chat architecture

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

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

## Overview

Realtime Chat is a browser chat client backed by an Express/Socket.IO server and MongoDB. Users register or log in, then join a room, load recent messages and online users, and exchange live messages; the server also supports private messages and message-history APIs. The graph follows calls and data transfers shown in the client, server entry point, routes, and socket handlers. Room model and user-directory route are included based on the source index; their internal behavior is not excerpted.

Main entry points: [`client/src/App.tsx`](https://github.com/aman6012/realtime-chat/blob/main/client/src/App.tsx) (Chat interface), [`server/src/index.ts`](https://github.com/aman6012/realtime-chat/blob/main/server/src/index.ts) (HTTP and socket server), [`server/src/routes/auth.ts`](https://github.com/aman6012/realtime-chat/blob/main/server/src/routes/auth.ts) (Authentication routes), [`server/src/socketHandlers/index.ts`](https://github.com/aman6012/realtime-chat/blob/main/server/src/socketHandlers/index.ts) (Live chat handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_app["Chat interface<br/>[App.tsx]"]
end

subgraph group_server["Server API and realtime"]
  node_entry["HTTP and socket server<br/>[index.ts]"]
  node_auth["Authentication routes<br/>[auth.ts]"]
  node_authmw["JWT authentication<br/>[auth.ts]"]
  node_validation["Input validation<br/>[validation.ts]"]
  node_messagesapi["Message history API<br/>[messages.ts]"]
  node_usersapi["Online user API<br/>[users.ts]"]
  node_socket["Live chat handlers<br/>[index.ts]"]
  node_legacy["Standalone chat server<br/>[index.js]"]
end

subgraph group_domain["Domain and persistence"]
  node_user[("User records<br/>[User.ts]")]
  node_message[("Message records<br/>[Message.ts]")]
  node_room[("Room model<br/>[Room.ts]")]
  node_types["Domain types<br/>[index.ts]"]
  node_legacyuser[("Legacy user model<br/>[User.js]")]
  node_legacymessage[("Legacy message model<br/>[Message.js]")]
end

node_person(("Chat user"))

node_person -->|"uses"| node_app
node_app -->|"registers or logs in"| node_auth
node_entry -->|"mounts routes"| node_auth
node_auth -->|"validates input"| node_validation
node_auth -->|"reads and updates"| node_user
node_auth -->|"protects endpoints"| node_authmw
node_app -->|"opens socket"| node_entry
node_app -->|"requests history"| node_messagesapi
node_app -->|"requests online users"| node_usersapi
node_entry -->|"mounts routes"| node_messagesapi
node_entry -->|"mounts routes"| node_usersapi
node_entry -->|"registers handlers"| node_socket
node_messagesapi -->|"authenticates requests"| node_authmw
node_messagesapi -->|"queries history"| node_message
node_socket -->|"stores and loads"| node_message
node_socket -->|"updates presence"| node_user
node_socket -->|"validates messages"| node_validation
node_app -->|"joins and exchanges events"| node_socket
node_legacy -->|"uses"| node_legacyuser
node_legacy -->|"uses"| node_legacymessage
node_user -->|"implements"| node_types
node_message -->|"implements"| node_types
node_room -->|"implements"| node_types

click node_app "https://github.com/aman6012/realtime-chat/blob/main/client/src/App.tsx"
click node_entry "https://github.com/aman6012/realtime-chat/blob/main/server/src/index.ts"
click node_auth "https://github.com/aman6012/realtime-chat/blob/main/server/src/routes/auth.ts"
click node_authmw "https://github.com/aman6012/realtime-chat/blob/main/server/src/middleware/auth.ts"
click node_validation "https://github.com/aman6012/realtime-chat/blob/main/server/src/middleware/validation.ts"
click node_messagesapi "https://github.com/aman6012/realtime-chat/blob/main/server/src/routes/messages.ts"
click node_usersapi "https://github.com/aman6012/realtime-chat/blob/main/server/src/routes/users.ts"
click node_socket "https://github.com/aman6012/realtime-chat/blob/main/server/src/socketHandlers/index.ts"
click node_user "https://github.com/aman6012/realtime-chat/blob/main/server/src/models/User.ts"
click node_message "https://github.com/aman6012/realtime-chat/blob/main/server/src/models/Message.ts"
click node_room "https://github.com/aman6012/realtime-chat/blob/main/server/src/models/Room.ts"
click node_types "https://github.com/aman6012/realtime-chat/blob/main/server/src/types/index.ts"
click node_legacy "https://github.com/aman6012/realtime-chat/blob/main/realtime-chat/index.js"
click node_legacyuser "https://github.com/aman6012/realtime-chat/blob/main/realtime-chat/models/User.js"
click node_legacymessage "https://github.com/aman6012/realtime-chat/blob/main/realtime-chat/models/Message.js"

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_app,node_person toneBlue
class node_entry,node_auth,node_authmw,node_validation,node_messagesapi,node_usersapi,node_socket,node_legacy toneAmber
class node_user,node_message,node_room,node_types,node_legacyuser,node_legacymessage toneMint
```

## Components

### Chat client

- [Chat interface](https://github.com/aman6012/realtime-chat/blob/main/client/src/App.tsx): `client/src/App.tsx`

### Server API and realtime

- [HTTP and socket server](https://github.com/aman6012/realtime-chat/blob/main/server/src/index.ts): `server/src/index.ts`
- [Authentication routes](https://github.com/aman6012/realtime-chat/blob/main/server/src/routes/auth.ts): `server/src/routes/auth.ts`
- [JWT authentication](https://github.com/aman6012/realtime-chat/blob/main/server/src/middleware/auth.ts): `server/src/middleware/auth.ts`
- [Input validation](https://github.com/aman6012/realtime-chat/blob/main/server/src/middleware/validation.ts): `server/src/middleware/validation.ts`
- [Message history API](https://github.com/aman6012/realtime-chat/blob/main/server/src/routes/messages.ts): `server/src/routes/messages.ts`
- [Online user API](https://github.com/aman6012/realtime-chat/blob/main/server/src/routes/users.ts): `server/src/routes/users.ts`
- [Live chat handlers](https://github.com/aman6012/realtime-chat/blob/main/server/src/socketHandlers/index.ts): `server/src/socketHandlers/index.ts`
- [Standalone chat server](https://github.com/aman6012/realtime-chat/blob/main/realtime-chat/index.js): `realtime-chat/index.js`

### Domain and persistence

- [User records](https://github.com/aman6012/realtime-chat/blob/main/server/src/models/User.ts): `server/src/models/User.ts`
- [Message records](https://github.com/aman6012/realtime-chat/blob/main/server/src/models/Message.ts): `server/src/models/Message.ts`
- [Room model](https://github.com/aman6012/realtime-chat/blob/main/server/src/models/Room.ts): `server/src/models/Room.ts`
- [Domain types](https://github.com/aman6012/realtime-chat/blob/main/server/src/types/index.ts): `server/src/types/index.ts`
- [Legacy user model](https://github.com/aman6012/realtime-chat/blob/main/realtime-chat/models/User.js): `realtime-chat/models/User.js`
- [Legacy message model](https://github.com/aman6012/realtime-chat/blob/main/realtime-chat/models/Message.js): `realtime-chat/models/Message.js`

### Other components

- **Chat user**

## Connections

- Chat user → Chat interface: uses (evidence: `client/src/App.tsx`)
- Chat interface → Authentication routes: registers or logs in (evidence: `client/src/App.tsx`)
- HTTP and socket server → Authentication routes: mounts routes (evidence: `server/src/index.ts`)
- Authentication routes → Input validation: validates input (evidence: `server/src/routes/auth.ts`)
- Authentication routes → User records: reads and updates (evidence: `server/src/routes/auth.ts`)
- Authentication routes → JWT authentication: protects endpoints (evidence: `server/src/routes/auth.ts`)
- Chat interface → HTTP and socket server: opens socket (evidence: `client/src/App.tsx`)
- Chat interface → Message history API: requests history (evidence: `client/src/App.tsx`)
- Chat interface → Online user API: requests online users (evidence: `client/src/App.tsx`)
- HTTP and socket server → Message history API: mounts routes (evidence: `server/src/index.ts`)
- HTTP and socket server → Online user API: mounts routes (evidence: `server/src/index.ts`)
- HTTP and socket server → Live chat handlers: registers handlers (evidence: `server/src/index.ts`)
- Message history API → JWT authentication: authenticates requests (evidence: `server/src/routes/messages.ts`)
- Message history API → Message records: queries history (evidence: `server/src/routes/messages.ts`)
- Live chat handlers → Message records: stores and loads (evidence: `server/src/socketHandlers/index.ts`)
- Live chat handlers → User records: updates presence (evidence: `server/src/socketHandlers/index.ts`)
- Live chat handlers → Input validation: validates messages (evidence: `server/src/socketHandlers/index.ts`)
- Chat interface → Live chat handlers: joins and exchanges events (evidence: `client/src/App.tsx`)
- Standalone chat server → Legacy user model: uses (evidence: `realtime-chat/index.js`)
- Standalone chat server → Legacy message model: uses (evidence: `realtime-chat/index.js`)
- User records → Domain types: implements (evidence: `server/src/models/User.ts`)
- Message records → Domain types: implements (evidence: `server/src/models/Message.ts`)
- Room model → Domain types: implements (evidence: `server/src/models/Room.ts`)
