# arunkumar09-06/chat_application architecture

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

- Interactive diagram: https://gitdiagram.com/arunkumar09-06/chat_application
- Repository: https://github.com/arunkumar09-06/chat_application

## Overview

This is a full-stack, one-to-one real-time chat application. Users register or log in, restore a cookie-backed session, discover contacts, start or reopen a conversation, then load chat history and exchange messages over Socket.IO (with an HTTP send fallback). The backend also supports profile-picture uploads. The graph preserves the documented features while limiting relationships to those visible in excerpts or the README; unsampled modules are represented only where their paths are supported.

Main entry points: [`frontend/src/context/AuthContext.jsx`](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/context/AuthContext.jsx) (Session state), [`frontend/src/components/ChatWindow.jsx`](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/ChatWindow.jsx) (Chat and history), [`frontend/src/pages/Chat.jsx`](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/pages/Chat.jsx) (Chat workspace), [`frontend/src/api/axios.js`](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/api/axios.js) (Axios API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_app["Routes and guards<br/>[App.jsx]"]
  node_auth_pages["Login and register"]
  node_auth_context["Session state<br/>[AuthContext.jsx]"]
  node_chat_page["Chat workspace<br/>[Chat.jsx]"]
  node_sidebar["Contact discovery<br/>[Sidebar.jsx]"]
  node_profile_modal["Profile customization<br/>[ProfileModal.jsx]"]
  node_avatar["User avatar<br/>[UserAvatar.jsx]"]
  node_chat_window["Chat and history<br/>[ChatWindow.jsx]"]
  node_message_bubble["Message display<br/>[MessageBubble.jsx]"]
  node_emoji_picker["Emoji input<br/>[EmojiPicker.jsx]"]
end

subgraph group_api["HTTP API"]
  node_http_client["Axios API client<br/>[axios.js]"]
  node_express_app["HTTP app and mounts<br/>[app.js]"]
  node_auth_routes["Authentication routes<br/>[auth.routes.js]"]
  node_conversation_routes["Conversation route"]
  node_message_routes["Message routes<br/>[message.route.js]"]
  node_auth_controller["Account and profile<br/>[auth.controller.js]"]
  node_conversation_controller["Conversation setup"]
  node_message_controller["History and HTTP send"]
  node_auth_middleware["Cookie JWT guard<br/>[auth.js]"]
  node_upload_middleware["Avatar upload handling<br/>[multer.js]"]
end

subgraph group_realtime["Real-time messaging"]
  node_socket_hook["Socket client<br/>[useSocket.js]"]
  node_socket_server["Socket rooms and delivery<br/>[server.js]"]
end

subgraph group_data["Persistence and uploads"]
  node_user_model[("User records<br/>[User.js]")]
  node_conversation_model[("Conversation records<br/>[Conversation.js]")]
  node_message_model[("Message records<br/>[Message.js]")]
  node_mongo[("MongoDB")]
  node_avatar_files[("Avatar files")]
end

node_browser_user(("Chat user"))

node_browser_user -->|"uses"| node_app
node_app -->|"provides session"| node_auth_context
node_app -->|"routes to"| node_auth_pages
node_app -->|"protects route"| node_chat_page
node_auth_pages -->|"authenticates through"| node_auth_context
node_auth_pages -->|"registers through"| node_auth_context
node_auth_context -->|"calls API"| node_http_client
node_chat_page -->|"reads session"| node_auth_context
node_chat_page -->|"creates socket"| node_socket_hook
node_chat_page -->|"renders"| node_sidebar
node_chat_page -->|"renders"| node_chat_window
node_sidebar -->|"loads contacts"| node_http_client
node_sidebar -->|"opens"| node_profile_modal
node_sidebar -->|"renders"| node_avatar
node_profile_modal -->|"uploads picture"| node_http_client
node_profile_modal -->|"updates user"| node_auth_context
node_profile_modal -->|"renders"| node_avatar
node_chat_window -->|"loads history or sends"| node_http_client
node_chat_window -->|"joins and sends"| node_socket_hook
node_chat_window -->|"renders"| node_message_bubble
node_chat_window -->|"renders"| node_avatar
node_chat_window -->|"opens"| node_emoji_picker
node_message_bubble -->|"reads current user"| node_auth_context
node_http_client -->|"HTTP requests"| node_express_app
node_express_app -->|"mounts"| node_auth_routes
node_express_app -->|"mounts"| node_conversation_routes
node_express_app -->|"mounts"| node_message_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_routes -->|"guards"| node_auth_middleware
node_auth_routes -->|"uploads through"| node_upload_middleware
node_conversation_routes -->|"dispatches"| node_conversation_controller
node_conversation_routes -->|"guards"| node_auth_middleware
node_message_routes -->|"dispatches"| node_message_controller
node_message_routes -->|"guards"| node_auth_middleware
node_auth_controller -->|"reads and writes"| node_user_model
node_auth_controller -->|"stores uploaded image"| node_avatar_files
node_conversation_controller -->|"checks participant"| node_user_model
node_conversation_controller -->|"finds or creates"| node_conversation_model
node_message_controller -->|"checks access"| node_conversation_model
node_message_controller -->|"reads and writes"| node_message_model
node_socket_hook -->|"Socket.IO events"| node_socket_server
node_socket_server -->|"validates room access"| node_conversation_model
node_socket_server -->|"creates messages"| node_message_model
node_user_model -.->|"persists"| node_mongo
node_conversation_model -.->|"persists"| node_mongo
node_message_model -.->|"persists"| node_mongo

click node_app "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/App.jsx"
click node_auth_pages "https://github.com/arunkumar09-06/chat_application/tree/main/frontend/src/pages"
click node_auth_context "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/context/AuthContext.jsx"
click node_chat_page "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/pages/Chat.jsx"
click node_sidebar "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/Sidebar.jsx"
click node_profile_modal "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/ProfileModal.jsx"
click node_avatar "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/UserAvatar.jsx"
click node_chat_window "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/ChatWindow.jsx"
click node_message_bubble "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/MessageBubble.jsx"
click node_emoji_picker "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/EmojiPicker.jsx"
click node_socket_hook "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/hooks/useSocket.js"
click node_http_client "https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/api/axios.js"
click node_express_app "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/app.js"
click node_auth_routes "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/routes/auth.routes.js"
click node_conversation_routes "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/routes/conversation.route.js"
click node_message_routes "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/routes/message.route.js"
click node_auth_controller "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/controllers/auth.controller.js"
click node_conversation_controller "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/controllers/conversation.controller.js"
click node_message_controller "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/controllers/message.controller.js"
click node_auth_middleware "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/middlewares/auth.js"
click node_upload_middleware "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/middlewares/multer.js"
click node_socket_server "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/server.js"
click node_user_model "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/models/User.js"
click node_conversation_model "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/models/Conversation.js"
click node_message_model "https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/models/Message.js"
click node_avatar_files "https://github.com/arunkumar09-06/chat_application/tree/main/backend/public/uploads/profilePictures"

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_pages,node_auth_context,node_chat_page,node_sidebar,node_profile_modal,node_avatar,node_chat_window,node_message_bubble,node_emoji_picker,node_browser_user toneBlue
class node_http_client,node_express_app,node_auth_routes,node_conversation_routes,node_message_routes,node_auth_controller,node_conversation_controller,node_message_controller,node_auth_middleware,node_upload_middleware toneAmber
class node_socket_hook,node_socket_server toneMint
class node_user_model,node_conversation_model,node_message_model,node_mongo,node_avatar_files toneRose
```

## Components

### React client

- [Routes and guards](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Login and register](https://github.com/arunkumar09-06/chat_application/tree/main/frontend/src/pages): `frontend/src/pages`
- [Session state](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Chat workspace](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/pages/Chat.jsx): `frontend/src/pages/Chat.jsx`
- [Contact discovery](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/Sidebar.jsx): `frontend/src/components/Sidebar.jsx`
- [Profile customization](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/ProfileModal.jsx): `frontend/src/components/ProfileModal.jsx`
- [User avatar](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/UserAvatar.jsx): `frontend/src/components/UserAvatar.jsx`
- [Chat and history](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/ChatWindow.jsx): `frontend/src/components/ChatWindow.jsx`
- [Message display](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/MessageBubble.jsx): `frontend/src/components/MessageBubble.jsx`
- [Emoji input](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/components/EmojiPicker.jsx): `frontend/src/components/EmojiPicker.jsx`

### HTTP API

- [Axios API client](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/api/axios.js): `frontend/src/api/axios.js`
- [HTTP app and mounts](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/app.js): `backend/src/app.js`
- [Authentication routes](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/routes/auth.routes.js): `backend/src/routes/auth.routes.js`
- [Conversation route](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/routes/conversation.route.js): `backend/src/routes/conversation.route.js`
- [Message routes](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/routes/message.route.js): `backend/src/routes/message.route.js`
- [Account and profile](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/controllers/auth.controller.js): `backend/src/controllers/auth.controller.js`
- [Conversation setup](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/controllers/conversation.controller.js): `backend/src/controllers/conversation.controller.js`
- [History and HTTP send](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/controllers/message.controller.js): `backend/src/controllers/message.controller.js`
- [Cookie JWT guard](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/middlewares/auth.js): `backend/src/middlewares/auth.js`
- [Avatar upload handling](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/middlewares/multer.js): `backend/src/middlewares/multer.js`

### Real-time messaging

- [Socket client](https://github.com/arunkumar09-06/chat_application/blob/main/frontend/src/hooks/useSocket.js): `frontend/src/hooks/useSocket.js`
- [Socket rooms and delivery](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/server.js): `backend/src/server.js`

### Persistence and uploads

- [User records](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/models/User.js): `backend/src/models/User.js`
- [Conversation records](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/models/Conversation.js): `backend/src/models/Conversation.js`
- [Message records](https://github.com/arunkumar09-06/chat_application/blob/main/backend/src/models/Message.js): `backend/src/models/Message.js`
- **MongoDB**
- [Avatar files](https://github.com/arunkumar09-06/chat_application/tree/main/backend/public/uploads/profilePictures): `backend/public/uploads/profilePictures`

### Other components

- **Chat user**

## Connections

- Chat user → Routes and guards: uses (evidence: `README.md`)
- Routes and guards → Session state: provides session (evidence: `frontend/src/App.jsx`)
- Routes and guards → Login and register: routes to (evidence: `frontend/src/App.jsx`)
- Routes and guards → Chat workspace: protects route (evidence: `frontend/src/App.jsx`)
- Login and register → Session state: authenticates through (evidence: `frontend/src/pages/Login.jsx`)
- Login and register → Session state: registers through (evidence: `frontend/src/pages/Register.jsx`)
- Session state → Axios API client: calls API (evidence: `frontend/src/context/AuthContext.jsx`)
- Chat workspace → Session state: reads session (evidence: `frontend/src/pages/Chat.jsx`)
- Chat workspace → Socket client: creates socket (evidence: `frontend/src/pages/Chat.jsx`)
- Chat workspace → Contact discovery: renders (evidence: `frontend/src/pages/Chat.jsx`)
- Chat workspace → Chat and history: renders (evidence: `frontend/src/pages/Chat.jsx`)
- Contact discovery → Axios API client: loads contacts (evidence: `frontend/src/components/Sidebar.jsx`)
- Contact discovery → Profile customization: opens (evidence: `frontend/src/components/Sidebar.jsx`)
- Contact discovery → User avatar: renders (evidence: `frontend/src/components/Sidebar.jsx`)
- Profile customization → Axios API client: uploads picture (evidence: `frontend/src/components/ProfileModal.jsx`)
- Profile customization → Session state: updates user (evidence: `frontend/src/components/ProfileModal.jsx`)
- Profile customization → User avatar: renders (evidence: `frontend/src/components/ProfileModal.jsx`)
- Chat and history → Axios API client: loads history or sends (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat and history → Socket client: joins and sends (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat and history → Message display: renders (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat and history → User avatar: renders (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat and history → Emoji input: opens (evidence: `frontend/src/components/ChatWindow.jsx`)
- Message display → Session state: reads current user (evidence: `frontend/src/components/MessageBubble.jsx`)
- Axios API client → HTTP app and mounts: HTTP requests (evidence: `README.md`)
- HTTP app and mounts → Authentication routes: mounts (evidence: `backend/src/app.js`)
- HTTP app and mounts → Conversation route: mounts (evidence: `backend/src/app.js`)
- HTTP app and mounts → Message routes: mounts (evidence: `backend/src/app.js`)
- Authentication routes → Account and profile: dispatches (evidence: `backend/src/routes/auth.routes.js`)
- Authentication routes → Cookie JWT guard: guards (evidence: `backend/src/routes/auth.routes.js`)
- Authentication routes → Avatar upload handling: uploads through (evidence: `backend/src/routes/auth.routes.js`)
- Conversation route → Conversation setup: dispatches (evidence: `backend/src/routes/conversation.route.js`)
- Conversation route → Cookie JWT guard: guards (evidence: `backend/src/routes/conversation.route.js`)
- Message routes → History and HTTP send: dispatches (evidence: `backend/src/routes/message.route.js`)
- Message routes → Cookie JWT guard: guards (evidence: `backend/src/routes/message.route.js`)
- Account and profile → User records: reads and writes (evidence: `backend/src/controllers/auth.controller.js`)
- Account and profile → Avatar files: stores uploaded image (evidence: `README.md`)
- Conversation setup → User records: checks participant (evidence: `backend/src/controllers/conversation.controller.js`)
- Conversation setup → Conversation records: finds or creates (evidence: `backend/src/controllers/conversation.controller.js`)
- History and HTTP send → Conversation records: checks access (evidence: `backend/src/controllers/message.controller.js`)
- History and HTTP send → Message records: reads and writes (evidence: `backend/src/controllers/message.controller.js`)
- Socket client → Socket rooms and delivery: Socket.IO events (evidence: `README.md`)
- Socket rooms and delivery → Conversation records: validates room access (evidence: `backend/src/server.js`)
- Socket rooms and delivery → Message records: creates messages (evidence: `backend/src/server.js`)
- User records → MongoDB: persists
- Conversation records → MongoDB: persists
- Message records → MongoDB: persists
