# g-sri-harshit/ai-pdf-chatbot architecture

> Architecture diagram of the GitHub repository g-sri-harshit/ai-pdf-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/g-sri-harshit/ai-pdf-chatbot
- Repository: https://github.com/g-sri-harshit/ai-pdf-chatbot

## Overview

This is a PDF RAG chatbot with a Streamlit upload-and-question workflow and a separate command-line workflow. Documents are extracted into text, table rows, and OCR text; the app chunks applicable content, embeds it, stores vectors, retrieves context for a question, and asks a local Ollama model for an answer. The graph includes the documented OCR and table capabilities. Source excerpts show the main calls; the CLI workflow is represented from its excerpt, while external model services are shown only where their use is explicit.

Main entry points: [`app.py`](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/app.py) (Streamlit workflow), [`main.py`](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/main.py) (CLI workflow), [`pdf_reader.py`](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/pdf_reader.py) (PDF extraction), [`query.py`](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/query.py) (Prompt and response)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User workflows"]
  node_streamlit["Streamlit workflow<br/>[app.py]"]
  node_cli["CLI workflow<br/>[main.py]"]
end

subgraph group_document["PDF processing"]
  node_pdf["PDF extraction<br/>[pdf_reader.py]"]
  node_tables["Table extraction<br/>[pdf_reader.py]"]
  node_ocr["Image OCR<br/>[pdf_reader.py]"]
  node_chunking["Text chunking<br/>[chunking.py]"]
end

subgraph group_retrieval["Embedding and retrieval"]
  node_embedding["Text embeddings<br/>[embedding.py]"]
  node_vector[("Vector store<br/>[vector_store.py]")]
end

subgraph group_answers["Answer generation"]
  node_llm["Prompt and response<br/>[query.py]"]
end

node_user(("PDF user"))
node_ollama{{"Ollama service"}}

node_user -->|"uploads PDF"| node_streamlit
node_streamlit -->|"extracts content"| node_pdf
node_pdf -->|"extracts tables"| node_tables
node_pdf -->|"runs OCR"| node_ocr
node_streamlit -->|"chunks text"| node_chunking
node_streamlit -->|"embeds text"| node_embedding
node_streamlit -->|"adds vectors"| node_vector
node_streamlit -->|"embeds question"| node_embedding
node_streamlit -->|"searches vectors"| node_vector
node_streamlit -->|"requests answer"| node_llm
node_llm -->|"posts prompt"| node_ollama
node_cli -->|"extracts content"| node_pdf
node_cli -->|"chunks text"| node_chunking
node_cli -->|"embeds text"| node_embedding
node_cli -->|"adds and searches"| node_vector
node_cli -->|"requests answer"| node_llm

click node_streamlit "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/app.py"
click node_cli "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/main.py"
click node_pdf "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/pdf_reader.py"
click node_tables "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/pdf_reader.py"
click node_ocr "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/pdf_reader.py"
click node_chunking "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/chunking.py"
click node_embedding "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/embedding.py"
click node_vector "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/vector_store.py"
click node_llm "https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/query.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_streamlit,node_cli,node_user toneBlue
class node_pdf,node_tables,node_ocr,node_chunking toneAmber
class node_embedding,node_vector toneMint
class node_llm toneRose
class node_ollama toneIndigo
```

## Components

### User workflows

- [Streamlit workflow](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/app.py): `app.py`
- [CLI workflow](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/main.py): `main.py`

### PDF processing

- [PDF extraction](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/pdf_reader.py): `pdf_reader.py`
- [Table extraction](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/pdf_reader.py): `pdf_reader.py`
- [Image OCR](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/pdf_reader.py): `pdf_reader.py`
- [Text chunking](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/chunking.py): `chunking.py`

### Embedding and retrieval

- [Text embeddings](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/embedding.py): `embedding.py`
- [Vector store](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/vector_store.py): `vector_store.py`

### Answer generation

- [Prompt and response](https://github.com/g-sri-harshit/ai-pdf-chatbot/blob/main/query.py): `query.py`

### Other components

- **PDF user**
- **Ollama service**

## Connections

- PDF user → Streamlit workflow: uploads PDF (evidence: `README.md`)
- Streamlit workflow → PDF extraction: extracts content (evidence: `app.py`)
- PDF extraction → Table extraction: extracts tables (evidence: `pdf_reader.py`)
- PDF extraction → Image OCR: runs OCR (evidence: `pdf_reader.py`)
- Streamlit workflow → Text chunking: chunks text (evidence: `app.py`)
- Streamlit workflow → Text embeddings: embeds text (evidence: `app.py`)
- Streamlit workflow → Vector store: adds vectors (evidence: `app.py`)
- Streamlit workflow → Text embeddings: embeds question (evidence: `app.py`)
- Streamlit workflow → Vector store: searches vectors (evidence: `app.py`)
- Streamlit workflow → Prompt and response: requests answer (evidence: `app.py`)
- Prompt and response → Ollama service: posts prompt (evidence: `query.py`)
- CLI workflow → PDF extraction: extracts content (evidence: `main.py`)
- CLI workflow → Text chunking: chunks text (evidence: `main.py`)
- CLI workflow → Text embeddings: embeds text (evidence: `main.py`)
- CLI workflow → Vector store: adds and searches (evidence: `main.py`)
- CLI workflow → Prompt and response: requests answer (evidence: `main.py`)
