# debjoy26/text_ai_ragbot architecture

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

- Interactive diagram: https://gitdiagram.com/debjoy26/text_ai_ragbot
- Repository: https://github.com/debjoy26/text_ai_ragbot

## Overview

RAGbot is a multi-tenant website chatbot with an embeddable visitor widget, a client portal, a provider console, and a server/API plus background-worker process. The visitor flow loads the widget’s manifest and status, answers eligible FAQs locally, and otherwise creates a session and sends chat to the API. The README documents broader client onboarding, knowledge management, escalation, usage, and operational capabilities. Some server wiring and integrations are unsampled; those links are omitted rather than inferred.

Main entry points: [`apps/server/src/index.ts`](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/index.ts) (REST and chat API), [`apps/widget/src/bundle.ts`](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/bundle.ts) (Widget runtime), [`apps/server/src/rag.ts`](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/rag.ts) (Retrieval and ingestion), [`apps/widget/src/api.ts`](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/api.ts) (Widget HTTP client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_visitor["Visitor widget"]
  node_widget_bundle["Widget runtime<br/>[bundle.ts]"]
  node_widget_api["Widget HTTP client<br/>[api.ts]"]
  node_faq_matcher["FAQ matcher<br/>[matcher.ts]"]
  node_answer_gate["Answer gate<br/>[gate.ts]"]
  node_widget_ui["Chat interface<br/>[ui.ts]"]
end

subgraph group_server["Server services"]
  node_server_api["REST and chat API<br/>[index.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_tenant["Tenant context<br/>[tenant.ts]"]
  node_rag["Retrieval and ingestion<br/>[rag.ts]"]
  node_knowledge["Knowledge management<br/>[knowledge.ts]"]
  node_onboarding["Client onboarding<br/>[onboarding.ts]"]
  node_escalation["Escalation handling<br/>[escalation.ts]"]
  node_manifest["Manifest publishing<br/>[manifest.ts]"]
  node_usage["Usage tracking<br/>[usage.ts]"]
  node_worker["Background worker<br/>[worker.ts]"]
end

subgraph group_client["Client portal"]
  node_portal_ui["Client workspace<br/>[App.tsx]"]
  node_portal_api["Client API wrapper<br/>[api.ts]"]
end

subgraph group_provider["Provider console"]
  node_console_ui["Provider console<br/>[App.tsx]"]
  node_console_api["Provider API wrapper<br/>[api.ts]"]
end

subgraph group_data["Data and integrations"]
  node_repositories[("Postgres repositories<br/>[repos.ts]")]
  node_llm["LLM provider layer<br/>[index.ts]"]
  node_email["Email service<br/>[index.ts]"]
end

node_visitor(("Website visitor"))
node_client(("Client operator"))
node_provider(("Provider staff"))

node_visitor -->|"loads widget"| node_widget_bundle
node_widget_bundle -->|"fetches data"| node_widget_api
node_widget_bundle -->|"evaluates answers"| node_answer_gate
node_widget_bundle -->|"renders chat"| node_widget_ui
node_answer_gate -->|"matches FAQs"| node_faq_matcher
node_widget_api -->|"calls REST API"| node_server_api
node_client -->|"manages account"| node_portal_ui
node_portal_ui -->|"calls client API"| node_portal_api
node_portal_api -->|"calls REST API"| node_server_api
node_provider -->|"manages service"| node_console_ui
node_console_ui -->|"calls provider API"| node_console_api
node_console_api -->|"calls REST API"| node_server_api
node_server_api -.->|"authenticates requests"| node_auth
node_auth -->|"resolves tenant"| node_tenant
node_server_api -.->|"handles chat and ingestion"| node_rag
node_server_api -.->|"serves onboarding"| node_onboarding
node_server_api -.->|"serves knowledge operations"| node_knowledge
node_server_api -.->|"serves escalations"| node_escalation
node_server_api -.->|"serves manifest"| node_manifest
node_server_api -.->|"serves usage data"| node_usage
node_worker -.->|"runs scheduled jobs"| node_server_api
node_rag -.->|"persists knowledge"| node_repositories
node_rag -.->|"generates answers"| node_llm
node_onboarding -.->|"sends account email"| node_email

click node_widget_bundle "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/bundle.ts"
click node_widget_api "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/api.ts"
click node_faq_matcher "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/matcher.ts"
click node_answer_gate "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/gate.ts"
click node_widget_ui "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/ui.ts"
click node_server_api "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/index.ts"
click node_auth "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/auth.ts"
click node_tenant "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/tenant.ts"
click node_rag "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/rag.ts"
click node_knowledge "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/knowledge.ts"
click node_onboarding "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/onboarding.ts"
click node_escalation "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/escalation.ts"
click node_manifest "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/manifest.ts"
click node_usage "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/usage.ts"
click node_worker "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/worker.ts"
click node_portal_ui "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/portal/src/App.tsx"
click node_portal_api "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/portal/src/api.ts"
click node_console_ui "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/console/src/App.tsx"
click node_console_api "https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/console/src/api.ts"
click node_repositories "https://github.com/debjoy26/text_ai_ragbot/blob/main/packages/db/src/repos.ts"
click node_llm "https://github.com/debjoy26/text_ai_ragbot/blob/main/packages/llm/src/index.ts"
click node_email "https://github.com/debjoy26/text_ai_ragbot/blob/main/packages/email/src/index.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_bundle,node_widget_api,node_faq_matcher,node_answer_gate,node_widget_ui,node_client toneBlue
class node_server_api,node_auth,node_tenant,node_rag,node_knowledge,node_onboarding,node_escalation,node_manifest,node_usage,node_worker toneAmber
class node_portal_ui,node_portal_api toneMint
class node_console_ui,node_console_api toneRose
class node_repositories,node_llm,node_email,node_visitor,node_provider toneIndigo
```

## Components

### Visitor widget

- [Widget runtime](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/bundle.ts): `apps/widget/src/bundle.ts`
- [Widget HTTP client](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/api.ts): `apps/widget/src/api.ts`
- [FAQ matcher](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/matcher.ts): `apps/widget/src/matcher.ts`
- [Answer gate](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/gate.ts): `apps/widget/src/gate.ts`
- [Chat interface](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/widget/src/ui.ts): `apps/widget/src/ui.ts`

### Server services

- [REST and chat API](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/index.ts): `apps/server/src/index.ts`
- [Authentication](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/auth.ts): `apps/server/src/auth.ts`
- [Tenant context](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/tenant.ts): `apps/server/src/tenant.ts`
- [Retrieval and ingestion](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/rag.ts): `apps/server/src/rag.ts`
- [Knowledge management](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/knowledge.ts): `apps/server/src/knowledge.ts`
- [Client onboarding](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/onboarding.ts): `apps/server/src/onboarding.ts`
- [Escalation handling](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/escalation.ts): `apps/server/src/escalation.ts`
- [Manifest publishing](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/manifest.ts): `apps/server/src/manifest.ts`
- [Usage tracking](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/usage.ts): `apps/server/src/usage.ts`
- [Background worker](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/server/src/worker.ts): `apps/server/src/worker.ts`

### Client portal

- [Client workspace](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/portal/src/App.tsx): `apps/portal/src/App.tsx`
- [Client API wrapper](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/portal/src/api.ts): `apps/portal/src/api.ts`

### Provider console

- [Provider console](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/console/src/App.tsx): `apps/console/src/App.tsx`
- [Provider API wrapper](https://github.com/debjoy26/text_ai_ragbot/blob/main/apps/console/src/api.ts): `apps/console/src/api.ts`

### Data and integrations

- [Postgres repositories](https://github.com/debjoy26/text_ai_ragbot/blob/main/packages/db/src/repos.ts): `packages/db/src/repos.ts`
- [LLM provider layer](https://github.com/debjoy26/text_ai_ragbot/blob/main/packages/llm/src/index.ts): `packages/llm/src/index.ts`
- [Email service](https://github.com/debjoy26/text_ai_ragbot/blob/main/packages/email/src/index.ts): `packages/email/src/index.ts`

### Other components

- **Website visitor**
- **Client operator**
- **Provider staff**

## Connections

- Website visitor → Widget runtime: loads widget
- Widget runtime → Widget HTTP client: fetches data (evidence: `apps/widget/src/bundle.ts`)
- Widget runtime → Answer gate: evaluates answers (evidence: `apps/widget/src/bundle.ts`)
- Widget runtime → Chat interface: renders chat (evidence: `apps/widget/src/bundle.ts`)
- Answer gate → FAQ matcher: matches FAQs (evidence: `apps/widget/src/gate.ts`)
- Widget HTTP client → REST and chat API: calls REST API
- Client operator → Client workspace: manages account
- Client workspace → Client API wrapper: calls client API (evidence: `apps/portal/src/App.tsx`)
- Client API wrapper → REST and chat API: calls REST API
- Provider staff → Provider console: manages service
- Provider console → Provider API wrapper: calls provider API (evidence: `apps/console/src/App.tsx`)
- Provider API wrapper → REST and chat API: calls REST API
- REST and chat API → Authentication: authenticates requests
- Authentication → Tenant context: resolves tenant (evidence: `apps/server/src/auth.ts`)
- REST and chat API → Retrieval and ingestion: handles chat and ingestion
- REST and chat API → Client onboarding: serves onboarding
- REST and chat API → Knowledge management: serves knowledge operations
- REST and chat API → Escalation handling: serves escalations
- REST and chat API → Manifest publishing: serves manifest
- REST and chat API → Usage tracking: serves usage data
- Background worker → REST and chat API: runs scheduled jobs
- Retrieval and ingestion → Postgres repositories: persists knowledge
- Retrieval and ingestion → LLM provider layer: generates answers
- Client onboarding → Email service: sends account email
