# amdkhalid8214/docuchat-ai-rag-system architecture

> Architecture diagram of the GitHub repository amdkhalid8214/docuchat-ai-rag-system, 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/amdkhalid8214/docuchat-ai-rag-system
- Repository: https://github.com/amdkhalid8214/docuchat-ai-rag-system

## Overview

DocuChat AI turns uploaded documents into searchable, provenance-bearing chunks, then answers questions with hybrid retrieval and grounded generation. Users interact through a React interface and backend APIs; the main paths are document ingestion and question answering, with conversation/authentication and live web knowledge as supporting capabilities. Documented features include PDF bounding-box highlighting, streaming answers, and general/live-web routing. The README and sampled sources support these links; some subsystems, including the frontend internals and web-search dispatch, are not fully shown, so those relationships rely on README documentation.

Main entry points: [`RAG-Based-ChatBot-Main/backend/api/documents.py`](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/documents.py) (Document API), [`RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py) (Retrieval Pipeline), [`RAG-Based-ChatBot-Main/backend/api/chat.py`](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/chat.py) (Chat API), [`RAG-Based-ChatBot-Main/backend/main.py`](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/main.py) (API Application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document Ingestion"]
  node_documents["Document API<br/>[documents.py]"]
  node_converter["Format Converter<br/>[converter.py]"]
  node_parser["Layout Parser<br/>[docling_parser.py]"]
  node_chunker["Structure Chunker"]
  node_embedder["Embedding Service<br/>[embedder.py]"]
  node_bm25["BM25 Index<br/>[bm25.py]"]
  node_vectors[("Vector Store<br/>[vector_store.py]")]
  node_bm25store[("BM25 Cache<br/>[bm25.py]")]
end

subgraph group_retrieval["Hybrid Retrieval"]
  node_pipeline["Retrieval Pipeline<br/>[pipeline.py]"]
  node_fusion["Rank Fusion<br/>[fusion.py]"]
  node_dedup["Chunk Deduplication<br/>[dedup.py]"]
  node_reranker["Cross-Encoder Reranker<br/>[reranker.py]"]
end

subgraph group_answering["Answering"]
  node_chat["Chat API<br/>[chat.py]"]
  node_router["Query Router<br/>[router.py]"]
  node_rewriter["Query Rewriter<br/>[rewriter.py]"]
  node_generator["Grounded Generator<br/>[generator.py]"]
  node_websearch["Live Web Search<br/>[web_search.py]"]
end

subgraph group_product["Application &amp; State"]
  node_ui["React Interface<br/>[App.jsx]"]
  node_app["API Application<br/>[main.py]"]
  node_sql[("Application Database<br/>[models.py]")]
  node_conversations["Conversation API<br/>[conversations.py]"]
  node_auth["Authentication API<br/>[auth.py]"]
end

node_user(("User"))
node_ollama["Ollama Service"]
node_docling["Docling Service"]

node_user -->|"uses"| node_ui
node_ui -.->|"requests"| node_app
node_app -->|"mounts"| node_documents
node_app -->|"mounts"| node_chat
node_app -->|"mounts"| node_conversations
node_app -->|"mounts"| node_auth
node_documents -->|"converts"| node_converter
node_documents -->|"parses"| node_parser
node_documents -->|"chunks"| node_chunker
node_documents -->|"embeds"| node_embedder
node_documents -->|"indexes vectors"| node_vectors
node_documents -->|"builds index"| node_bm25
node_parser -->|"parses remotely"| node_docling
node_chunker -->|"chunks elements"| node_parser
node_bm25 -->|"persists index"| node_bm25store
node_chat -->|"reads and writes"| node_sql
node_conversations -->|"reads and writes"| node_sql
node_auth -->|"reads and writes"| node_sql
node_chat -->|"routes query"| node_router
node_chat -->|"rewrites query"| node_rewriter
node_chat -->|"retrieves passages"| node_pipeline
node_chat -->|"generates answer"| node_generator
node_pipeline -->|"embeds queries"| node_embedder
node_pipeline -->|"searches vectors"| node_vectors
node_pipeline -->|"searches terms"| node_bm25
node_pipeline -->|"fuses rankings"| node_fusion
node_pipeline -->|"deduplicates hits"| node_dedup
node_pipeline -->|"reranks candidates"| node_reranker
node_generator -->|"generates tokens"| node_ollama
node_generator -->|"uses fallback"| node_websearch
node_websearch -.->|"returns context"| node_ollama
node_generator -->|"streams answer"| node_ui
node_ui -.->|"shows provenance"| node_vectors

click node_ui "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/frontend/src/App.jsx"
click node_app "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/main.py"
click node_documents "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/documents.py"
click node_converter "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/parsers/converter.py"
click node_parser "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/parsers/docling_parser.py"
click node_chunker "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/chunking/structure_chunker.py"
click node_embedder "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/embeddings/embedder.py"
click node_bm25 "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/bm25.py"
click node_vectors "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/vector_store.py"
click node_bm25store "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/bm25.py"
click node_chat "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/chat.py"
click node_router "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/llm/router.py"
click node_rewriter "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/llm/rewriter.py"
click node_pipeline "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py"
click node_fusion "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/fusion.py"
click node_dedup "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/dedup.py"
click node_reranker "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/reranker.py"
click node_generator "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/llm/generator.py"
click node_websearch "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/web_search.py"
click node_sql "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/db/models.py"
click node_conversations "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/conversations.py"
click node_auth "https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/auth.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_documents,node_converter,node_parser,node_chunker,node_embedder,node_bm25,node_vectors,node_bm25store,node_user toneBlue
class node_pipeline,node_fusion,node_dedup,node_reranker toneAmber
class node_chat,node_router,node_rewriter,node_generator,node_websearch toneMint
class node_ui,node_app,node_sql,node_conversations,node_auth toneRose
class node_ollama,node_docling toneIndigo
```

## Components

### Document Ingestion

- [Document API](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/documents.py): `RAG-Based-ChatBot-Main/backend/api/documents.py`
- [Format Converter](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/parsers/converter.py): `RAG-Based-ChatBot-Main/backend/parsers/converter.py`
- [Layout Parser](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/parsers/docling_parser.py): `RAG-Based-ChatBot-Main/backend/parsers/docling_parser.py`
- [Structure Chunker](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/chunking/structure_chunker.py): `RAG-Based-ChatBot-Main/backend/chunking/structure_chunker.py`
- [Embedding Service](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/embeddings/embedder.py): `RAG-Based-ChatBot-Main/backend/embeddings/embedder.py`
- [BM25 Index](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/bm25.py): `RAG-Based-ChatBot-Main/backend/retrieval/bm25.py`
- [Vector Store](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/vector_store.py): `RAG-Based-ChatBot-Main/backend/retrieval/vector_store.py`
- [BM25 Cache](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/bm25.py): `RAG-Based-ChatBot-Main/backend/retrieval/bm25.py`

### Hybrid Retrieval

- [Retrieval Pipeline](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py): `RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`
- [Rank Fusion](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/fusion.py): `RAG-Based-ChatBot-Main/backend/retrieval/fusion.py`
- [Chunk Deduplication](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/dedup.py): `RAG-Based-ChatBot-Main/backend/retrieval/dedup.py`
- [Cross-Encoder Reranker](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/reranker.py): `RAG-Based-ChatBot-Main/backend/retrieval/reranker.py`

### Answering

- [Chat API](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/chat.py): `RAG-Based-ChatBot-Main/backend/api/chat.py`
- [Query Router](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/llm/router.py): `RAG-Based-ChatBot-Main/backend/llm/router.py`
- [Query Rewriter](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/llm/rewriter.py): `RAG-Based-ChatBot-Main/backend/llm/rewriter.py`
- [Grounded Generator](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/llm/generator.py): `RAG-Based-ChatBot-Main/backend/llm/generator.py`
- [Live Web Search](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/retrieval/web_search.py): `RAG-Based-ChatBot-Main/backend/retrieval/web_search.py`

### Application & State

- [React Interface](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/frontend/src/App.jsx): `RAG-Based-ChatBot-Main/frontend/src/App.jsx`
- [API Application](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/main.py): `RAG-Based-ChatBot-Main/backend/main.py`
- [Application Database](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/db/models.py): `RAG-Based-ChatBot-Main/backend/db/models.py`
- [Conversation API](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/conversations.py): `RAG-Based-ChatBot-Main/backend/api/conversations.py`
- [Authentication API](https://github.com/amdkhalid8214/docuchat-ai-rag-system/blob/main/RAG-Based-ChatBot-Main/backend/api/auth.py): `RAG-Based-ChatBot-Main/backend/api/auth.py`

### Other components

- **User**
- **Ollama Service**
- **Docling Service**

## Connections

- User → React Interface: uses
- React Interface → API Application: requests
- API Application → Document API: mounts (evidence: `RAG-Based-ChatBot-Main/backend/main.py`)
- API Application → Chat API: mounts (evidence: `RAG-Based-ChatBot-Main/backend/main.py`)
- API Application → Conversation API: mounts (evidence: `RAG-Based-ChatBot-Main/backend/main.py`)
- API Application → Authentication API: mounts (evidence: `RAG-Based-ChatBot-Main/backend/main.py`)
- Document API → Format Converter: converts (evidence: `RAG-Based-ChatBot-Main/backend/api/documents.py`)
- Document API → Layout Parser: parses (evidence: `RAG-Based-ChatBot-Main/backend/api/documents.py`)
- Document API → Structure Chunker: chunks (evidence: `RAG-Based-ChatBot-Main/backend/api/documents.py`)
- Document API → Embedding Service: embeds (evidence: `RAG-Based-ChatBot-Main/backend/api/documents.py`)
- Document API → Vector Store: indexes vectors (evidence: `RAG-Based-ChatBot-Main/backend/api/documents.py`)
- Document API → BM25 Index: builds index (evidence: `RAG-Based-ChatBot-Main/backend/api/documents.py`)
- Layout Parser → Docling Service: parses remotely (evidence: `RAG-Based-ChatBot-Main/backend/parsers/docling_parser.py`)
- Structure Chunker → Layout Parser: chunks elements (evidence: `RAG-Based-ChatBot-Main/backend/chunking/structure_chunker.py`)
- BM25 Index → BM25 Cache: persists index (evidence: `RAG-Based-ChatBot-Main/backend/retrieval/bm25.py`)
- Chat API → Application Database: reads and writes (evidence: `RAG-Based-ChatBot-Main/backend/api/chat.py`)
- Conversation API → Application Database: reads and writes (evidence: `RAG-Based-ChatBot-Main/backend/api/conversations.py`)
- Authentication API → Application Database: reads and writes (evidence: `RAG-Based-ChatBot-Main/backend/api/auth.py`)
- Chat API → Query Router: routes query (evidence: `RAG-Based-ChatBot-Main/backend/api/chat.py`)
- Chat API → Query Rewriter: rewrites query (evidence: `RAG-Based-ChatBot-Main/backend/api/chat.py`)
- Chat API → Retrieval Pipeline: retrieves passages (evidence: `RAG-Based-ChatBot-Main/backend/api/chat.py`)
- Chat API → Grounded Generator: generates answer (evidence: `RAG-Based-ChatBot-Main/backend/api/chat.py`)
- Retrieval Pipeline → Embedding Service: embeds queries (evidence: `RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`)
- Retrieval Pipeline → Vector Store: searches vectors (evidence: `RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`)
- Retrieval Pipeline → BM25 Index: searches terms (evidence: `RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`)
- Retrieval Pipeline → Rank Fusion: fuses rankings (evidence: `RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`)
- Retrieval Pipeline → Chunk Deduplication: deduplicates hits (evidence: `RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`)
- Retrieval Pipeline → Cross-Encoder Reranker: reranks candidates (evidence: `RAG-Based-ChatBot-Main/backend/retrieval/pipeline.py`)
- Grounded Generator → Ollama Service: generates tokens
- Grounded Generator → Live Web Search: uses fallback (evidence: `RAG-Based-ChatBot-Main/backend/llm/generator.py`)
- Live Web Search → Ollama Service: returns context
- Grounded Generator → React Interface: streams answer
- React Interface → Vector Store: shows provenance
