# sabtain-dev/rag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/sabtain-dev/rag-chatbot
- Repository: https://github.com/sabtain-dev/rag-chatbot

## Overview

Lumeluxe is a storefront RAG chatbot: a customer asks through the widget, the API applies session-aware chat logic, retrieves relevant catalog or policy content, and returns a grounded answer or fallback. The separate knowledge-base workflow ingests live product data and indexes cleaned documents. The graph preserves documented streaming, session reset, and rate limiting. Relationships for sampled runtime code are excerpt-backed; ingestion and indexing links rely on the README, since those scripts were not excerpted.

Main entry points: [`app/chatbot/rag_service.py`](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/rag_service.py) (RAG service), [`app/api/routes.py`](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/api/routes.py) (Chat routes), [`scripts/index_documents.py`](https://github.com/sabtain-dev/rag-chatbot/blob/main/scripts/index_documents.py) (Document indexing), [`app/chatbot/generator.py`](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/generator.py) (Answer generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_widget["Chat widget<br/>[chatbot.js]"]
end

subgraph group_api["API and limits"]
  node_app["FastAPI app<br/>[main.py]"]
  node_routes["Chat routes<br/>[routes.py]"]
  node_request_schema["Chat schemas<br/>[chat.py]"]
  node_ip_limiter["IP rate limiter<br/>[rate_limit.py]"]
  node_config["Runtime config<br/>[config.py]"]
end

subgraph group_chat["Chat and retrieval"]
  node_service["RAG service<br/>[rag_service.py]"]
  node_memory["Session memory<br/>[memory.py]"]
  node_retriever["Retriever<br/>[retriever.py]"]
  node_generator["Answer generator<br/>[generator.py]"]
  node_prompts["System prompts<br/>[prompts.py]"]
end

subgraph group_knowledge["Knowledge base"]
  node_embeddings["Query embeddings<br/>[embeddings.py]"]
  node_vector_store[("ChromaDB")]
  node_ingestion["Catalog ingestion<br/>[ingest_from_db.py]"]
  node_cleaned_data["Cleaned documents"]
  node_indexing["Document indexing<br/>[index_documents.py]"]
  node_chunker["Document chunker<br/>[chunker.py]"]
end

node_customer(("Customer"))
node_groq["Groq API"]
node_mongo[("MongoDB Atlas")]

node_customer -->|"asks"| node_widget
node_widget -->|"sends chat"| node_routes
node_app -->|"mounts"| node_routes
node_app -->|"attaches"| node_ip_limiter
node_routes -->|"validates"| node_request_schema
node_routes -->|"limits requests"| node_ip_limiter
node_routes -->|"dispatches chat"| node_service
node_service -->|"reads and writes"| node_memory
node_service -->|"retrieves context"| node_retriever
node_service -->|"generates answer"| node_generator
node_service -->|"returns response"| node_request_schema
node_retriever -->|"embeds query"| node_embeddings
node_retriever -->|"queries"| node_vector_store
node_generator -->|"uses prompt"| node_prompts
node_generator -->|"loads settings"| node_config
node_generator -->|"requests completion"| node_groq
node_mongo -->|"provides catalog"| node_ingestion
node_ingestion -->|"feeds reindexing"| node_indexing
node_cleaned_data -->|"supplies documents"| node_indexing
node_indexing -->|"chunks documents"| node_chunker
node_indexing -->|"creates vectors"| node_embeddings
node_indexing -->|"indexes chunks"| node_vector_store

click node_widget "https://github.com/sabtain-dev/rag-chatbot/blob/main/frontend/chatbot.js"
click node_app "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/main.py"
click node_routes "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/api/routes.py"
click node_request_schema "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/models/chat.py"
click node_ip_limiter "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/core/rate_limit.py"
click node_service "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/rag_service.py"
click node_memory "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/memory.py"
click node_retriever "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/retriever.py"
click node_embeddings "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/rag/embeddings.py"
click node_vector_store "https://github.com/sabtain-dev/rag-chatbot/tree/main/chroma_db"
click node_generator "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/generator.py"
click node_prompts "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/prompts.py"
click node_config "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/core/config.py"
click node_ingestion "https://github.com/sabtain-dev/rag-chatbot/blob/main/scripts/ingest_from_db.py"
click node_cleaned_data "https://github.com/sabtain-dev/rag-chatbot/tree/main/data/cleaned"
click node_indexing "https://github.com/sabtain-dev/rag-chatbot/blob/main/scripts/index_documents.py"
click node_chunker "https://github.com/sabtain-dev/rag-chatbot/blob/main/app/rag/chunker.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_widget toneBlue
class node_app,node_routes,node_request_schema,node_ip_limiter,node_config,node_mongo toneAmber
class node_service,node_memory,node_retriever,node_generator,node_prompts,node_groq toneMint
class node_embeddings,node_vector_store,node_ingestion,node_cleaned_data,node_indexing,node_chunker toneRose
class node_customer toneIndigo
```

## Components

### Chat client

- [Chat widget](https://github.com/sabtain-dev/rag-chatbot/blob/main/frontend/chatbot.js): `frontend/chatbot.js`

### API and limits

- [FastAPI app](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/main.py): `app/main.py`
- [Chat routes](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/api/routes.py): `app/api/routes.py`
- [Chat schemas](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/models/chat.py): `app/models/chat.py`
- [IP rate limiter](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/core/rate_limit.py): `app/core/rate_limit.py`
- [Runtime config](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/core/config.py): `app/core/config.py`

### Chat and retrieval

- [RAG service](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/rag_service.py): `app/chatbot/rag_service.py`
- [Session memory](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/memory.py): `app/chatbot/memory.py`
- [Retriever](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/retriever.py): `app/chatbot/retriever.py`
- [Answer generator](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/generator.py): `app/chatbot/generator.py`
- [System prompts](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/chatbot/prompts.py): `app/chatbot/prompts.py`

### Knowledge base

- [Query embeddings](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/rag/embeddings.py): `app/rag/embeddings.py`
- [ChromaDB](https://github.com/sabtain-dev/rag-chatbot/tree/main/chroma_db): `chroma_db`
- [Catalog ingestion](https://github.com/sabtain-dev/rag-chatbot/blob/main/scripts/ingest_from_db.py): `scripts/ingest_from_db.py`
- [Cleaned documents](https://github.com/sabtain-dev/rag-chatbot/tree/main/data/cleaned): `data/cleaned`
- [Document indexing](https://github.com/sabtain-dev/rag-chatbot/blob/main/scripts/index_documents.py): `scripts/index_documents.py`
- [Document chunker](https://github.com/sabtain-dev/rag-chatbot/blob/main/app/rag/chunker.py): `app/rag/chunker.py`

### Other components

- **Customer**
- **Groq API**
- **MongoDB Atlas**

## Connections

- Customer → Chat widget: asks (evidence: `README.md`)
- Chat widget → Chat routes: sends chat (evidence: `README.md`)
- FastAPI app → Chat routes: mounts (evidence: `app/main.py`)
- FastAPI app → IP rate limiter: attaches (evidence: `app/main.py`)
- Chat routes → Chat schemas: validates (evidence: `app/api/routes.py`)
- Chat routes → IP rate limiter: limits requests (evidence: `app/api/routes.py`)
- Chat routes → RAG service: dispatches chat (evidence: `app/api/routes.py`)
- RAG service → Session memory: reads and writes (evidence: `app/chatbot/rag_service.py`)
- RAG service → Retriever: retrieves context (evidence: `app/chatbot/rag_service.py`)
- RAG service → Answer generator: generates answer (evidence: `app/chatbot/rag_service.py`)
- RAG service → Chat schemas: returns response (evidence: `app/chatbot/rag_service.py`)
- Retriever → Query embeddings: embeds query (evidence: `app/chatbot/retriever.py`)
- Retriever → ChromaDB: queries (evidence: `app/chatbot/retriever.py`)
- Answer generator → System prompts: uses prompt (evidence: `app/chatbot/generator.py`)
- Answer generator → Runtime config: loads settings (evidence: `app/chatbot/generator.py`)
- Answer generator → Groq API: requests completion (evidence: `app/chatbot/generator.py`)
- MongoDB Atlas → Catalog ingestion: provides catalog (evidence: `README.md`)
- Catalog ingestion → Document indexing: feeds reindexing (evidence: `README.md`)
- Cleaned documents → Document indexing: supplies documents (evidence: `README.md`)
- Document indexing → Document chunker: chunks documents (evidence: `scripts/index_documents.py`)
- Document indexing → Query embeddings: creates vectors (evidence: `scripts/index_documents.py`)
- Document indexing → ChromaDB: indexes chunks (evidence: `scripts/index_documents.py`)
