# lau2k1/support-chat architecture

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

- Interactive diagram: https://gitdiagram.com/lau2k1/support-chat
- Repository: https://github.com/lau2k1/support-chat

## Overview

SupportChat is a multitenant support-chat SaaS. A customer starts a conversation in the embedded widget or Telegram; operators handle it in the role-based panel, while tenant admins configure service and billing and the superadmin manages tenants. The backend provides authenticated APIs, WebSocket chat, persistence, uploads, Telegram integration, and billing. The graph combines shown source references with README-documented product capabilities; unsampled UI and route details are represented at subsystem level, and unsupported internal links are omitted.

Main entry points: [`backend/src/server.ts`](https://github.com/lau2k1/support-chat/blob/main/backend/src/server.ts) (HTTP and socket server), [`backend/src/db/index.ts`](https://github.com/lau2k1/support-chat/blob/main/backend/src/db/index.ts) (PostgreSQL), [`backend/src/routes/admin.ts`](https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/admin.ts) (Tenant administration API), [`backend/src/ws/handler.ts`](https://github.com/lau2k1/support-chat/blob/main/backend/src/ws/handler.ts) (Live chat handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Customer channels"]
  node_widget["Embedded chat widget<br/>[WidgetChat.tsx]"]
  node_widgetws["Widget WebSocket<br/>[useWidgetWs.ts]"]
  node_telegram["Telegram bot channel<br/>[telegram.ts]"]
end

subgraph group_backend["Backend services"]
  node_authroutes["Authentication routes<br/>[auth.ts]"]
  node_auth["JWT authorization<br/>[auth.ts]"]
  node_server["HTTP and socket server<br/>[server.ts]"]
  node_chatroutes["Chat and archive API<br/>[chat.ts]"]
  node_ws["Live chat handler<br/>[handler.ts]"]
  node_chatservice["Chat rooms and dispatch<br/>[chat.ts]"]
  node_database[("PostgreSQL<br/>[index.ts]")]
  node_uploads["File uploads<br/>[upload.ts]"]
end

subgraph group_operator["Operator workspace"]
  node_operatorui["Operator workspace"]
  node_wsclient["Panel WebSocket client<br/>[useWebSocket.ts]"]
  node_api["Panel API client<br/>[api.ts]"]
  node_authui["Login and registration<br/>[Login.tsx]"]
  node_canned["Quick replies<br/>[canned.ts]"]
end

subgraph group_management["Tenant and platform management"]
  node_billing["Billing domain<br/>[billing.ts]"]
  node_billingroutes["Billing and payments API<br/>[billing.ts]"]
  node_adminui["Tenant admin panel<br/>[AdminPanel.tsx]"]
  node_adminroutes["Tenant administration API<br/>[admin.ts]"]
  node_ownerui["Owner CRM<br/>[OwnerDashboard.tsx]"]
  node_cryptobot["Crypto payment provider<br/>[cryptobot.ts]"]
end

node_customer(("Customer"))
node_operator(("Operator"))

node_customer -->|"opens chat"| node_widget
node_widget -->|"uses socket"| node_widgetws
node_widgetws -.->|"connects"| node_server
node_customer -->|"messages bot"| node_telegram
node_telegram -->|"dispatches chats"| node_chatservice
node_operator -->|"signs in"| node_authui
node_authui -->|"submits credentials"| node_authroutes
node_authroutes -->|"uses JWT auth"| node_auth
node_operator -->|"handles conversations"| node_operatorui
node_operatorui -->|"uses socket"| node_wsclient
node_operatorui -.->|"requests API"| node_api
node_wsclient -.->|"connects"| node_server
node_api -.->|"calls API"| node_server
node_server -->|"mounts routes"| node_authroutes
node_server -->|"mounts routes"| node_chatroutes
node_server -->|"registers handler"| node_ws
node_server -->|"mounts routes"| node_uploads
node_ws -->|"resolves session"| node_auth
node_ws -->|"dispatches chat"| node_chatservice
node_chatroutes -->|"protects routes"| node_auth
node_ws -->|"reads and writes"| node_database
node_chatroutes -->|"reads and writes"| node_database
node_authroutes -->|"reads and writes"| node_database
node_uploads -->|"checks tenant"| node_database
node_operatorui -.->|"uses quick replies"| node_canned
node_adminui -.->|"manages tenant"| node_adminroutes
node_adminroutes -->|"protects routes"| node_auth
node_adminroutes -->|"confirms payment"| node_billing
node_adminroutes -->|"reads and writes"| node_database
node_ownerui -.->|"manages tenants"| node_adminroutes
node_billingroutes -->|"uses billing logic"| node_billing
node_billingroutes -->|"initiates crypto payment"| node_cryptobot
node_billing -->|"reads and writes"| node_database

click node_widget "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/widget/WidgetChat.tsx"
click node_widgetws "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/widget/useWidgetWs.ts"
click node_telegram "https://github.com/lau2k1/support-chat/blob/main/backend/src/services/telegram.ts"
click node_operatorui "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/operator/OperatorDashboard.tsx"
click node_wsclient "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/hooks/useWebSocket.ts"
click node_api "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/services/api.ts"
click node_authui "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/Login.tsx"
click node_authroutes "https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/auth.ts"
click node_auth "https://github.com/lau2k1/support-chat/blob/main/backend/src/middleware/auth.ts"
click node_server "https://github.com/lau2k1/support-chat/blob/main/backend/src/server.ts"
click node_chatroutes "https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/chat.ts"
click node_ws "https://github.com/lau2k1/support-chat/blob/main/backend/src/ws/handler.ts"
click node_chatservice "https://github.com/lau2k1/support-chat/blob/main/backend/src/services/chat.ts"
click node_database "https://github.com/lau2k1/support-chat/blob/main/backend/src/db/index.ts"
click node_uploads "https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/upload.ts"
click node_billing "https://github.com/lau2k1/support-chat/blob/main/backend/src/services/billing.ts"
click node_billingroutes "https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/billing.ts"
click node_adminui "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/admin/AdminPanel.tsx"
click node_adminroutes "https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/admin.ts"
click node_ownerui "https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/owner/OwnerDashboard.tsx"
click node_canned "https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/canned.ts"
click node_cryptobot "https://github.com/lau2k1/support-chat/blob/main/backend/src/services/cryptobot.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_widget,node_widgetws,node_telegram toneBlue
class node_authroutes,node_auth,node_server,node_chatroutes,node_ws,node_chatservice,node_database,node_uploads toneAmber
class node_operatorui,node_wsclient,node_api,node_authui,node_canned toneMint
class node_billing,node_billingroutes,node_adminui,node_adminroutes,node_ownerui,node_cryptobot toneRose
class node_customer,node_operator toneIndigo
```

## Components

### Customer channels

- [Embedded chat widget](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/widget/WidgetChat.tsx): `frontend-react/src/widget/WidgetChat.tsx`
- [Widget WebSocket](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/widget/useWidgetWs.ts): `frontend-react/src/widget/useWidgetWs.ts`
- [Telegram bot channel](https://github.com/lau2k1/support-chat/blob/main/backend/src/services/telegram.ts): `backend/src/services/telegram.ts`

### Backend services

- [Authentication routes](https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/auth.ts): `backend/src/routes/auth.ts`
- [JWT authorization](https://github.com/lau2k1/support-chat/blob/main/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`
- [HTTP and socket server](https://github.com/lau2k1/support-chat/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [Chat and archive API](https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/chat.ts): `backend/src/routes/chat.ts`
- [Live chat handler](https://github.com/lau2k1/support-chat/blob/main/backend/src/ws/handler.ts): `backend/src/ws/handler.ts`
- [Chat rooms and dispatch](https://github.com/lau2k1/support-chat/blob/main/backend/src/services/chat.ts): `backend/src/services/chat.ts`
- [PostgreSQL](https://github.com/lau2k1/support-chat/blob/main/backend/src/db/index.ts): `backend/src/db/index.ts`
- [File uploads](https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/upload.ts): `backend/src/routes/upload.ts`

### Operator workspace

- [Operator workspace](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/operator/OperatorDashboard.tsx): `frontend-react/src/pages/operator/OperatorDashboard.tsx`
- [Panel WebSocket client](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/hooks/useWebSocket.ts): `frontend-react/src/hooks/useWebSocket.ts`
- [Panel API client](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/services/api.ts): `frontend-react/src/services/api.ts`
- [Login and registration](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/Login.tsx): `frontend-react/src/pages/Login.tsx`
- [Quick replies](https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/canned.ts): `backend/src/routes/canned.ts`

### Tenant and platform management

- [Billing domain](https://github.com/lau2k1/support-chat/blob/main/backend/src/services/billing.ts): `backend/src/services/billing.ts`
- [Billing and payments API](https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/billing.ts): `backend/src/routes/billing.ts`
- [Tenant admin panel](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/admin/AdminPanel.tsx): `frontend-react/src/pages/admin/AdminPanel.tsx`
- [Tenant administration API](https://github.com/lau2k1/support-chat/blob/main/backend/src/routes/admin.ts): `backend/src/routes/admin.ts`
- [Owner CRM](https://github.com/lau2k1/support-chat/blob/main/frontend-react/src/pages/owner/OwnerDashboard.tsx): `frontend-react/src/pages/owner/OwnerDashboard.tsx`
- [Crypto payment provider](https://github.com/lau2k1/support-chat/blob/main/backend/src/services/cryptobot.ts): `backend/src/services/cryptobot.ts`

### Other components

- **Customer**
- **Operator**

## Connections

- Customer → Embedded chat widget: opens chat
- Embedded chat widget → Widget WebSocket: uses socket (evidence: `frontend-react/src/widget/WidgetChat.tsx`)
- Widget WebSocket → HTTP and socket server: connects
- Customer → Telegram bot channel: messages bot
- Telegram bot channel → Chat rooms and dispatch: dispatches chats (evidence: `backend/src/services/telegram.ts`)
- Operator → Login and registration: signs in
- Login and registration → Authentication routes: submits credentials (evidence: `backend/src/routes/auth.ts`)
- Authentication routes → JWT authorization: uses JWT auth (evidence: `backend/src/routes/auth.ts`)
- Operator → Operator workspace: handles conversations
- Operator workspace → Panel WebSocket client: uses socket (evidence: `frontend-react/src/pages/operator/OperatorDashboard.tsx`)
- Operator workspace → Panel API client: requests API
- Panel WebSocket client → HTTP and socket server: connects
- Panel API client → HTTP and socket server: calls API
- HTTP and socket server → Authentication routes: mounts routes (evidence: `backend/src/server.ts`)
- HTTP and socket server → Chat and archive API: mounts routes (evidence: `backend/src/server.ts`)
- HTTP and socket server → Live chat handler: registers handler (evidence: `backend/src/server.ts`)
- HTTP and socket server → File uploads: mounts routes (evidence: `backend/src/server.ts`)
- Live chat handler → JWT authorization: resolves session (evidence: `backend/src/ws/handler.ts`)
- Live chat handler → Chat rooms and dispatch: dispatches chat (evidence: `backend/src/ws/handler.ts`)
- Chat and archive API → JWT authorization: protects routes (evidence: `backend/src/routes/chat.ts`)
- Live chat handler → PostgreSQL: reads and writes (evidence: `backend/src/ws/handler.ts`)
- Chat and archive API → PostgreSQL: reads and writes (evidence: `backend/src/routes/chat.ts`)
- Authentication routes → PostgreSQL: reads and writes (evidence: `backend/src/routes/auth.ts`)
- File uploads → PostgreSQL: checks tenant (evidence: `backend/src/routes/upload.ts`)
- Operator workspace → Quick replies: uses quick replies
- Tenant admin panel → Tenant administration API: manages tenant
- Tenant administration API → JWT authorization: protects routes (evidence: `backend/src/routes/admin.ts`)
- Tenant administration API → Billing domain: confirms payment (evidence: `backend/src/routes/admin.ts`)
- Tenant administration API → PostgreSQL: reads and writes (evidence: `backend/src/routes/admin.ts`)
- Owner CRM → Tenant administration API: manages tenants
- Billing and payments API → Billing domain: uses billing logic (evidence: `backend/src/routes/billing.ts`)
- Billing and payments API → Crypto payment provider: initiates crypto payment (evidence: `backend/src/routes/billing.ts`)
- Billing domain → PostgreSQL: reads and writes (evidence: `backend/src/services/billing.ts`)
