# nishit-luhadia30/chat-sphere architecture

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

- Interactive diagram: https://gitdiagram.com/nishit-luhadia30/chat-sphere
- Repository: https://github.com/nishit-luhadia30/chat-sphere

## Overview

ChatSphere is a browser-based chat product. Users register or log in, find or create private and group chats, then exchange text and uploaded files; the app also documents reactions, editing, deletion, profiles, and notifications. The frontend uses shared chat state and an API client; the Express backend protects routes and persists users, chats, and messages in MongoDB, with Cloudinary file storage and Socket.IO events. Some capabilities are documented but their implementation was not sampled, so those connections are shown only where supported.

Main entry points: [`server/server.js`](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/server.js) (HTTP and socket server), [`server/routes/fileRoutes.js`](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/fileRoutes.js) (File upload route), [`client/src/components/Chat/SingleChat.jsx`](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/SingleChat.jsx) (Conversation view), [`client/src/utils/api.js`](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/utils/api.js) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["App routing<br/>[App.jsx]"]
  node_home["Login and signup<br/>[HomePage.jsx]"]
  node_authforms["Auth forms<br/>[Login.jsx]"]
  node_chatpage["Chat workspace<br/>[ChatPage.jsx]"]
  node_context["Chat state<br/>[ChatContext.jsx]"]
  node_api["API client<br/>[api.js]"]
  node_chatlist["Chat list<br/>[MyChats.jsx]"]
  node_chatops["Chat management UI<br/>[GroupChatModal.jsx]"]
  node_usersearch["User search UI<br/>[SideDrawer.jsx]"]
end

subgraph group_identity["Identity and chats"]
  node_profileui["User profiles"]
  node_authroutes["User routes<br/>[userRoutes.js]"]
  node_usercontroller["User accounts<br/>[userController.js]"]
  node_usermodel[("User records<br/>[userModel.js]")]
  node_chatroutes["Chat routes<br/>[chatRoutes.js]"]
  node_chatcontroller["Chat operations<br/>[chatController.js]"]
  node_chatmodel[("Chat records<br/>[chatModel.js]")]
end

subgraph group_messaging["Messaging and files"]
  node_conversation["Conversation view<br/>[SingleChat.jsx]"]
  node_messageview["Message rendering<br/>[ScrollableChat.jsx]"]
  node_messageactions["Message interactions<br/>[MessageBubble.jsx]"]
  node_fileui["File upload UI<br/>[FileUpload.jsx]"]
  node_messageroutes["Message routes<br/>[messageRoutes.js]"]
  node_messagecontroller["Message operations"]
  node_messagemodel[("Message records<br/>[messageModel.js]")]
  node_fileroute["File upload route<br/>[fileRoutes.js]"]
  node_upload["Upload middleware<br/>[upload.js]"]
  node_cloudinary["Cloudinary storage<br/>[cloudinary.js]"]
end

subgraph group_platform["Backend platform"]
  node_authguard["JWT protection<br/>[authMiddleware.js]"]
  node_server["HTTP and socket server<br/>[server.js]"]
  node_database[("MongoDB connection<br/>[db.js]")]
end

node_person(("Chat user"))

node_person -->|"uses"| node_app
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_chatpage
node_home -->|"renders"| node_authforms
node_chatpage -->|"reads state"| node_context
node_chatpage -->|"renders"| node_chatlist
node_chatpage -->|"renders"| node_conversation
node_chatlist -->|"updates state"| node_context
node_chatlist -->|"opens"| node_chatops
node_usersearch -->|"reads state"| node_context
node_conversation -->|"reads state"| node_context
node_conversation -->|"renders"| node_messageview
node_messageview -->|"renders"| node_messageactions
node_messageview -->|"opens"| node_profileui
node_conversation -->|"renders"| node_fileui
node_authforms -->|"calls"| node_api
node_chatlist -->|"calls"| node_api
node_conversation -->|"calls"| node_api
node_fileui -->|"calls"| node_api
node_api -->|"sends API requests"| node_server
node_server -->|"mounts"| node_authroutes
node_server -->|"mounts"| node_chatroutes
node_server -->|"mounts"| node_messageroutes
node_server -->|"mounts"| node_fileroute
node_authroutes -->|"protects"| node_authguard
node_chatroutes -->|"protects"| node_authguard
node_messageroutes -->|"protects"| node_authguard
node_fileroute -->|"protects"| node_authguard
node_authroutes -->|"dispatches"| node_usercontroller
node_usercontroller -->|"reads and writes"| node_usermodel
node_chatroutes -->|"dispatches"| node_chatcontroller
node_chatcontroller -->|"reads and writes"| node_chatmodel
node_chatcontroller -->|"populates users"| node_usermodel
node_messageroutes -->|"dispatches"| node_messagecontroller
node_messagecontroller -->|"reads and writes"| node_messagemodel
node_messagecontroller -->|"updates latest message"| node_chatmodel
node_messagecontroller -->|"populates users"| node_usermodel
node_fileroute -->|"processes upload"| node_upload
node_fileroute -->|"uploads file"| node_cloudinary
node_fileroute -->|"creates message"| node_messagemodel
node_fileroute -->|"updates latest message"| node_chatmodel
node_server -->|"connects"| node_database
node_person -.->|"exchanges live events"| node_server

