# safamathlouthi06/chatbot-factory architecture

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

- Interactive diagram: https://gitdiagram.com/safamathlouthi06/chatbot-factory
- Repository: https://github.com/safamathlouthi06/chatbot-factory

## Overview

Chatbot Factory is a multi-tenant SaaS for companies and employees to create and deploy role-configured chatbots. Its core workflow is knowledge setup (documents and FAQs), conversational testing/use through the RAG answer path, and conversation history; widget deployment, account administration, notifications, and usage analytics are additional product branches. The README and sampled files support the documented RAG stages, but several routes and frontend screens were not sampled, so their internal calls are not expanded here.

Main entry points: [`backend/database.py`](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/database.py) (Supabase data and vectors), [`backend/routes/chat.py`](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/chat.py) (Chat endpoint), [`backend/services/document_service.py`](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/document_service.py) (Document processing), [`backend/services/rag_service.py`](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/rag_service.py) (RAG retrieval and selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Web application"]
  node_frontend["Company and employee workspace"]
  node_admin_ui["Admin console"]
  node_login_ui["Login and registration<br/>[page.tsx]"]
  node_chatbot_ui["Chatbot setup"]
  node_knowledge_ui["Knowledge and deployment screens"]
end

subgraph group_api["API and access"]
  node_api_entry["FastAPI application<br/>[main.py]"]
  node_auth["JWT authentication and accounts<br/>[auth.py]"]
  node_chatbot_routes["Chatbot management<br/>[chatbot.py]"]
  node_employee_routes["Employee management<br/>[employe.py]"]
end

subgraph group_knowledge["Knowledge management"]
  node_document_routes["Document endpoints<br/>[document.py]"]
  node_faq_routes["FAQ endpoints<br/>[faq.py]"]
  node_document_service["Document processing"]
  node_faq_service["FAQ indexing<br/>[faq_service.py]"]
  node_chunking["Text chunking"]
end

subgraph group_answers["Answer engine"]
  node_rag["RAG retrieval and selection<br/>[rag_service.py]"]
  node_embedding["Local embeddings"]
  node_chat_routes["Chat endpoint<br/>[chat.py]"]
  node_generation["Answer generation"]
  node_conversation_routes["Conversation history<br/>[conversation.py]"]
  node_widget_routes["Embeddable widget API<br/>[widget.py]"]
end

subgraph group_operations["Platform operations"]
  node_statistics["Usage analytics<br/>[statistiques.py]"]
  node_notifications["Notification endpoints<br/>[notification.py]"]
  node_notification_service["Notification handling"]
  node_database[("Supabase data and vectors<br/>[database.py]")]
  node_ai_config["AI and Supabase configuration<br/>[config.py]"]
end

node_company_user(("Company / employee"))
node_website_visitor(("Website visitor"))
node_azure_openai{{"Azure OpenAI"}}
node_supabase[("Supabase / PostgreSQL")]

node_company_user -->|"signs in"| node_login_ui
node_company_user -->|"manages workspace"| node_frontend
node_website_visitor -->|"uses widget"| node_widget_routes
node_frontend -->|"calls REST API"| node_api_entry
node_login_ui -->|"authenticates"| node_auth
node_admin_ui -->|"manages companies"| node_auth
node_chatbot_ui -->|"manages bots"| node_chatbot_routes
node_knowledge_ui -->|"uploads documents"| node_document_routes
node_knowledge_ui -->|"manages FAQs"| node_faq_routes
node_document_routes -->|"delegates processing"| node_document_service
node_faq_routes -->|"delegates indexing"| node_faq_service
node_document_service -.->|"chunks text"| node_chunking
node_document_service -.->|"stores knowledge"| node_database
node_faq_service -.->|"indexes FAQ"| node_database
node_chat_routes -->|"retrieves context"| node_rag
node_rag -->|"embeds question"| node_embedding
node_rag -->|"queries vector RPC"| node_ai_config
node_ai_config -->|"connects to"| node_supabase
node_chat_routes -->|"generates response"| node_generation
node_generation -->|"requests completion"| node_azure_openai
node_chat_routes -->|"records conversation"| node_database
node_conversation_routes -->|"reads history"| node_database
node_widget_routes -->|"loads bot data"| node_database
node_statistics -->|"queries usage"| node_database
node_notifications -->|"delegates handling"| node_notification_service
node_notification_service -->|"stores notifications"| node_database
node_auth -->|"reads and writes accounts"| node_database
node_employee_routes -->|"manages employee records"| node_database

click node_frontend "https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/dashboard"
click node_admin_ui "https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/admin"
click node_login_ui "https://github.com/safamathlouthi06/chatbot-factory/blob/main/frontend/app/login/page.tsx"
click node_chatbot_ui "https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/dashboard/chatbots"
click node_knowledge_ui "https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/dashboard/chatbots/%5BchatbotId%5D"
click node_api_entry "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/main.py"
click node_auth "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/auth.py"
click node_chatbot_routes "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/chatbot.py"
click node_employee_routes "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/employe.py"
click node_document_routes "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/document.py"
click node_faq_routes "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/faq.py"
click node_document_service "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/document_service.py"
click node_faq_service "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/faq_service.py"
click node_chunking "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/chunking_service.py"
click node_rag "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/rag_service.py"
click node_embedding "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/embedding_service.py"
click node_chat_routes "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/chat.py"
click node_generation "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/generation_service.py"
click node_conversation_routes "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/conversation.py"
click node_widget_routes "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/widget.py"
click node_statistics "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/statistiques.py"
click node_notifications "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/notification.py"
click node_notification_service "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/notification_service.py"
click node_database "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/database.py"
click node_ai_config "https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/core/config.py"

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_frontend,node_admin_ui,node_login_ui,node_chatbot_ui,node_knowledge_ui toneBlue
class node_api_entry,node_auth,node_chatbot_routes,node_employee_routes,node_supabase toneAmber
class node_document_routes,node_faq_routes,node_document_service,node_faq_service,node_chunking toneMint
class node_rag,node_embedding,node_chat_routes,node_generation,node_conversation_routes,node_widget_routes toneRose
class node_statistics,node_notifications,node_notification_service,node_database,node_ai_config,node_company_user,node_website_visitor,node_azure_openai toneIndigo
```

## Components

### Web application

- [Company and employee workspace](https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/dashboard): `frontend/app/dashboard`
- [Admin console](https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/admin): `frontend/app/admin`
- [Login and registration](https://github.com/safamathlouthi06/chatbot-factory/blob/main/frontend/app/login/page.tsx): `frontend/app/login/page.tsx`
- [Chatbot setup](https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/dashboard/chatbots): `frontend/app/dashboard/chatbots`
- [Knowledge and deployment screens](https://github.com/safamathlouthi06/chatbot-factory/tree/main/frontend/app/dashboard/chatbots/%5BchatbotId%5D): `frontend/app/dashboard/chatbots/[chatbotId]`

### API and access

- [FastAPI application](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/main.py): `backend/main.py`
- [JWT authentication and accounts](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/auth.py): `backend/auth.py`
- [Chatbot management](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/chatbot.py): `backend/routes/chatbot.py`
- [Employee management](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/employe.py): `backend/routes/employe.py`

### Knowledge management

- [Document endpoints](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/document.py): `backend/routes/document.py`
- [FAQ endpoints](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/faq.py): `backend/routes/faq.py`
- [Document processing](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/document_service.py): `backend/services/document_service.py`
- [FAQ indexing](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/faq_service.py): `backend/services/faq_service.py`
- [Text chunking](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/chunking_service.py): `backend/services/chunking_service.py`

### Answer engine

- [RAG retrieval and selection](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/rag_service.py): `backend/services/rag_service.py`
- [Local embeddings](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/embedding_service.py): `backend/services/embedding_service.py`
- [Chat endpoint](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/chat.py): `backend/routes/chat.py`
- [Answer generation](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/generation_service.py): `backend/services/generation_service.py`
- [Conversation history](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/conversation.py): `backend/routes/conversation.py`
- [Embeddable widget API](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/widget.py): `backend/routes/widget.py`

### Platform operations

- [Usage analytics](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/statistiques.py): `backend/routes/statistiques.py`
- [Notification endpoints](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/routes/notification.py): `backend/routes/notification.py`
- [Notification handling](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/services/notification_service.py): `backend/services/notification_service.py`
- [Supabase data and vectors](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/database.py): `backend/database.py`
- [AI and Supabase configuration](https://github.com/safamathlouthi06/chatbot-factory/blob/main/backend/core/config.py): `backend/core/config.py`

### Other components

- **Company / employee**
- **Website visitor**
- **Azure OpenAI**
- **Supabase / PostgreSQL**

## Connections

- Company / employee → Login and registration: signs in
- Company / employee → Company and employee workspace: manages workspace
- Website visitor → Embeddable widget API: uses widget
- Company and employee workspace → FastAPI application: calls REST API
- Login and registration → JWT authentication and accounts: authenticates
- Admin console → JWT authentication and accounts: manages companies (evidence: `backend/auth.py`)
- Chatbot setup → Chatbot management: manages bots
- Knowledge and deployment screens → Document endpoints: uploads documents
- Knowledge and deployment screens → FAQ endpoints: manages FAQs
- Document endpoints → Document processing: delegates processing (evidence: `backend/routes/document.py`)
- FAQ endpoints → FAQ indexing: delegates indexing (evidence: `backend/routes/faq.py`)
- Document processing → Text chunking: chunks text
- Document processing → Supabase data and vectors: stores knowledge
- FAQ indexing → Supabase data and vectors: indexes FAQ
- Chat endpoint → RAG retrieval and selection: retrieves context (evidence: `backend/routes/chat.py`)
- RAG retrieval and selection → Local embeddings: embeds question (evidence: `backend/services/rag_service.py`)
- RAG retrieval and selection → AI and Supabase configuration: queries vector RPC (evidence: `backend/services/rag_service.py`)
- AI and Supabase configuration → Supabase / PostgreSQL: connects to (evidence: `backend/core/config.py`)
- Chat endpoint → Answer generation: generates response (evidence: `backend/routes/chat.py`)
- Answer generation → Azure OpenAI: requests completion (evidence: `backend/services/generation_service.py`)
- Chat endpoint → Supabase data and vectors: records conversation (evidence: `backend/routes/chat.py`)
- Conversation history → Supabase data and vectors: reads history (evidence: `backend/routes/conversation.py`)
- Embeddable widget API → Supabase data and vectors: loads bot data (evidence: `backend/routes/widget.py`)
- Usage analytics → Supabase data and vectors: queries usage (evidence: `backend/routes/statistiques.py`)
- Notification endpoints → Notification handling: delegates handling (evidence: `backend/routes/notification.py`)
- Notification handling → Supabase data and vectors: stores notifications (evidence: `backend/services/notification_service.py`)
- JWT authentication and accounts → Supabase data and vectors: reads and writes accounts (evidence: `backend/auth.py`)
- Employee management → Supabase data and vectors: manages employee records (evidence: `backend/routes/employe.py`)
