# hamzask018/chatapp_scalable architecture

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

- Interactive diagram: https://gitdiagram.com/hamzask018/chatapp_scalable
- Repository: https://github.com/hamzask018/chatapp_scalable

## Overview

This repository implements a chat application with OTP-based login, user profiles, one-to-one chats, text/image messages, and email delivery of login codes. The main workflow starts with a user requesting an OTP, verifying it, then using the chat interface to create chats and exchange messages. The backend separates user, chat, and mail services; MongoDB-backed models hold users, chats, and messages, while Redis stores OTPs and RabbitMQ carries email jobs. Frontend-to-chat API wiring is only partly visible in the supplied excerpts.

Main entry points: [`backend/user/src/routes/user.ts`](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/routes/user.ts) (User API), [`backend/user/src/controllers/user.ts`](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/controllers/user.ts) (User workflows), [`backend/chat/src/controllers/chat.ts`](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/controllers/chat.ts) (Chat workflows), [`backend/chat/src/routes/chat.ts`](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/routes/chat.ts) (Chat API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web client"]
  node_login["Login page<br/>[page.tsx]"]
  node_verify["OTP verification<br/>[verifyOtp.tsx]"]
  node_chatui["Chat page<br/>[page.tsx]"]
  node_sidebar["Chat sidebar<br/>[ChatSidebar.tsx]"]
  node_appcontext["App context<br/>[AppContext.tsx]"]
end

subgraph group_identity["Identity and email"]
  node_userapi["User API<br/>[user.ts]"]
  node_userctrl["User workflows<br/>[user.ts]"]
  node_userauth["JWT authentication<br/>[isAuth.ts]"]
  node_publisher["Email queue publisher<br/>[rabbitmq.ts]"]
  node_mailworker["OTP mail consumer<br/>[consumer.ts]"]
end

subgraph group_messaging["Chat and messages"]
  node_chatapi["Chat API<br/>[chat.ts]"]
  node_chatctrl["Chat workflows<br/>[chat.ts]"]
  node_chatauth["Chat authentication<br/>[isAuth.ts]"]
  node_upload["Image upload<br/>[multer.ts]"]
end

subgraph group_state["Data and infrastructure"]
  node_usermodel[("User records<br/>[user.ts]")]
  node_otpstore[("OTP and rate limits<br/>[redis.ts]")]
  node_chatmodel[("Chat records<br/>[chat.ts]")]
  node_messages[("Message records<br/>[messages.ts]")]
  node_cloudinary["Image storage<br/>[cloudinary.ts]"]
end

node_visitor(("User"))

node_visitor -->|"requests login"| node_login
node_visitor -->|"enters code"| node_verify
node_visitor -->|"uses chat"| node_chatui
node_verify -->|"posts OTP"| node_userapi
node_verify -->|"updates auth state"| node_appcontext
node_chatui -.->|"renders"| node_sidebar
node_login -.->|"requests OTP"| node_userapi
node_userapi -->|"guards profile routes"| node_userauth
node_userapi -->|"dispatches routes"| node_userctrl
node_userctrl -->|"stores and checks codes"| node_otpstore
node_userctrl -->|"publishes email job"| node_publisher
node_userctrl -->|"reads and writes users"| node_usermodel
node_publisher -.->|"queues OTP email"| node_mailworker
node_mailworker -->|"sends email"| node_visitor
node_chatapi -->|"authenticates requests"| node_chatauth
node_chatapi -->|"processes image upload"| node_upload
node_chatapi -->|"dispatches routes"| node_chatctrl
node_chatctrl -->|"reads and writes chats"| node_chatmodel
node_chatctrl -->|"reads and writes messages"| node_messages
node_upload -->|"uploads images"| node_cloudinary
node_chatctrl -->|"fetches participant profile"| node_userapi
node_chatui -.->|"uses chat endpoints"| node_chatapi

click node_login "https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/app/login/page.tsx"
click node_verify "https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/components/verifyOtp.tsx"
click node_chatui "https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/app/chat/page.tsx"
click node_sidebar "https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/components/ChatSidebar.tsx"
click node_appcontext "https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/context/AppContext.tsx"
click node_userapi "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/routes/user.ts"
click node_userctrl "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/controllers/user.ts"
click node_userauth "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/middleware/isAuth.ts"
click node_usermodel "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/model/user.ts"
click node_otpstore "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/config/redis.ts"
click node_publisher "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/config/rabbitmq.ts"
click node_mailworker "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/mail/src/consumer.ts"
click node_chatapi "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/routes/chat.ts"
click node_chatctrl "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/controllers/chat.ts"
click node_chatauth "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/middlewares/isAuth.ts"
click node_upload "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/middlewares/multer.ts"
click node_chatmodel "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/models/chat.ts"
click node_messages "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/models/messages.ts"
click node_cloudinary "https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/config/cloudinary.ts"

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_login,node_verify,node_chatui,node_sidebar,node_appcontext,node_visitor toneBlue
class node_userapi,node_userctrl,node_userauth,node_publisher,node_mailworker toneAmber
class node_chatapi,node_chatctrl,node_chatauth,node_upload toneMint
class node_usermodel,node_otpstore,node_chatmodel,node_messages,node_cloudinary toneRose
```

## Components

### Web client

- [Login page](https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/app/login/page.tsx): `frontend/app/login/page.tsx`
- [OTP verification](https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/components/verifyOtp.tsx): `frontend/components/verifyOtp.tsx`
- [Chat page](https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/app/chat/page.tsx): `frontend/app/chat/page.tsx`
- [Chat sidebar](https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/components/ChatSidebar.tsx): `frontend/components/ChatSidebar.tsx`
- [App context](https://github.com/hamzask018/chatapp_scalable/blob/main/frontend/context/AppContext.tsx): `frontend/context/AppContext.tsx`

### Identity and email

- [User API](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/routes/user.ts): `backend/user/src/routes/user.ts`
- [User workflows](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/controllers/user.ts): `backend/user/src/controllers/user.ts`
- [JWT authentication](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/middleware/isAuth.ts): `backend/user/src/middleware/isAuth.ts`
- [Email queue publisher](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/config/rabbitmq.ts): `backend/user/src/config/rabbitmq.ts`
- [OTP mail consumer](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/mail/src/consumer.ts): `backend/mail/src/consumer.ts`

### Chat and messages

- [Chat API](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/routes/chat.ts): `backend/chat/src/routes/chat.ts`
- [Chat workflows](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/controllers/chat.ts): `backend/chat/src/controllers/chat.ts`
- [Chat authentication](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/middlewares/isAuth.ts): `backend/chat/src/middlewares/isAuth.ts`
- [Image upload](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/middlewares/multer.ts): `backend/chat/src/middlewares/multer.ts`

### Data and infrastructure

- [User records](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/model/user.ts): `backend/user/src/model/user.ts`
- [OTP and rate limits](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/user/src/config/redis.ts): `backend/user/src/config/redis.ts`
- [Chat records](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/models/chat.ts): `backend/chat/src/models/chat.ts`
- [Message records](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/models/messages.ts): `backend/chat/src/models/messages.ts`
- [Image storage](https://github.com/hamzask018/chatapp_scalable/blob/main/backend/chat/src/config/cloudinary.ts): `backend/chat/src/config/cloudinary.ts`

### Other components

- **User**

## Connections

- User → Login page: requests login
- User → OTP verification: enters code
- User → Chat page: uses chat
- OTP verification → User API: posts OTP (evidence: `frontend/components/verifyOtp.tsx`)
- OTP verification → App context: updates auth state (evidence: `frontend/components/verifyOtp.tsx`)
- Chat page → Chat sidebar: renders
- Login page → User API: requests OTP
- User API → JWT authentication: guards profile routes (evidence: `backend/user/src/routes/user.ts`)
- User API → User workflows: dispatches routes (evidence: `backend/user/src/routes/user.ts`)
- User workflows → OTP and rate limits: stores and checks codes (evidence: `backend/user/src/controllers/user.ts`)
- User workflows → Email queue publisher: publishes email job (evidence: `backend/user/src/controllers/user.ts`)
- User workflows → User records: reads and writes users (evidence: `backend/user/src/controllers/user.ts`)
- Email queue publisher → OTP mail consumer: queues OTP email
- OTP mail consumer → User: sends email (evidence: `backend/mail/src/consumer.ts`)
- Chat API → Chat authentication: authenticates requests (evidence: `backend/chat/src/routes/chat.ts`)
- Chat API → Image upload: processes image upload (evidence: `backend/chat/src/routes/chat.ts`)
- Chat API → Chat workflows: dispatches routes (evidence: `backend/chat/src/routes/chat.ts`)
- Chat workflows → Chat records: reads and writes chats (evidence: `backend/chat/src/controllers/chat.ts`)
- Chat workflows → Message records: reads and writes messages (evidence: `backend/chat/src/controllers/chat.ts`)
- Image upload → Image storage: uploads images (evidence: `backend/chat/src/middlewares/multer.ts`)
- Chat workflows → User API: fetches participant profile (evidence: `backend/chat/src/controllers/chat.ts`)
- Chat page → Chat API: uses chat endpoints