click node_app "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/App.jsx"
click node_home "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/pages/HomePage.jsx"
click node_authforms "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Auth/Login.jsx"
click node_chatpage "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/pages/ChatPage.jsx"
click node_context "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/context/ChatContext.jsx"
click node_api "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/utils/api.js"
click node_chatlist "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/MyChats.jsx"
click node_chatops "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/GroupChatModal.jsx"
click node_usersearch "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/SideDrawer.jsx"
click node_conversation "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/SingleChat.jsx"
click node_messageview "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/ScrollableChat.jsx"
click node_messageactions "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/MessageBubble.jsx"
click node_fileui "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/FileUpload.jsx"
click node_profileui "https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/UserProfileModal.jsx"
click node_authroutes "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/userRoutes.js"
click node_usercontroller "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/controllers/userController.js"
click node_usermodel "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/models/userModel.js"
click node_chatroutes "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/chatRoutes.js"
click node_chatcontroller "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/controllers/chatController.js"
click node_chatmodel "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/models/chatModel.js"
click node_messageroutes "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/messageRoutes.js"
click node_messagecontroller "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/controllers/messageController.js"
click node_messagemodel "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/models/messageModel.js"
click node_fileroute "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/fileRoutes.js"
click node_upload "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/middleware/upload.js"
click node_cloudinary "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/config/cloudinary.js"
click node_authguard "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/middleware/authMiddleware.js"
click node_server "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/server.js"
click node_database "https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/config/db.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_home,node_authforms,node_chatpage,node_context,node_api,node_chatlist,node_chatops,node_usersearch,node_person toneBlue
class node_profileui,node_authroutes,node_usercontroller,node_usermodel,node_chatroutes,node_chatcontroller,node_chatmodel toneAmber
class node_conversation,node_messageview,node_messageactions,node_fileui,node_messageroutes,node_messagecontroller,node_messagemodel,node_fileroute,node_upload,node_cloudinary toneMint
class node_authguard,node_server,node_database toneRose
```

## Components

### Web client

- [App routing](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Login and signup](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/pages/HomePage.jsx): `client/src/pages/HomePage.jsx`
- [Auth forms](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Auth/Login.jsx): `client/src/components/Auth/Login.jsx`
- [Chat workspace](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/pages/ChatPage.jsx): `client/src/pages/ChatPage.jsx`
- [Chat state](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/context/ChatContext.jsx): `client/src/context/ChatContext.jsx`
- [API client](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/utils/api.js): `client/src/utils/api.js`
- [Chat list](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/MyChats.jsx): `client/src/components/Chat/MyChats.jsx`
- [Chat management UI](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/GroupChatModal.jsx): `client/src/components/Chat/GroupChatModal.jsx`
- [User search UI](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/SideDrawer.jsx): `client/src/components/Chat/SideDrawer.jsx`

### Identity and chats

- [User profiles](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/UserProfileModal.jsx): `client/src/components/Chat/UserProfileModal.jsx`
- [User routes](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/userRoutes.js): `server/routes/userRoutes.js`
- [User accounts](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/controllers/userController.js): `server/controllers/userController.js`
- [User records](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/models/userModel.js): `server/models/userModel.js`
- [Chat routes](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/chatRoutes.js): `server/routes/chatRoutes.js`
- [Chat operations](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/controllers/chatController.js): `server/controllers/chatController.js`
- [Chat records](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/models/chatModel.js): `server/models/chatModel.js`

### Messaging and files

- [Conversation view](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/SingleChat.jsx): `client/src/components/Chat/SingleChat.jsx`
- [Message rendering](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/ScrollableChat.jsx): `client/src/components/Chat/ScrollableChat.jsx`
- [Message interactions](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/MessageBubble.jsx): `client/src/components/Chat/MessageBubble.jsx`
- [File upload UI](https://github.com/nishit-luhadia30/chat-sphere/blob/main/client/src/components/Chat/FileUpload.jsx): `client/src/components/Chat/FileUpload.jsx`
- [Message routes](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/messageRoutes.js): `server/routes/messageRoutes.js`
- [Message operations](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/controllers/messageController.js): `server/controllers/messageController.js`
- [Message records](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/models/messageModel.js): `server/models/messageModel.js`
- [File upload route](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/routes/fileRoutes.js): `server/routes/fileRoutes.js`
- [Upload middleware](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/middleware/upload.js): `server/middleware/upload.js`
- [Cloudinary storage](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/config/cloudinary.js): `server/config/cloudinary.js`

### Backend platform

- [JWT protection](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/middleware/authMiddleware.js): `server/middleware/authMiddleware.js`
- [HTTP and socket server](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/server.js): `server/server.js`
- [MongoDB connection](https://github.com/nishit-luhadia30/chat-sphere/blob/main/server/config/db.js): `server/config/db.js`

### Other components

- **Chat user**

## Connections

- Chat user → App routing: uses (evidence: `README.md`)
- App routing → Login and signup: routes to (evidence: `client/src/App.jsx`)
- App routing → Chat workspace: routes to (evidence: `client/src/App.jsx`)
- Login and signup → Auth forms: renders (evidence: `client/src/pages/HomePage.jsx`)
- Chat workspace → Chat state: reads state (evidence: `client/src/pages/ChatPage.jsx`)
- Chat workspace → Chat list: renders (evidence: `client/src/pages/ChatPage.jsx`)
- Chat workspace → Conversation view: renders (evidence: `client/src/pages/ChatPage.jsx`)
- Chat list → Chat state: updates state (evidence: `client/src/components/Chat/MyChats.jsx`)
- Chat list → Chat management UI: opens (evidence: `client/src/components/Chat/MyChats.jsx`)
- User search UI → Chat state: reads state (evidence: `client/src/components/Chat/SideDrawer.jsx`)
- Conversation view → Chat state: reads state (evidence: `client/src/components/Chat/SingleChat.jsx`)
- Conversation view → Message rendering: renders (evidence: `client/src/components/Chat/SingleChat.jsx`)
- Message rendering → Message interactions: renders (evidence: `client/src/components/Chat/ScrollableChat.jsx`)
- Message rendering → User profiles: opens (evidence: `client/src/components/Chat/ScrollableChat.jsx`)
- Conversation view → File upload UI: renders (evidence: `client/src/components/Chat/SingleChat.jsx`)
- Auth forms → API client: calls (evidence: `client/src/components/Auth/Login.jsx`)
- Chat list → API client: calls (evidence: `client/src/components/Chat/MyChats.jsx`)
- Conversation view → API client: calls (evidence: `client/src/components/Chat/SingleChat.jsx`)
- File upload UI → API client: calls (evidence: `client/src/components/Chat/FileUpload.jsx`)
- API client → HTTP and socket server: sends API requests (evidence: `README.md`)
- HTTP and socket server → User routes: mounts (evidence: `server/server.js`)
- HTTP and socket server → Chat routes: mounts (evidence: `server/server.js`)
- HTTP and socket server → Message routes: mounts (evidence: `server/server.js`)
- HTTP and socket server → File upload route: mounts (evidence: `server/server.js`)
- User routes → JWT protection: protects (evidence: `server/routes/userRoutes.js`)
- Chat routes → JWT protection: protects (evidence: `server/routes/chatRoutes.js`)
- Message routes → JWT protection: protects (evidence: `server/routes/messageRoutes.js`)
- File upload route → JWT protection: protects (evidence: `server/routes/fileRoutes.js`)
- User routes → User accounts: dispatches (evidence: `server/routes/userRoutes.js`)
- User accounts → User records: reads and writes (evidence: `server/controllers/userController.js`)
- Chat routes → Chat operations: dispatches (evidence: `server/routes/chatRoutes.js`)
- Chat operations → Chat records: reads and writes (evidence: `server/controllers/chatController.js`)
- Chat operations → User records: populates users (evidence: `server/controllers/chatController.js`)
- Message routes → Message operations: dispatches (evidence: `server/routes/messageRoutes.js`)
- Message operations → Message records: reads and writes (evidence: `server/controllers/messageController.js`)
- Message operations → Chat records: updates latest message (evidence: `server/controllers/messageController.js`)
- Message operations → User records: populates users (evidence: `server/controllers/messageController.js`)
- File upload route → Upload middleware: processes upload (evidence: `server/routes/fileRoutes.js`)
- File upload route → Cloudinary storage: uploads file (evidence: `server/routes/fileRoutes.js`)
- File upload route → Message records: creates message (evidence: `server/routes/fileRoutes.js`)
- File upload route → Chat records: updates latest message (evidence: `server/routes/fileRoutes.js`)
- HTTP and socket server → MongoDB connection: connects (evidence: `server/server.js`)
- Chat user → HTTP and socket server: exchanges live events (evidence: `README.md`)
