# lebao1234/bd-sidcorp architecture

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

- Interactive diagram: https://gitdiagram.com/lebao1234/bd-sidcorp
- Repository: https://github.com/lebao1234/bd-sidcorp

## Overview

QuanLyHTKH combines team CRM, task/reporting workflows, and internal real-time chat. Users enter through the authenticated React application; its screens and hooks use the API for CRM, tasks, resources, and reports, while chat and mention notifications provide live collaboration. The backend separates HTTP controllers, socket handling, and persistence across PostgreSQL, MongoDB, and Supabase Storage. The excerpts establish selected calls and startup wiring; some documented capabilities have unsampled implementations, so uncertain links are left out or marked unverified.

Main entry points: [`backend/src/index.ts`](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/index.ts) (HTTP server), [`frontend/src/services/api.ts`](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/services/api.ts) (API client), [`frontend/src/App.tsx`](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/App.tsx) (App routing), [`backend/src/controllers/CustomerController.ts`](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/CustomerController.ts) (Customer management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["App routing<br/>[App.tsx]"]
  node_authctx["Authentication state<br/>[AuthContext.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_task_ui["Task workflows<br/>[TasksPage.tsx]"]
  node_task_hook["Task data hook<br/>[useTasks.ts]"]
  node_crm_ui["CRM screens<br/>[CustomerTab.tsx]"]
  node_notes_ui["Notes and timeline<br/>[NotesPage.tsx]"]
  node_chat_ui["Chat interface<br/>[ChatPage.tsx]"]
  node_resource_ui["Resource hub"]
  node_reports_ui["Reports dashboard"]
end

subgraph group_http["HTTP API"]
  node_server["HTTP server<br/>[index.ts]"]
  node_auth["Authentication and RBAC<br/>[AuthController.ts]"]
  node_customers["Customer management"]
  node_tasks["Task management<br/>[TaskController.ts]"]
  node_assets["Assets and attachments<br/>[AssetController.ts]"]
  node_chat_controller["Chat history API<br/>[ChatController.ts]"]
end

subgraph group_collab["Live collaboration"]
  node_sockets["Socket manager<br/>[socketManager.ts]"]
  node_reminders["Task reminders<br/>[taskReminder.ts]"]
end

subgraph group_data["Persistence and storage"]
  node_postgres[("PostgreSQL data<br/>[db.ts]")]
  node_mongo_messages[("Chat message store<br/>[GlobalMessage.ts]")]
  node_storage[("Supabase file storage<br/>[supabase.ts]")]
  node_redis[("Redis adapter<br/>[redis.ts]")]
end

node_staff(("Team member"))

node_staff -->|"uses"| node_app
node_app -->|"provides auth"| node_authctx
node_app -->|"routes to"| node_task_ui
node_app -->|"routes to"| node_chat_ui
node_app -->|"routes to"| node_reports_ui
node_task_ui -->|"uses"| node_task_hook
node_task_hook -->|"requests tasks"| node_api_client
node_crm_ui -.->|"uses"| node_api_client
node_notes_ui -.->|"uses"| node_api_client
node_resource_ui -.->|"uses"| node_api_client
node_reports_ui -.->|"uses"| node_api_client
node_api_client -.->|"calls HTTP API"| node_server
node_server -.->|"mounts routes"| node_auth
node_server -.->|"mounts routes"| node_customers
node_server -.->|"mounts routes"| node_tasks
node_server -.->|"mounts routes"| node_assets
node_server -.->|"mounts routes"| node_chat_controller
node_server -->|"initializes"| node_sockets
node_server -->|"starts job"| node_reminders
node_customers -->|"reads and writes"| node_postgres
node_customers -.->|"notifies mentions"| node_storage
node_assets -->|"reads and writes"| node_postgres
node_assets -->|"uploads files"| node_storage
node_tasks -->|"reads and writes"| node_postgres
node_sockets -->|"persists messages"| node_mongo_messages
node_sockets -->|"configures adapter"| node_redis
node_chat_controller -->|"reads chat history"| node_mongo_messages

click node_app "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/App.tsx"
click node_authctx "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/context/AuthContext.tsx"
click node_api_client "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/services/api.ts"
click node_task_ui "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Tasks/TasksPage.tsx"
click node_task_hook "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/hooks/useTasks.ts"
click node_crm_ui "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/User/tabs/CustomerTab.tsx"
click node_notes_ui "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Notes/NotesPage.tsx"
click node_chat_ui "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Chat/ChatPage.tsx"
click node_resource_ui "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Resources/ResourceHubPage.tsx"
click node_reports_ui "https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/components/reports/ReportDashboard.tsx"
click node_server "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/index.ts"
click node_auth "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/AuthController.ts"
click node_customers "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/CustomerController.ts"
click node_tasks "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/TaskController.ts"
click node_assets "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/AssetController.ts"
click node_chat_controller "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/ChatController.ts"
click node_sockets "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/sockets/socketManager.ts"
click node_reminders "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/jobs/taskReminder.ts"
click node_postgres "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/config/db.ts"
click node_mongo_messages "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/models/GlobalMessage.ts"
click node_storage "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/config/supabase.ts"
click node_redis "https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/config/redis.ts"

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_authctx,node_api_client,node_task_ui,node_task_hook,node_crm_ui,node_notes_ui,node_chat_ui,node_resource_ui,node_reports_ui toneBlue
class node_server,node_auth,node_customers,node_tasks,node_assets,node_chat_controller toneAmber
class node_sockets,node_reminders toneMint
class node_postgres,node_mongo_messages,node_storage,node_redis toneRose
class node_staff toneIndigo
```

## Components

### Web application

- [App routing](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Authentication state](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [API client](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Task workflows](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Tasks/TasksPage.tsx): `frontend/src/pages/Tasks/TasksPage.tsx`
- [Task data hook](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/hooks/useTasks.ts): `frontend/src/hooks/useTasks.ts`
- [CRM screens](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/User/tabs/CustomerTab.tsx): `frontend/src/pages/User/tabs/CustomerTab.tsx`
- [Notes and timeline](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Notes/NotesPage.tsx): `frontend/src/pages/Notes/NotesPage.tsx`
- [Chat interface](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Chat/ChatPage.tsx): `frontend/src/pages/Chat/ChatPage.tsx`
- [Resource hub](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/pages/Resources/ResourceHubPage.tsx): `frontend/src/pages/Resources/ResourceHubPage.tsx`
- [Reports dashboard](https://github.com/lebao1234/bd-sidcorp/blob/main/frontend/src/components/reports/ReportDashboard.tsx): `frontend/src/components/reports/ReportDashboard.tsx`

### HTTP API

- [HTTP server](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/index.ts): `backend/src/index.ts`
- [Authentication and RBAC](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/AuthController.ts): `backend/src/controllers/AuthController.ts`
- [Customer management](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/CustomerController.ts): `backend/src/controllers/CustomerController.ts`
- [Task management](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/TaskController.ts): `backend/src/controllers/TaskController.ts`
- [Assets and attachments](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/AssetController.ts): `backend/src/controllers/AssetController.ts`
- [Chat history API](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/controllers/ChatController.ts): `backend/src/controllers/ChatController.ts`

### Live collaboration

- [Socket manager](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/sockets/socketManager.ts): `backend/src/sockets/socketManager.ts`
- [Task reminders](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/jobs/taskReminder.ts): `backend/src/jobs/taskReminder.ts`

### Persistence and storage

- [PostgreSQL data](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/config/db.ts): `backend/src/config/db.ts`
- [Chat message store](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/models/GlobalMessage.ts): `backend/src/models/GlobalMessage.ts`
- [Supabase file storage](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/config/supabase.ts): `backend/src/config/supabase.ts`
- [Redis adapter](https://github.com/lebao1234/bd-sidcorp/blob/main/backend/src/config/redis.ts): `backend/src/config/redis.ts`

### Other components

- **Team member**

## Connections

- Team member → App routing: uses (evidence: `README.md`)
- App routing → Authentication state: provides auth (evidence: `frontend/src/App.tsx`)
- App routing → Task workflows: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Chat interface: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Reports dashboard: routes to (evidence: `frontend/src/App.tsx`)
- Task workflows → Task data hook: uses (evidence: `frontend/src/pages/Tasks/TasksPage.tsx`)
- Task data hook → API client: requests tasks (evidence: `frontend/src/hooks/useTasks.ts`)
- CRM screens → API client: uses
- Notes and timeline → API client: uses
- Resource hub → API client: uses
- Reports dashboard → API client: uses
- API client → HTTP server: calls HTTP API
- HTTP server → Authentication and RBAC: mounts routes
- HTTP server → Customer management: mounts routes
- HTTP server → Task management: mounts routes
- HTTP server → Assets and attachments: mounts routes
- HTTP server → Chat history API: mounts routes
- HTTP server → Socket manager: initializes (evidence: `backend/src/index.ts`)
- HTTP server → Task reminders: starts job (evidence: `backend/src/index.ts`)
- Customer management → PostgreSQL data: reads and writes (evidence: `backend/src/controllers/CustomerController.ts`)
- Customer management → Supabase file storage: notifies mentions
- Assets and attachments → PostgreSQL data: reads and writes (evidence: `backend/src/controllers/AssetController.ts`)
- Assets and attachments → Supabase file storage: uploads files (evidence: `backend/src/controllers/AssetController.ts`)
- Task management → PostgreSQL data: reads and writes (evidence: `backend/src/controllers/TaskController.ts`)
- Socket manager → Chat message store: persists messages (evidence: `backend/src/sockets/socketManager.ts`)
- Socket manager → Redis adapter: configures adapter (evidence: `backend/src/sockets/socketManager.ts`)
- Chat history API → Chat message store: reads chat history (evidence: `backend/src/controllers/ChatController.ts`)
