# hnib1908/chatpdf-modern architecture

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

- Interactive diagram: https://gitdiagram.com/hnib1908/chatpdf-modern
- Repository: https://github.com/hnib1908/chatpdf-modern

## Overview

Chat PDF is a local-first Streamlit RAG application. A user uploads PDFs, chooses extraction and chunking settings, indexes the document, selects it, asks a question, and receives a streamed or complete LLM answer with cited chunks. The main stages are ingestion, persistent vector storage, hybrid retrieval/re-ranking, prompt-based generation, and conversation persistence. The sampled code clearly shows Ollama and optional Sambanova generation; some surrounding app wiring is omitted, so only supported relationships are shown.

Main entry points: [`app.py`](https://github.com/hnib1908/chatpdf-modern/blob/main/app.py) (Streamlit App), [`rag_core/rag.py`](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py) (RAG System), [`app_services/ingest_service.py`](https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/ingest_service.py) (Ingest Service), [`rag_core/llm_inference.py`](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/llm_inference.py) (LLM Inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_streamlit_app["Streamlit App<br/>[app.py]"]
  node_ui_components["Chat UI<br/>[components.py]"]
  node_theme["Theme UI<br/>[theme.py]"]
  node_citation_view["Citation View<br/>[components.py]"]
end

subgraph group_ingestion["Document Ingestion"]
  node_ingest_service["Ingest Service<br/>[ingest_service.py]"]
  node_pdf_processing["PDF Processing<br/>[ingest_service.py]"]
  node_markdown_converter["Markdown Converter<br/>[md_convertor.py]"]
  node_embedding_model["Embedding Model"]
  node_vector_store[("Chroma Vector Store<br/>[ingest_service.py]")]
end

subgraph group_retrieval["RAG Retrieval"]
  node_rag_system["RAG System<br/>[rag.py]"]
  node_retriever["Vector Retriever<br/>[rag.py]"]
  node_reranker["Hybrid Re-ranker<br/>[rag.py]"]
  node_prompt_builder["Prompt Builder<br/>[rag.py]"]
  node_llm_inference["LLM Inference<br/>[llm_inference.py]"]
end

subgraph group_conversation["Conversation Services"]
  node_history_service["History Service<br/>[history_service.py]"]
  node_history_db[("Chat History DB<br/>[history_service.py]")]
end

node_user(("PDF User"))
node_ollama["Ollama Runtime"]
node_sambanova["Sambanova API"]

node_user -->|"uploads and asks"| node_streamlit_app
node_streamlit_app -->|"indexes PDFs"| node_ingest_service
node_ingest_service -->|"extracts text"| node_pdf_processing
node_ingest_service -->|"converts advanced"| node_markdown_converter
node_ingest_service -->|"embeds chunks"| node_embedding_model
node_embedding_model -->|"runs embeddings"| node_ollama
node_ingest_service -->|"writes chunks"| node_vector_store
node_streamlit_app -->|"injects theme"| node_theme
node_streamlit_app -->|"renders controls"| node_ui_components
node_streamlit_app -->|"submits query"| node_rag_system
node_rag_system -->|"retrieves chunks"| node_retriever
node_retriever -->|"queries vectors"| node_vector_store
node_rag_system -->|"creates query embedding"| node_llm_inference
node_llm_inference -->|"embeds query"| node_ollama
node_rag_system -->|"reranks chunks"| node_reranker
node_rag_system -->|"builds prompt"| node_prompt_builder
node_rag_system -->|"generates answer"| node_llm_inference
node_llm_inference -->|"generates or streams"| node_ollama
node_llm_inference -.->|"generates answer"| node_sambanova
node_rag_system -->|"returns answer and sources"| node_streamlit_app
node_streamlit_app -->|"renders citations"| node_citation_view
node_streamlit_app -->|"loads and saves chats"| node_history_service
node_history_service -->|"reads and writes"| node_history_db

click node_streamlit_app "https://github.com/hnib1908/chatpdf-modern/blob/main/app.py"
click node_ui_components "https://github.com/hnib1908/chatpdf-modern/blob/main/ui/components.py"
click node_theme "https://github.com/hnib1908/chatpdf-modern/blob/main/ui/theme.py"
click node_ingest_service "https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/ingest_service.py"
click node_pdf_processing "https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/ingest_service.py"
click node_markdown_converter "https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/md_convertor.py"
click node_vector_store "https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/ingest_service.py"
click node_rag_system "https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py"
click node_retriever "https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py"
click node_reranker "https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py"
click node_prompt_builder "https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py"
click node_llm_inference "https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/llm_inference.py"
click node_citation_view "https://github.com/hnib1908/chatpdf-modern/blob/main/ui/components.py"
click node_history_service "https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/history_service.py"
click node_history_db "https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/history_service.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_app,node_ui_components,node_theme,node_citation_view,node_user toneBlue
class node_ingest_service,node_pdf_processing,node_markdown_converter,node_embedding_model,node_vector_store toneAmber
class node_rag_system,node_retriever,node_reranker,node_prompt_builder,node_llm_inference,node_sambanova toneMint
class node_history_service,node_history_db toneRose
class node_ollama toneIndigo
```

## Components

### User Interface

- [Streamlit App](https://github.com/hnib1908/chatpdf-modern/blob/main/app.py): `app.py`
- [Chat UI](https://github.com/hnib1908/chatpdf-modern/blob/main/ui/components.py): `ui/components.py`
- [Theme UI](https://github.com/hnib1908/chatpdf-modern/blob/main/ui/theme.py): `ui/theme.py`
- [Citation View](https://github.com/hnib1908/chatpdf-modern/blob/main/ui/components.py): `ui/components.py`

### Document Ingestion

- [Ingest Service](https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/ingest_service.py): `app_services/ingest_service.py`
- [PDF Processing](https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/ingest_service.py): `app_services/ingest_service.py`
- [Markdown Converter](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/md_convertor.py): `rag_core/md_convertor.py`
- **Embedding Model**
- [Chroma Vector Store](https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/ingest_service.py): `app_services/ingest_service.py`

### RAG Retrieval

- [RAG System](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py): `rag_core/rag.py`
- [Vector Retriever](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py): `rag_core/rag.py`
- [Hybrid Re-ranker](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py): `rag_core/rag.py`
- [Prompt Builder](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/rag.py): `rag_core/rag.py`
- [LLM Inference](https://github.com/hnib1908/chatpdf-modern/blob/main/rag_core/llm_inference.py): `rag_core/llm_inference.py`

### Conversation Services

- [History Service](https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/history_service.py): `app_services/history_service.py`
- [Chat History DB](https://github.com/hnib1908/chatpdf-modern/blob/main/app_services/history_service.py): `app_services/history_service.py`

### Other components

- **PDF User**
- **Ollama Runtime**
- **Sambanova API**

## Connections

- PDF User → Streamlit App: uploads and asks
- Streamlit App → Ingest Service: indexes PDFs
- Ingest Service → PDF Processing: extracts text
- Ingest Service → Markdown Converter: converts advanced
- Ingest Service → Embedding Model: embeds chunks
- Embedding Model → Ollama Runtime: runs embeddings
- Ingest Service → Chroma Vector Store: writes chunks
- Streamlit App → Theme UI: injects theme
- Streamlit App → Chat UI: renders controls
- Streamlit App → RAG System: submits query
- RAG System → Vector Retriever: retrieves chunks
- Vector Retriever → Chroma Vector Store: queries vectors
- RAG System → LLM Inference: creates query embedding
- LLM Inference → Ollama Runtime: embeds query
- RAG System → Hybrid Re-ranker: reranks chunks
- RAG System → Prompt Builder: builds prompt
- RAG System → LLM Inference: generates answer
- LLM Inference → Ollama Runtime: generates or streams
- LLM Inference → Sambanova API: generates answer
- RAG System → Streamlit App: returns answer and sources
- Streamlit App → Citation View: renders citations
- Streamlit App → History Service: loads and saves chats
- History Service → Chat History DB: reads and writes
