# bhargav-sadineni/chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/bhargav-sadineni/chat-app
- Repository: https://github.com/bhargav-sadineni/chat-app

## Overview

QuickChat is a real-time messaging and calling application with group conversations, media sharing, and Gemini-powered assistance. A user enters through authenticated React pages; chat state coordinates REST operations and live updates, while the Express server routes authenticated requests to domain controllers and MongoDB models. Calls use client-side WebRTC media with Socket.io signaling; the server also tracks call lifecycle and history. The README documents the main capabilities, but several frontend and server files were not sampled, so those subsystem details are represented without speculative internal call chains.

Main entry points: [`server/server.js`](https://github.com/bhargav-sadineni/chat-app/blob/main/server/server.js) (HTTP and Socket.IO), [`client/src/components/ChatContainer.jsx`](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/ChatContainer.jsx) (Chat interface), [`server/controllers/aiController.js`](https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/aiController.js) (AI conversation service), [`client/context/CallContext.jsx`](https://github.com/bhargav-sadineni/chat-app/blob/main/client/context/CallContext.jsx) (WebRTC call state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client experience"]
  node_app["App routing<br/>[App.jsx]"]
  node_auth["Auth and presence<br/>[Authcontext.jsx]"]
  node_chat_ui["Chat interface<br/>[ChatContainer.jsx]"]
  node_message_ui["Message display<br/>[MessageBubble.jsx]"]
  node_image_viewer["Image viewer"]
  node_ai_ui["AI assist panel<br/>[AIAssistPanel.jsx]"]
end

subgraph group_messaging["Messaging and groups"]
  node_chat_state["Chat state<br/>[ChatContext.jsx]"]
  node_group_ui["Group management UI"]
end

subgraph group_calling["Calls and signaling"]
  node_call_state["WebRTC call state<br/>[CallContext.jsx]"]
  node_call_screen["Call screen<br/>[CallScreen.jsx]"]
  node_incoming_call["Incoming call UI"]
end

subgraph group_server["Server domain services"]
  node_server_entry["HTTP and Socket.IO<br/>[server.js]"]
  node_auth_middleware["JWT protection<br/>[auth.js]"]
  node_message_routes["Message routes<br/>[messageRoutes.js]"]
  node_message_controller["Message operations"]
  node_message_store[("Message records<br/>[Message.js]")]
  node_user_store[("User records<br/>[User.js]")]
  node_group_store[("Group records<br/>[Group.js]")]
  node_group_routes["Group routes<br/>[groupRoutes.js]"]
  node_group_controller["Group operations<br/>[groupController.js]"]
  node_ai_routes["AI routes<br/>[aiRoutes.js]"]
  node_ai_controller["AI conversation service<br/>[aiController.js]"]
  node_call_routes["Call history routes<br/>[callRoutes.js]"]
  node_call_controller["Call history operations<br/>[callController.js]"]
  node_call_store[("Call history records<br/>[CallLog.js]")]
end

subgraph group_integrations["External services"]
  node_gemini["Gemini client<br/>[gemini.js]"]
  node_gemini_service{{"Google Gemini"}}
  node_cloudinary_lib["Media upload client<br/>[cloudinary.js]"]
  node_cloudinary_service{{"Cloudinary storage"}}
  node_mongodb[("MongoDB")]
end

node_person(("User"))
node_webrtc_peers(("Peer devices"))

node_person -->|"uses"| node_app
node_app -->|"checks session"| node_auth
node_app -.->|"renders chat"| node_chat_ui
node_auth -.->|"REST and socket"| node_server_entry
node_chat_ui -->|"uses chat state"| node_chat_state
node_chat_ui -->|"renders messages"| node_message_ui
node_chat_ui -->|"opens media"| node_image_viewer
node_chat_ui -->|"opens assistant"| node_ai_ui
node_chat_state -->|"requests messages"| node_message_routes
node_person -.->|"manages groups"| node_group_ui
node_group_ui -->|"uses group state"| node_chat_state
node_server_entry -->|"mounts routes"| node_message_routes
node_server_entry -->|"mounts routes"| node_group_routes
node_server_entry -->|"mounts routes"| node_ai_routes
node_server_entry -->|"mounts routes"| node_call_routes
node_message_routes -->|"protects endpoints"| node_auth_middleware
node_message_routes -->|"dispatches requests"| node_message_controller
node_message_controller -->|"reads and writes"| node_message_store
node_message_controller -->|"checks group"| node_group_store
node_message_controller -->|"uploads media"| node_cloudinary_lib
node_cloudinary_lib -.->|"stores media"| node_cloudinary_service
node_group_routes -->|"protects endpoints"| node_auth_middleware
node_group_routes -->|"dispatches requests"| node_group_controller
node_group_controller -->|"reads and writes"| node_group_store
node_group_controller -->|"uses messages"| node_message_store
node_ai_routes -->|"protects endpoints"| node_auth_middleware
node_ai_routes -->|"dispatches requests"| node_ai_controller
node_ai_controller -->|"loads transcript"| node_message_store
node_ai_controller -->|"loads participants"| node_user_store
node_ai_controller -->|"loads group context"| node_group_store
node_ai_controller -->|"requests answers"| node_gemini
node_gemini -.->|"queries model"| node_gemini_service
node_ai_ui -.->|"requests AI"| node_chat_state
node_call_state -->|"uses socket"| node_auth
node_call_screen -->|"controls call"| node_call_state
node_incoming_call -->|"handles invite"| node_call_state
node_call_state -.->|"exchanges media"| node_webrtc_peers
node_call_state -.->|"signals call"| node_server_entry
node_call_routes -->|"protects endpoints"| node_auth_middleware
node_call_routes -->|"dispatches requests"| node_call_controller
node_call_controller -->|"reads and writes"| node_call_store
node_server_entry -->|"connects database"| node_mongodb
node_auth_middleware -->|"loads account"| node_user_store

click node_app "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/App.jsx"
click node_auth "https://github.com/bhargav-sadineni/chat-app/blob/main/client/context/Authcontext.jsx"
click node_chat_ui "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/ChatContainer.jsx"
click node_message_ui "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/MessageBubble.jsx"
click node_image_viewer "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/ImageViewerModal.jsx"
click node_chat_state "https://github.com/bhargav-sadineni/chat-app/blob/main/client/context/ChatContext.jsx"
click node_group_ui "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/GroupInfoSidebar.jsx"
click node_server_entry "https://github.com/bhargav-sadineni/chat-app/blob/main/server/server.js"
click node_auth_middleware "https://github.com/bhargav-sadineni/chat-app/blob/main/server/middleware/auth.js"
click node_message_routes "https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/messageRoutes.js"
click node_message_controller "https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/messageController.js"
click node_message_store "https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/Message.js"
click node_user_store "https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/User.js"
click node_group_store "https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/Group.js"
click node_group_routes "https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/groupRoutes.js"
click node_group_controller "https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/groupController.js"
click node_ai_ui "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/AIAssistPanel.jsx"
click node_ai_routes "https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/aiRoutes.js"
click node_ai_controller "https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/aiController.js"
click node_gemini "https://github.com/bhargav-sadineni/chat-app/blob/main/server/lib/gemini.js"
click node_call_state "https://github.com/bhargav-sadineni/chat-app/blob/main/client/context/CallContext.jsx"
click node_call_screen "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/CallScreen.jsx"
click node_incoming_call "https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/IncomingCallModal.jsx"
click node_call_routes "https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/callRoutes.js"
click node_call_controller "https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/callController.js"
click node_call_store "https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/CallLog.js"
click node_cloudinary_lib "https://github.com/bhargav-sadineni/chat-app/blob/main/server/lib/cloudinary.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_auth,node_chat_ui,node_message_ui,node_image_viewer,node_ai_ui,node_person toneBlue
class node_chat_state,node_group_ui toneAmber
class node_call_state,node_call_screen,node_incoming_call toneMint
class node_server_entry,node_auth_middleware,node_message_routes,node_message_controller,node_message_store,node_user_store,node_group_store,node_group_routes,node_group_controller,node_ai_routes,node_ai_controller,node_call_routes,node_call_controller,node_call_store toneRose
class node_gemini,node_gemini_service,node_cloudinary_lib,node_cloudinary_service,node_mongodb,node_webrtc_peers toneIndigo
```

## Components

### Client experience

- [App routing](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Auth and presence](https://github.com/bhargav-sadineni/chat-app/blob/main/client/context/Authcontext.jsx): `client/context/Authcontext.jsx`
- [Chat interface](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/ChatContainer.jsx): `client/src/components/ChatContainer.jsx`
- [Message display](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/MessageBubble.jsx): `client/src/components/MessageBubble.jsx`
- [Image viewer](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/ImageViewerModal.jsx): `client/src/components/ImageViewerModal.jsx`
- [AI assist panel](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/AIAssistPanel.jsx): `client/src/components/AIAssistPanel.jsx`

### Messaging and groups

- [Chat state](https://github.com/bhargav-sadineni/chat-app/blob/main/client/context/ChatContext.jsx): `client/context/ChatContext.jsx`
- [Group management UI](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/GroupInfoSidebar.jsx): `client/src/components/GroupInfoSidebar.jsx`

### Calls and signaling

- [WebRTC call state](https://github.com/bhargav-sadineni/chat-app/blob/main/client/context/CallContext.jsx): `client/context/CallContext.jsx`
- [Call screen](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/CallScreen.jsx): `client/src/components/CallScreen.jsx`
- [Incoming call UI](https://github.com/bhargav-sadineni/chat-app/blob/main/client/src/components/IncomingCallModal.jsx): `client/src/components/IncomingCallModal.jsx`

### Server domain services

- [HTTP and Socket.IO](https://github.com/bhargav-sadineni/chat-app/blob/main/server/server.js): `server/server.js`
- [JWT protection](https://github.com/bhargav-sadineni/chat-app/blob/main/server/middleware/auth.js): `server/middleware/auth.js`
- [Message routes](https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/messageRoutes.js): `server/routes/messageRoutes.js`
- [Message operations](https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/messageController.js): `server/controllers/messageController.js`
- [Message records](https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/Message.js): `server/models/Message.js`
- [User records](https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/User.js): `server/models/User.js`
- [Group records](https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/Group.js): `server/models/Group.js`
- [Group routes](https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/groupRoutes.js): `server/routes/groupRoutes.js`
- [Group operations](https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/groupController.js): `server/controllers/groupController.js`
- [AI routes](https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/aiRoutes.js): `server/routes/aiRoutes.js`
- [AI conversation service](https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/aiController.js): `server/controllers/aiController.js`
- [Call history routes](https://github.com/bhargav-sadineni/chat-app/blob/main/server/routes/callRoutes.js): `server/routes/callRoutes.js`
- [Call history operations](https://github.com/bhargav-sadineni/chat-app/blob/main/server/controllers/callController.js): `server/controllers/callController.js`
- [Call history records](https://github.com/bhargav-sadineni/chat-app/blob/main/server/models/CallLog.js): `server/models/CallLog.js`

### External services

- [Gemini client](https://github.com/bhargav-sadineni/chat-app/blob/main/server/lib/gemini.js): `server/lib/gemini.js`
- **Google Gemini**
- [Media upload client](https://github.com/bhargav-sadineni/chat-app/blob/main/server/lib/cloudinary.js): `server/lib/cloudinary.js`
- **Cloudinary storage**
- **MongoDB**

### Other components

- **User**
- **Peer devices**

## Connections

- User → App routing: uses (evidence: `client/src/App.jsx`)
- App routing → Auth and presence: checks session (evidence: `client/src/App.jsx`)
- App routing → Chat interface: renders chat
- Auth and presence → HTTP and Socket.IO: REST and socket
- Chat interface → Chat state: uses chat state (evidence: `client/src/components/ChatContainer.jsx`)
- Chat interface → Message display: renders messages (evidence: `client/src/components/ChatContainer.jsx`)
- Chat interface → Image viewer: opens media (evidence: `client/src/components/ChatContainer.jsx`)
- Chat interface → AI assist panel: opens assistant (evidence: `client/src/components/ChatContainer.jsx`)
- Chat state → Message routes: requests messages (evidence: `client/context/ChatContext.jsx`)
- User → Group management UI: manages groups
- Group management UI → Chat state: uses group state (evidence: `client/src/components/GroupInfoSidebar.jsx`)
- HTTP and Socket.IO → Message routes: mounts routes (evidence: `server/server.js`)
- HTTP and Socket.IO → Group routes: mounts routes (evidence: `server/server.js`)
- HTTP and Socket.IO → AI routes: mounts routes (evidence: `server/server.js`)
- HTTP and Socket.IO → Call history routes: mounts routes (evidence: `server/server.js`)
- Message routes → JWT protection: protects endpoints (evidence: `server/routes/messageRoutes.js`)
- Message routes → Message operations: dispatches requests (evidence: `server/routes/messageRoutes.js`)
- Message operations → Message records: reads and writes (evidence: `server/controllers/messageController.js`)
- Message operations → Group records: checks group (evidence: `server/controllers/messageController.js`)
- Message operations → Media upload client: uploads media (evidence: `server/controllers/messageController.js`)
- Media upload client → Cloudinary storage: stores media
- Group routes → JWT protection: protects endpoints (evidence: `server/routes/groupRoutes.js`)
- Group routes → Group operations: dispatches requests (evidence: `server/routes/groupRoutes.js`)
- Group operations → Group records: reads and writes (evidence: `server/controllers/groupController.js`)
- Group operations → Message records: uses messages (evidence: `server/controllers/groupController.js`)
- AI routes → JWT protection: protects endpoints (evidence: `server/routes/aiRoutes.js`)
- AI routes → AI conversation service: dispatches requests (evidence: `server/routes/aiRoutes.js`)
- AI conversation service → Message records: loads transcript (evidence: `server/controllers/aiController.js`)
- AI conversation service → User records: loads participants (evidence: `server/controllers/aiController.js`)
- AI conversation service → Group records: loads group context (evidence: `server/controllers/aiController.js`)
- AI conversation service → Gemini client: requests answers (evidence: `server/controllers/aiController.js`)
- Gemini client → Google Gemini: queries model
- AI assist panel → Chat state: requests AI
- WebRTC call state → Auth and presence: uses socket (evidence: `client/context/CallContext.jsx`)
- Call screen → WebRTC call state: controls call (evidence: `client/src/components/CallScreen.jsx`)
- Incoming call UI → WebRTC call state: handles invite (evidence: `client/src/components/IncomingCallModal.jsx`)
- WebRTC call state → Peer devices: exchanges media
- WebRTC call state → HTTP and Socket.IO: signals call
- Call history routes → JWT protection: protects endpoints (evidence: `server/routes/callRoutes.js`)
- Call history routes → Call history operations: dispatches requests (evidence: `server/routes/callRoutes.js`)
- Call history operations → Call history records: reads and writes (evidence: `server/controllers/callController.js`)
- HTTP and Socket.IO → MongoDB: connects database (evidence: `server/server.js`)
- JWT protection → User records: loads account (evidence: `server/middleware/auth.js`)
