# itzap77/chathub-restructured architecture

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

- Interactive diagram: https://gitdiagram.com/itzap77/chathub-restructured
- Repository: https://github.com/itzap77/chathub-restructured

## Overview

ChatHub is a browser-based real-time chat platform. Users register or sign in, then join the public channel, create or join passkey-protected rooms, start disposable rooms, or request private conversations; they exchange messages and files over WebSockets and HTTP. Room membership, moderation, read tracking, and cleanup are separate domain stages. The graph follows the documented capabilities and sampled wiring; several route implementations and WebSocket message handlers were not sampled, so their internal call relationships are not expanded.

Main entry points: [`app/main.py`](https://github.com/itzap77/chathub-restructured/blob/main/app/main.py) (FastAPI app), [`app/routes/dm.py`](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/dm.py) (DM and ephemeral), [`app/routes/rooms.py`](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/rooms.py) (Room management), [`app/routes/auth_routes.py`](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/auth_routes.py) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_index["Chat UI<br/>[index.html]"]
  node_client_app["Client state<br/>[app.js]"]
  node_client_auth["Authentication UI<br/>[auth.js]"]
  node_client_chat["Chat UI logic<br/>[chat.js]"]
  node_client_rooms["Room controls<br/>[rooms.js]"]
  node_client_directory["User directory<br/>[directory.js]"]
  node_client_ephemeral["Disposable rooms UI<br/>[ephemeral.js]"]
end

subgraph group_entry["Application entry"]
  node_main["FastAPI app<br/>[main.py]"]
end

subgraph group_features["Chat features"]
  node_auth_routes["Auth routes<br/>[auth_routes.py]"]
  node_users_routes["User routes<br/>[users.py]"]
  node_rooms_routes["Room management<br/>[rooms.py]"]
  node_dm_routes["DM and ephemeral<br/>[dm.py]"]
  node_messages_routes["Message routes<br/>[messages.py]"]
  node_uploads_routes["Upload routes<br/>[uploads.py]"]
  node_ws_routes["WebSocket endpoint<br/>[ws.py]"]
end

subgraph group_services["Backend services"]
  node_auth_service["Sessions and hashing<br/>[auth.py]"]
  node_manager["Room connections"]
  node_message_repo["Message operations<br/>[messages_repo.py]"]
end

subgraph group_state["Persistent and file state"]
  node_db[("SQLite database<br/>[db.py]")]
  node_uploads["Uploaded files"]
end

node_browser(("Web browser"))

node_browser -->|"requests page"| node_main
node_main -->|"serves page"| node_index
node_browser -->|"HTTP auth"| node_auth_routes
node_client_auth -->|"registers and signs in"| node_auth_routes
node_auth_routes -->|"hashes and manages sessions"| node_auth_service
node_auth_routes -->|"reads and writes accounts"| node_db
node_client_rooms -->|"manages rooms"| node_rooms_routes
node_rooms_routes -->|"checks sessions"| node_auth_service
node_rooms_routes -->|"reads and writes room state"| node_db
node_rooms_routes -->|"kicks and broadcasts"| node_manager
node_client_ephemeral -->|"creates and verifies rooms"| node_dm_routes
node_client_directory -->|"requests private chats"| node_dm_routes
node_dm_routes -->|"checks sessions"| node_auth_service
node_dm_routes -->|"reads and writes requests"| node_db
node_dm_routes -->|"notifies users"| node_manager
node_client_chat -->|"sends chat events"| node_ws_routes
node_ws_routes -->|"handles connections"| node_manager
node_manager -->|"loads and tracks reads"| node_message_repo
node_client_chat -.->|"requests message data"| node_messages_routes
node_messages_routes -.->|"uses message operations"| node_message_repo
node_client_chat -->|"uploads attachments"| node_uploads_routes
node_uploads_routes -.->|"stores attachments"| node_uploads
node_main -->|"initializes and purges"| node_db
node_main -->|"registers endpoint"| node_ws_routes
node_main -->|"registers routes"| node_auth_routes
node_main -->|"registers routes"| node_rooms_routes
node_main -->|"registers routes"| node_dm_routes
node_main -->|"registers routes"| node_messages_routes
node_main -->|"registers routes"| node_uploads_routes
node_main -->|"registers routes"| node_users_routes
node_client_app -->|"shares client state"| node_client_auth
node_client_app -->|"shares client state"| node_client_chat
node_client_app -->|"shares client state"| node_client_rooms

click node_main "https://github.com/itzap77/chathub-restructured/blob/main/app/main.py"
click node_index "https://github.com/itzap77/chathub-restructured/blob/main/static/index.html"
click node_client_app "https://github.com/itzap77/chathub-restructured/blob/main/static/js/app.js"
click node_client_auth "https://github.com/itzap77/chathub-restructured/blob/main/static/js/auth.js"
click node_client_chat "https://github.com/itzap77/chathub-restructured/blob/main/static/js/chat.js"
click node_client_rooms "https://github.com/itzap77/chathub-restructured/blob/main/static/js/rooms.js"
click node_client_directory "https://github.com/itzap77/chathub-restructured/blob/main/static/js/directory.js"
click node_client_ephemeral "https://github.com/itzap77/chathub-restructured/blob/main/static/js/ephemeral.js"
click node_auth_routes "https://github.com/itzap77/chathub-restructured/blob/main/app/routes/auth_routes.py"
click node_users_routes "https://github.com/itzap77/chathub-restructured/blob/main/app/routes/users.py"
click node_rooms_routes "https://github.com/itzap77/chathub-restructured/blob/main/app/routes/rooms.py"
click node_dm_routes "https://github.com/itzap77/chathub-restructured/blob/main/app/routes/dm.py"
click node_messages_routes "https://github.com/itzap77/chathub-restructured/blob/main/app/routes/messages.py"
click node_uploads_routes "https://github.com/itzap77/chathub-restructured/blob/main/app/routes/uploads.py"
click node_ws_routes "https://github.com/itzap77/chathub-restructured/blob/main/app/ws.py"
click node_auth_service "https://github.com/itzap77/chathub-restructured/blob/main/app/auth.py"
click node_manager "https://github.com/itzap77/chathub-restructured/blob/main/app/connection_manager.py"
click node_message_repo "https://github.com/itzap77/chathub-restructured/blob/main/app/messages_repo.py"
click node_db "https://github.com/itzap77/chathub-restructured/blob/main/app/db.py"
click node_uploads "https://github.com/itzap77/chathub-restructured/tree/main/uploads"

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_index,node_client_app,node_client_auth,node_client_chat,node_client_rooms,node_client_directory,node_client_ephemeral,node_browser toneBlue
class node_main toneAmber
class node_auth_routes,node_users_routes,node_rooms_routes,node_dm_routes,node_messages_routes,node_uploads_routes,node_ws_routes toneMint
class node_auth_service,node_manager,node_message_repo toneRose
class node_db,node_uploads toneIndigo
```

## Components

### Browser client

- [Chat UI](https://github.com/itzap77/chathub-restructured/blob/main/static/index.html): `static/index.html`
- [Client state](https://github.com/itzap77/chathub-restructured/blob/main/static/js/app.js): `static/js/app.js`
- [Authentication UI](https://github.com/itzap77/chathub-restructured/blob/main/static/js/auth.js): `static/js/auth.js`
- [Chat UI logic](https://github.com/itzap77/chathub-restructured/blob/main/static/js/chat.js): `static/js/chat.js`
- [Room controls](https://github.com/itzap77/chathub-restructured/blob/main/static/js/rooms.js): `static/js/rooms.js`
- [User directory](https://github.com/itzap77/chathub-restructured/blob/main/static/js/directory.js): `static/js/directory.js`
- [Disposable rooms UI](https://github.com/itzap77/chathub-restructured/blob/main/static/js/ephemeral.js): `static/js/ephemeral.js`

### Application entry

- [FastAPI app](https://github.com/itzap77/chathub-restructured/blob/main/app/main.py): `app/main.py`

### Chat features

- [Auth routes](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/auth_routes.py): `app/routes/auth_routes.py`
- [User routes](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/users.py): `app/routes/users.py`
- [Room management](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/rooms.py): `app/routes/rooms.py`
- [DM and ephemeral](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/dm.py): `app/routes/dm.py`
- [Message routes](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/messages.py): `app/routes/messages.py`
- [Upload routes](https://github.com/itzap77/chathub-restructured/blob/main/app/routes/uploads.py): `app/routes/uploads.py`
- [WebSocket endpoint](https://github.com/itzap77/chathub-restructured/blob/main/app/ws.py): `app/ws.py`

### Backend services

- [Sessions and hashing](https://github.com/itzap77/chathub-restructured/blob/main/app/auth.py): `app/auth.py`
- [Room connections](https://github.com/itzap77/chathub-restructured/blob/main/app/connection_manager.py): `app/connection_manager.py`
- [Message operations](https://github.com/itzap77/chathub-restructured/blob/main/app/messages_repo.py): `app/messages_repo.py`

### Persistent and file state

- [SQLite database](https://github.com/itzap77/chathub-restructured/blob/main/app/db.py): `app/db.py`
- [Uploaded files](https://github.com/itzap77/chathub-restructured/tree/main/uploads): `uploads`

### Other components

- **Web browser**

## Connections

- Web browser → FastAPI app: requests page
- FastAPI app → Chat UI: serves page
- Web browser → Auth routes: HTTP auth
- Authentication UI → Auth routes: registers and signs in
- Auth routes → Sessions and hashing: hashes and manages sessions
- Auth routes → SQLite database: reads and writes accounts
- Room controls → Room management: manages rooms
- Room management → Sessions and hashing: checks sessions
- Room management → SQLite database: reads and writes room state
- Room management → Room connections: kicks and broadcasts
- Disposable rooms UI → DM and ephemeral: creates and verifies rooms
- User directory → DM and ephemeral: requests private chats
- DM and ephemeral → Sessions and hashing: checks sessions
- DM and ephemeral → SQLite database: reads and writes requests
- DM and ephemeral → Room connections: notifies users
- Chat UI logic → WebSocket endpoint: sends chat events
- WebSocket endpoint → Room connections: handles connections
- Room connections → Message operations: loads and tracks reads
- Chat UI logic → Message routes: requests message data
- Message routes → Message operations: uses message operations
- Chat UI logic → Upload routes: uploads attachments
- Upload routes → Uploaded files: stores attachments
- FastAPI app → SQLite database: initializes and purges
- FastAPI app → WebSocket endpoint: registers endpoint
- FastAPI app → Auth routes: registers routes
- FastAPI app → Room management: registers routes
- FastAPI app → DM and ephemeral: registers routes
- FastAPI app → Message routes: registers routes
- FastAPI app → Upload routes: registers routes
- FastAPI app → User routes: registers routes
- Client state → Authentication UI: shares client state
- Client state → Chat UI logic: shares client state
- Client state → Room controls: shares client state
