# ashutosh-6398/pdf-rag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/ashutosh-6398/pdf-rag-chatbot
- Repository: https://github.com/ashutosh-6398/pdf-rag-chatbot

## Overview

PDF RAG Chatbot supports PDF ingestion, persistent semantic indexing, and context-grounded question answering through both a browser/API workflow and the documented command-line workflow. Uploads and the CLI indexer share extraction, chunking, and embedding utilities; API and CLI question paths retrieve from ChromaDB before generating an answer with Hugging Face inference. The sampled sources support these calls; README capabilities also describe the indexing and retrieval stages.

Main entry points: [`backend/upload.py`](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/upload.py) (PDF upload processing), [`backend/rag.py`](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py) (API question retrieval), [`index.py`](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/index.py) (CLI indexer), [`utils.py`](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py) (Embedding utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_browser["Chat UI<br/>[script.js]"]
end

subgraph group_api["API workflows"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_upload["PDF upload processing<br/>[upload.py]"]
  node_api_rag["API question retrieval<br/>[rag.py]"]
  node_cli_index["CLI indexer<br/>[index.py]"]
  node_cli_chat["CLI chat<br/>[chat.py]"]
end

subgraph group_rag["RAG processing"]
  node_pdf["PDF text extraction<br/>[utils.py]"]
  node_chunks["Text chunking<br/>[utils.py]"]
  node_embedding["Embedding utilities<br/>[utils.py]"]
  node_retrieval["Similarity retrieval<br/>[rag.py]"]
  node_prompt["Context prompt<br/>[rag.py]"]
  node_generation["Answer generation<br/>[utils.py]"]
end

subgraph group_storage["Vector storage"]
  node_chroma[("Persistent vector store<br/>[rag.py]")]
end

node_user(("User"))
node_model["SentenceTransformer"]
node_hf["Hugging Face inference"]

node_user -->|"asks or uploads"| node_browser
node_browser -->|"sends requests"| node_api
node_api -->|"processes PDF"| node_upload
node_upload -->|"extracts text"| node_pdf
node_upload -->|"splits text"| node_chunks
node_upload -->|"embeds chunks"| node_embedding
node_embedding -->|"encodes text"| node_model
node_upload -->|"stores chunks"| node_chroma
node_api -->|"asks question"| node_api_rag
node_api_rag -->|"embeds query"| node_embedding
node_api_rag -->|"queries store"| node_retrieval
node_retrieval -->|"searches vectors"| node_chroma
node_api_rag -->|"builds context"| node_prompt
node_api_rag -->|"generates answer"| node_generation
node_generation -->|"requests completion"| node_hf
node_api -->|"returns answer"| node_browser
node_user -.->|"runs indexing"| node_cli_index
node_cli_index -->|"extracts text"| node_pdf
node_cli_index -->|"splits text"| node_chunks
node_cli_index -->|"embeds chunks"| node_embedding
node_cli_index -->|"stores vectors"| node_chroma
node_user -.->|"asks question"| node_cli_chat
node_cli_chat -->|"embeds query"| node_embedding
node_cli_chat -->|"searches vectors"| node_chroma
node_cli_chat -->|"generates answer"| node_generation

click node_browser "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/frontend/script.js"
click node_api "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/main.py"
click node_upload "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/upload.py"
click node_api_rag "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py"
click node_cli_index "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/index.py"
click node_cli_chat "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/chat.py"
click node_pdf "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py"
click node_chunks "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py"
click node_embedding "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py"
click node_retrieval "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py"
click node_prompt "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py"
click node_generation "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py"
click node_chroma "https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.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_user toneBlue
class node_api,node_upload,node_api_rag,node_cli_index,node_cli_chat toneAmber
class node_pdf,node_chunks,node_embedding,node_retrieval,node_prompt,node_generation toneMint
class node_chroma toneRose
class node_model,node_hf toneIndigo
```

## Components

### Web interface

- [Chat UI](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/frontend/script.js): `frontend/script.js`

### API workflows

- [FastAPI routes](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/main.py): `backend/main.py`
- [PDF upload processing](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/upload.py): `backend/upload.py`
- [API question retrieval](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py): `backend/rag.py`
- [CLI indexer](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/index.py): `index.py`
- [CLI chat](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/chat.py): `chat.py`

### RAG processing

- [PDF text extraction](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py): `utils.py`
- [Text chunking](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py): `utils.py`
- [Embedding utilities](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py): `utils.py`
- [Similarity retrieval](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py): `backend/rag.py`
- [Context prompt](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py): `backend/rag.py`
- [Answer generation](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/utils.py): `utils.py`

### Vector storage

- [Persistent vector store](https://github.com/ashutosh-6398/pdf-rag-chatbot/blob/main/backend/rag.py): `backend/rag.py`

### Other components

- **User**
- **SentenceTransformer**
- **Hugging Face inference**

## Connections

- User → Chat UI: asks or uploads
- Chat UI → FastAPI routes: sends requests
- FastAPI routes → PDF upload processing: processes PDF
- PDF upload processing → PDF text extraction: extracts text
- PDF upload processing → Text chunking: splits text
- PDF upload processing → Embedding utilities: embeds chunks
- Embedding utilities → SentenceTransformer: encodes text
- PDF upload processing → Persistent vector store: stores chunks
- FastAPI routes → API question retrieval: asks question
- API question retrieval → Embedding utilities: embeds query
- API question retrieval → Similarity retrieval: queries store
- Similarity retrieval → Persistent vector store: searches vectors
- API question retrieval → Context prompt: builds context
- API question retrieval → Answer generation: generates answer
- Answer generation → Hugging Face inference: requests completion
- FastAPI routes → Chat UI: returns answer
- User → CLI indexer: runs indexing
- CLI indexer → PDF text extraction: extracts text
- CLI indexer → Text chunking: splits text
- CLI indexer → Embedding utilities: embeds chunks
- CLI indexer → Persistent vector store: stores vectors
- User → CLI chat: asks question
- CLI chat → Embedding utilities: embeds query
- CLI chat → Persistent vector store: searches vectors
- CLI chat → Answer generation: generates answer
