# mitanshumakwana/pdf-chatbot-using-rag architecture

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

- Interactive diagram: https://gitdiagram.com/mitanshumakwana/pdf-chatbot-using-rag
- Repository: https://github.com/mitanshumakwana/pdf-chatbot-using-rag

## Overview

This is a session-scoped PDF RAG web app: a signed-in user uploads PDFs, asks questions about selected documents, and receives grounded answers with source pages. The browser sends authenticated requests to FastAPI; indexing and question answering are handled by the RAG assistant, which uses ChromaDB for document chunks and a configured model for generation. Redis is an optional semantic answer cache, not the document store. The graph preserves the documented extraction, chunking, embedding, per-document retrieval, and cache stages; some internal RAG details come from the README because the source excerpt is partial.

Main entry points: [`main.py`](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/main.py) (FastAPI routes), [`static/script.js`](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/static/script.js) (Chat interface), [`rag.py`](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py) (Per-document search), [`semantic_cache.py`](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/semantic_cache.py) (Semantic cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_browser["Chat interface<br/>[script.js]"]
  node_page["Web page<br/>[index.html]"]
end

subgraph group_api["API and identity"]
  node_api_routes["FastAPI routes<br/>[main.py]"]
  node_auth["Bearer verification<br/>[authentication.py]"]
end

subgraph group_rag["Document Q&amp;A"]
  node_ingest["PDF indexing<br/>[rag.py]"]
  node_extract["PDF extraction<br/>[rag.py]"]
  node_chunk_embed["Chunk and embed<br/>[rag.py]"]
  node_chroma[("ChromaDB documents<br/>[rag.py]")]
  node_retrieve["Per-document search<br/>[rag.py]"]
  node_context["Labeled context<br/>[rag.py]"]
  node_model["Configured LLM<br/>[rag.py]"]
  node_answer["Answer and sources<br/>[rag.py]"]
end

subgraph group_cache["Answer cache"]
  node_cache_lifecycle["Cache lifecycle<br/>[main.py]"]
  node_cache_logic["Semantic cache<br/>[semantic_cache.py]"]
end

node_user(("Signed-in user"))
node_supabase["Supabase Auth"]
node_providers["Ollama or Gemini"]
node_redis[("Redis Search")]

node_user -->|"uses"| node_browser
node_browser -->|"renders"| node_page
node_browser -->|"sends requests"| node_api_routes
node_browser -->|"authenticates"| node_supabase
node_api_routes -->|"requires user"| node_auth
node_auth -->|"verifies token"| node_supabase
node_api_routes -->|"indexes PDF"| node_ingest
node_ingest -->|"extracts text"| node_extract
node_extract -->|"splits and embeds"| node_chunk_embed
node_chunk_embed -->|"stores chunks"| node_chroma
node_api_routes -->|"queries documents"| node_retrieve
node_retrieve -->|"searches chunks"| node_chroma
node_retrieve -->|"labels results"| node_context
node_context -->|"prompts model"| node_model
node_model -->|"calls provider"| node_providers
node_model -->|"generates answer"| node_answer
node_answer -->|"returns sources"| node_browser
node_api_routes -->|"starts and closes"| node_cache_lifecycle
node_cache_lifecycle -->|"creates cache"| node_cache_logic
node_cache_logic -->|"reads and writes"| node_redis
node_retrieve -->|"looks up and stores answers"| node_cache_logic
node_ingest -->|"invalidates scope"| node_cache_logic

click node_browser "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/static/script.js"
click node_page "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/templates/index.html"
click node_api_routes "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/main.py"
click node_auth "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/authentication.py"
click node_ingest "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_extract "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_chunk_embed "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_chroma "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_retrieve "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_context "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_model "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_answer "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py"
click node_cache_lifecycle "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/main.py"
click node_cache_logic "https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/semantic_cache.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_browser,node_page,node_user toneBlue
class node_api_routes,node_auth,node_redis toneAmber
class node_ingest,node_extract,node_chunk_embed,node_chroma,node_retrieve,node_context,node_model,node_answer toneMint
class node_cache_lifecycle,node_cache_logic toneRose
class node_supabase,node_providers toneIndigo
```

## Components

### Web experience

- [Chat interface](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/static/script.js): `static/script.js`
- [Web page](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/templates/index.html): `templates/index.html`

### API and identity

- [FastAPI routes](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/main.py): `main.py`
- [Bearer verification](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/authentication.py): `authentication.py`

### Document Q&A

- [PDF indexing](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`
- [PDF extraction](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`
- [Chunk and embed](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`
- [ChromaDB documents](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`
- [Per-document search](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`
- [Labeled context](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`
- [Configured LLM](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`
- [Answer and sources](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/rag.py): `rag.py`

### Answer cache

- [Cache lifecycle](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/main.py): `main.py`
- [Semantic cache](https://github.com/mitanshumakwana/pdf-chatbot-using-rag/blob/main/semantic_cache.py): `semantic_cache.py`

### Other components

- **Signed-in user**
- **Supabase Auth**
- **Ollama or Gemini**
- **Redis Search**

## Connections

- Signed-in user → Chat interface: uses (evidence: `README.md`)
- Chat interface → Web page: renders
- Chat interface → FastAPI routes: sends requests (evidence: `README.md`)
- Chat interface → Supabase Auth: authenticates (evidence: `static/script.js`)
- FastAPI routes → Bearer verification: requires user (evidence: `main.py`)
- Bearer verification → Supabase Auth: verifies token (evidence: `authentication.py`)
- FastAPI routes → PDF indexing: indexes PDF (evidence: `main.py`)
- PDF indexing → PDF extraction: extracts text (evidence: `README.md`)
- PDF extraction → Chunk and embed: splits and embeds (evidence: `README.md`)
- Chunk and embed → ChromaDB documents: stores chunks (evidence: `README.md`)
- FastAPI routes → Per-document search: queries documents (evidence: `main.py`)
- Per-document search → ChromaDB documents: searches chunks (evidence: `README.md`)
- Per-document search → Labeled context: labels results (evidence: `README.md`)
- Labeled context → Configured LLM: prompts model (evidence: `README.md`)
- Configured LLM → Ollama or Gemini: calls provider (evidence: `README.md`)
- Configured LLM → Answer and sources: generates answer (evidence: `README.md`)
- Answer and sources → Chat interface: returns sources (evidence: `README.md`)
- FastAPI routes → Cache lifecycle: starts and closes (evidence: `main.py`)
- Cache lifecycle → Semantic cache: creates cache (evidence: `main.py`)
- Semantic cache → Redis Search: reads and writes (evidence: `semantic_cache.py`)
- Per-document search → Semantic cache: looks up and stores answers (evidence: `README.md`)
- PDF indexing → Semantic cache: invalidates scope (evidence: `rag.py`)
