# aayush746/wiget_chat architecture

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

- Interactive diagram: https://gitdiagram.com/aayush746/wiget_chat
- Repository: https://github.com/aayush746/wiget_chat

## Overview

ChatFlow is an embeddable, multi-tenant support-chat product: visitors start and resume widget conversations, while staff manage the inbox and respond from a real-time dashboard. The API also handles identity, website/FAQ configuration, assignments, reporting, and an optional FAQ-grounded AI agent with human handoff. The README documents client/API and database links; sampled controllers show key service calls. Several subsystem internals were not sampled, so their detailed links are omitted rather than inferred.

Main entry points: [`apps/api/src/app.module.ts`](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/app.module.ts) (API application), [`apps/widget/src/WidgetApp.tsx`](https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/WidgetApp.tsx) (Chat widget), [`apps/api/src/ai/ai.worker.ts`](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/ai/ai.worker.ts) (AI agent), [`apps/api/src/conversations/conversations.service.ts`](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/conversations/conversations.service.ts) (Conversation workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Chat clients"]
  node_widget["Chat widget<br/>[WidgetApp.tsx]"]
  node_widget_ui["Widget panel<br/>[Panel.tsx]"]
  node_widget_messages["Message state<br/>[messages.ts]"]
  node_widget_storage["Visitor storage<br/>[storage.ts]"]
  node_dashboard["Staff dashboard<br/>[DashboardShell.tsx]"]
  node_dashboard_auth["Dashboard session<br/>[App.tsx]"]
end

subgraph group_api["API services"]
  node_api_entry["API application<br/>[app.module.ts]"]
  node_auth["Authentication<br/>[auth.service.ts]"]
  node_visitors["Visitor identity"]
  node_conversations["Conversation workflow"]
  node_messages["Message handling"]
  node_realtime["Realtime chat<br/>[chat.gateway.ts]"]
end

subgraph group_admin["Tenant administration"]
  node_website_admin["Website settings"]
  node_faq["FAQ knowledge base<br/>[faqs.service.ts]"]
  node_memberships["Staff memberships"]
  node_users["Staff accounts<br/>[users.service.ts]"]
  node_assignments["Conversation assignments"]
end

subgraph group_automation["AI and reporting"]
  node_ai["AI agent<br/>[ai.worker.ts]"]
  node_reports["Tenant reports<br/>[reports.service.ts]"]
end

subgraph group_persistence["Persistence"]
  node_postgres[("Postgres database")]
end

node_visitor(("Website visitor"))
node_model["Model backend"]

node_visitor -->|"opens chat"| node_widget
node_widget -->|"HTTP and sockets"| node_api_entry
node_dashboard -->|"HTTP and sockets"| node_api_entry
node_widget -->|"renders"| node_widget_ui
node_widget -->|"sends messages"| node_widget_messages
node_widget -->|"loads and saves"| node_widget_storage
node_dashboard_auth -->|"shows after login"| node_dashboard
node_api_entry -->|"registers module"| node_auth
node_api_entry -->|"registers module"| node_conversations
node_api_entry -->|"registers module"| node_visitors
node_api_entry -->|"registers module"| node_realtime
node_api_entry -->|"registers module"| node_reports
node_api_entry -->|"registers module"| node_website_admin
node_api_entry -->|"registers module"| node_users
node_api_entry -->|"registers module"| node_ai
node_api_entry -->|"persists data"| node_postgres
node_auth -->|"looks up accounts"| node_users
node_visitors -.->|"reads and writes"| node_postgres
node_conversations -.->|"reads and writes"| node_postgres
node_messages -.->|"reads and writes"| node_postgres
node_realtime -.->|"dispatches messages"| node_messages
node_ai -->|"grounds answers"| node_faq
node_ai -->|"requests completions"| node_model
node_ai -->|"hands off threads"| node_conversations
node_reports -->|"aggregates data"| node_postgres
node_memberships -.->|"reads and writes"| node_postgres
node_assignments -.->|"reads and writes"| node_postgres

click node_widget "https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/WidgetApp.tsx"
click node_widget_ui "https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/components/Panel.tsx"
click node_widget_messages "https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/lib/messages.ts"
click node_widget_storage "https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/lib/storage.ts"
click node_dashboard "https://github.com/aayush746/wiget_chat/blob/main/apps/dashboard/src/app/DashboardShell.tsx"
click node_dashboard_auth "https://github.com/aayush746/wiget_chat/blob/main/apps/dashboard/src/App.tsx"
click node_api_entry "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/app.module.ts"
click node_auth "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/auth/auth.service.ts"
click node_visitors "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/visitors/visitors.service.ts"
click node_conversations "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/conversations/conversations.service.ts"
click node_messages "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/conversations/messages.service.ts"
click node_realtime "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/realtime/chat.gateway.ts"
click node_website_admin "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/websites/websites.service.ts"
click node_faq "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/websites/faqs.service.ts"
click node_memberships "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/websites/memberships.service.ts"
click node_users "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/users/users.service.ts"
click node_assignments "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/conversations/assignments.service.ts"
click node_ai "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/ai/ai.worker.ts"
click node_reports "https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/reports/reports.service.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_widget_ui,node_widget_messages,node_widget_storage,node_dashboard,node_dashboard_auth toneBlue
class node_api_entry,node_auth,node_visitors,node_conversations,node_messages,node_realtime toneAmber
class node_website_admin,node_faq,node_memberships,node_users,node_assignments toneMint
class node_ai,node_reports toneRose
class node_postgres,node_visitor,node_model toneIndigo
```

## Components

### Chat clients

- [Chat widget](https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/WidgetApp.tsx): `apps/widget/src/WidgetApp.tsx`
- [Widget panel](https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/components/Panel.tsx): `apps/widget/src/components/Panel.tsx`
- [Message state](https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/lib/messages.ts): `apps/widget/src/lib/messages.ts`
- [Visitor storage](https://github.com/aayush746/wiget_chat/blob/main/apps/widget/src/lib/storage.ts): `apps/widget/src/lib/storage.ts`
- [Staff dashboard](https://github.com/aayush746/wiget_chat/blob/main/apps/dashboard/src/app/DashboardShell.tsx): `apps/dashboard/src/app/DashboardShell.tsx`
- [Dashboard session](https://github.com/aayush746/wiget_chat/blob/main/apps/dashboard/src/App.tsx): `apps/dashboard/src/App.tsx`

### API services

- [API application](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/app.module.ts): `apps/api/src/app.module.ts`
- [Authentication](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/auth/auth.service.ts): `apps/api/src/auth/auth.service.ts`
- [Visitor identity](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/visitors/visitors.service.ts): `apps/api/src/visitors/visitors.service.ts`
- [Conversation workflow](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/conversations/conversations.service.ts): `apps/api/src/conversations/conversations.service.ts`
- [Message handling](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/conversations/messages.service.ts): `apps/api/src/conversations/messages.service.ts`
- [Realtime chat](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/realtime/chat.gateway.ts): `apps/api/src/realtime/chat.gateway.ts`

### Tenant administration

- [Website settings](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/websites/websites.service.ts): `apps/api/src/websites/websites.service.ts`
- [FAQ knowledge base](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/websites/faqs.service.ts): `apps/api/src/websites/faqs.service.ts`
- [Staff memberships](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/websites/memberships.service.ts): `apps/api/src/websites/memberships.service.ts`
- [Staff accounts](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/users/users.service.ts): `apps/api/src/users/users.service.ts`
- [Conversation assignments](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/conversations/assignments.service.ts): `apps/api/src/conversations/assignments.service.ts`

### AI and reporting

- [AI agent](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/ai/ai.worker.ts): `apps/api/src/ai/ai.worker.ts`
- [Tenant reports](https://github.com/aayush746/wiget_chat/blob/main/apps/api/src/reports/reports.service.ts): `apps/api/src/reports/reports.service.ts`

### Persistence

- **Postgres database**

### Other components

- **Website visitor**
- **Model backend**

## Connections

- Website visitor → Chat widget: opens chat
- Chat widget → API application: HTTP and sockets
- Staff dashboard → API application: HTTP and sockets
- Chat widget → Widget panel: renders (evidence: `apps/widget/src/WidgetApp.tsx`)
- Chat widget → Message state: sends messages (evidence: `apps/widget/src/WidgetApp.tsx`)
- Chat widget → Visitor storage: loads and saves (evidence: `apps/widget/src/WidgetApp.tsx`)
- Dashboard session → Staff dashboard: shows after login (evidence: `apps/dashboard/src/App.tsx`)
- API application → Authentication: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → Conversation workflow: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → Visitor identity: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → Realtime chat: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → Tenant reports: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → Website settings: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → Staff accounts: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → AI agent: registers module (evidence: `apps/api/src/app.module.ts`)
- API application → Postgres database: persists data
- Authentication → Staff accounts: looks up accounts (evidence: `apps/api/src/auth/auth.service.ts`)
- Visitor identity → Postgres database: reads and writes
- Conversation workflow → Postgres database: reads and writes
- Message handling → Postgres database: reads and writes
- Realtime chat → Message handling: dispatches messages
- AI agent → FAQ knowledge base: grounds answers
- AI agent → Model backend: requests completions
- AI agent → Conversation workflow: hands off threads
- Tenant reports → Postgres database: aggregates data
- Staff memberships → Postgres database: reads and writes
- Conversation assignments → Postgres database: reads and writes
