# omprakash20071125-a11y/nexuschat architecture

> Architecture diagram of the GitHub repository omprakash20071125-a11y/nexuschat, 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/omprakash20071125-a11y/nexuschat
- Repository: https://github.com/omprakash20071125-a11y/nexuschat

## Overview

NexusChat is a browser-based real-time messaging application supporting direct and group conversations. The main workflow is browser REST or Socket.IO requests, routed through authentication and chat handlers, then validated and persisted; live messages are additionally broadcast to conversation rooms. The graph preserves account management, conversation membership and management, message history/search/read status, and the browser client. Relationship evidence comes from the README and shown source excerpts; unsampled frontend behavior is represented only as documented.

Main entry points: [`src/utils/db.py`](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/db.py) (Database sessions), [`src/realtime/events.py`](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/realtime/events.py) (Socket event handlers), [`src/user/controller.py`](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/controller.py) (Account and auth logic), [`src/chat/controller.py`](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/controller.py) (Conversation and message logic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_web_client["Web client<br/>[app.html]"]
end

subgraph group_api["REST API and accounts"]
  node_application["ASGI application<br/>[main.py]"]
  node_user_routes["User routes<br/>[router.py]"]
  node_user_logic["Account and auth logic<br/>[controller.py]"]
  node_user_schemas["User schemas<br/>[dtos.py]"]
  node_auth_dependency["Bearer authentication<br/>[helpers.py]"]
  node_user_model["User model<br/>[models.py]"]
end

subgraph group_chat["Conversations and messaging"]
  node_chat_routes["Chat routes<br/>[router.py]"]
  node_chat_logic["Conversation and message logic<br/>[controller.py]"]
  node_chat_schemas["Chat schemas<br/>[dtos.py]"]
  node_chat_model["Conversation and message models<br/>[models.py]"]
end

subgraph group_realtime["Real-time delivery"]
  node_socket_server["Socket.IO ASGI server<br/>[socket_server.py]"]
  node_socket_events["Socket event handlers<br/>[events.py]"]
end

subgraph group_infra["Persistence and configuration"]
  node_database_sessions["Database sessions<br/>[db.py]"]
  node_sql_database[("SQL database")]
  node_settings["Runtime settings<br/>[settings.py]"]
  node_registration_mail["Registration email sender<br/>[mail.py]"]
end

node_browser(("Browser user"))

node_browser -->|"uses"| node_web_client
node_web_client -->|"REST requests"| node_application
node_web_client -->|"Socket.IO connects"| node_socket_server
node_application -->|"mounts"| node_user_routes
node_application -->|"mounts"| node_chat_routes
node_application -->|"wraps ASGI"| node_socket_server
node_user_routes -->|"calls"| node_user_logic
node_user_routes -->|"depends on"| node_auth_dependency
node_user_routes -->|"validates with"| node_user_schemas
node_user_logic -->|"queries and creates"| node_user_model
node_user_logic -->|"reads token settings"| node_settings
node_auth_dependency -->|"loads user"| node_user_model
node_auth_dependency -->|"reads token settings"| node_settings
node_chat_routes -->|"calls"| node_chat_logic
node_chat_routes -->|"depends on"| node_auth_dependency
node_chat_routes -->|"validates with"| node_chat_schemas
node_chat_logic -->|"queries and writes"| node_chat_model
node_chat_logic -->|"loads participants"| node_user_model
node_socket_server -->|"registers handlers"| node_socket_events
node_socket_events -->|"saves messages"| node_chat_logic
node_socket_events -->|"loads connected user"| node_user_model
node_socket_events -->|"builds message DTO"| node_chat_schemas
node_socket_events -->|"broadcasts to room"| node_socket_server
node_user_logic -.->|"uses DB dependency"| node_database_sessions
node_chat_logic -.->|"uses DB session"| node_database_sessions
node_socket_events -->|"opens session"| node_database_sessions
node_database_sessions -->|"connects"| node_sql_database
node_chat_model -->|"uses declarative base"| node_database_sessions
node_user_model -->|"uses declarative base"| node_database_sessions
node_database_sessions -->|"reads connection setting"| node_settings
node_user_logic -.->|"optional mail task"| node_registration_mail

click node_web_client "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/app.html"
click node_application "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/main.py"
click node_user_routes "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/router.py"
click node_user_logic "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/controller.py"
click node_user_schemas "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/dtos.py"
click node_auth_dependency "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/helpers.py"
click node_chat_routes "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/router.py"
click node_chat_logic "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/controller.py"
click node_chat_schemas "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/dtos.py"
click node_user_model "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/models.py"
click node_chat_model "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/models.py"
click node_socket_server "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/realtime/socket_server.py"
click node_socket_events "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/realtime/events.py"
click node_database_sessions "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/db.py"
click node_settings "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/settings.py"
click node_registration_mail "https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/mail.py"

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_web_client,node_browser toneBlue
class node_application,node_user_routes,node_user_logic,node_user_schemas,node_auth_dependency,node_user_model toneAmber
class node_chat_routes,node_chat_logic,node_chat_schemas,node_chat_model toneMint
class node_socket_server,node_socket_events toneRose
class node_database_sessions,node_sql_database,node_settings,node_registration_mail toneIndigo
```

## Components

### Browser client

- [Web client](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/app.html): `app.html`

### REST API and accounts

- [ASGI application](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/main.py): `main.py`
- [User routes](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/router.py): `src/user/router.py`
- [Account and auth logic](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/controller.py): `src/user/controller.py`
- [User schemas](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/dtos.py): `src/user/dtos.py`
- [Bearer authentication](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/helpers.py): `src/utils/helpers.py`
- [User model](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/user/models.py): `src/user/models.py`

### Conversations and messaging

- [Chat routes](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/router.py): `src/chat/router.py`
- [Conversation and message logic](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/controller.py): `src/chat/controller.py`
- [Chat schemas](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/dtos.py): `src/chat/dtos.py`
- [Conversation and message models](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/chat/models.py): `src/chat/models.py`

### Real-time delivery

- [Socket.IO ASGI server](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/realtime/socket_server.py): `src/realtime/socket_server.py`
- [Socket event handlers](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/realtime/events.py): `src/realtime/events.py`

### Persistence and configuration

- [Database sessions](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/db.py): `src/utils/db.py`
- **SQL database**
- [Runtime settings](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/settings.py): `src/utils/settings.py`
- [Registration email sender](https://github.com/omprakash20071125-a11y/nexuschat/blob/main/src/utils/mail.py): `src/utils/mail.py`

### Other components

- **Browser user**

## Connections

- Browser user → Web client: uses (evidence: `Readme.md`)
- Web client → ASGI application: REST requests (evidence: `Readme.md`)
- Web client → Socket.IO ASGI server: Socket.IO connects (evidence: `Readme.md`)
- ASGI application → User routes: mounts (evidence: `main.py`)
- ASGI application → Chat routes: mounts (evidence: `main.py`)
- ASGI application → Socket.IO ASGI server: wraps ASGI (evidence: `main.py`)
- User routes → Account and auth logic: calls (evidence: `src/user/router.py`)
- User routes → Bearer authentication: depends on (evidence: `src/user/router.py`)
- User routes → User schemas: validates with (evidence: `src/user/router.py`)
- Account and auth logic → User model: queries and creates (evidence: `src/user/controller.py`)
- Account and auth logic → Runtime settings: reads token settings (evidence: `src/user/controller.py`)
- Bearer authentication → User model: loads user (evidence: `src/utils/helpers.py`)
- Bearer authentication → Runtime settings: reads token settings (evidence: `src/utils/helpers.py`)
- Chat routes → Conversation and message logic: calls (evidence: `src/chat/router.py`)
- Chat routes → Bearer authentication: depends on (evidence: `src/chat/router.py`)
- Chat routes → Chat schemas: validates with (evidence: `src/chat/router.py`)
- Conversation and message logic → Conversation and message models: queries and writes (evidence: `src/chat/controller.py`)
- Conversation and message logic → User model: loads participants (evidence: `src/chat/controller.py`)
- Socket.IO ASGI server → Socket event handlers: registers handlers (evidence: `src/realtime/events.py`)
- Socket event handlers → Conversation and message logic: saves messages (evidence: `src/realtime/events.py`)
- Socket event handlers → User model: loads connected user (evidence: `src/realtime/events.py`)
- Socket event handlers → Chat schemas: builds message DTO (evidence: `src/realtime/events.py`)
- Socket event handlers → Socket.IO ASGI server: broadcasts to room (evidence: `src/realtime/events.py`)
- Account and auth logic → Database sessions: uses DB dependency
- Conversation and message logic → Database sessions: uses DB session
- Socket event handlers → Database sessions: opens session (evidence: `src/realtime/events.py`)
- Database sessions → SQL database: connects (evidence: `src/utils/db.py`)
- Conversation and message models → Database sessions: uses declarative base (evidence: `src/chat/models.py`)
- User model → Database sessions: uses declarative base (evidence: `src/user/models.py`)
- Database sessions → Runtime settings: reads connection setting (evidence: `src/utils/db.py`)
- Account and auth logic → Registration email sender: optional mail task (evidence: `src/user/controller.py`)
