# krishna-118/document_reader architecture

> Architecture diagram of the GitHub repository krishna-118/document_reader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishna-118/document_reader
- Repository: https://github.com/krishna-118/document_reader

## Overview

This is a Streamlit academic textbook assistant: users upload PDFs, process them into a searchable vector store, then ask questions answered from retrieved textbook context. PDF extraction, chunking, embedding, and indexing form the ingestion stage; query handling uses chat history, retrieval, and a context-constrained answer chain before displaying the answer and source metadata. The graph reflects the shown calls; framework-internal behavior is represented only where the app configures or invokes it.

Main entry points: [`app.py`](https://github.com/krishna-118/document_reader/blob/main/app.py) (Query Orchestration), [`utils.py`](https://github.com/krishna-118/document_reader/blob/main/utils.py) (PDF Processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_ui["Streamlit App<br/>[app.py]"]
  node_answer_sources["Answer and Sources<br/>[app.py]"]
end

subgraph group_ingestion["PDF Ingestion"]
  node_pdf_processing["PDF Processing<br/>[utils.py]"]
  node_pdf_loader["PDF Loader<br/>[utils.py]"]
  node_text_splitter["Text Splitter<br/>[utils.py]"]
  node_embeddings["Text Embeddings<br/>[utils.py]"]
  node_vector_store[("FAISS Index<br/>[utils.py]")]
end

subgraph group_qa["Question Answering"]
  node_query_flow["Query Orchestration<br/>[app.py]"]
  node_chat_history["Chat History<br/>[app.py]"]
  node_retriever["History-Aware Retriever<br/>[app.py]"]
  node_qa_chain["Answer Chain<br/>[app.py]"]
end

node_user(("User"))
node_groq["Groq LLM"]

node_user -->|"uploads or asks"| node_ui
node_ui -->|"calls processing"| node_pdf_processing
node_pdf_processing -->|"loads PDFs"| node_pdf_loader
node_pdf_processing -->|"splits documents"| node_text_splitter
node_pdf_processing -->|"creates embeddings"| node_embeddings
node_pdf_processing -->|"indexes chunks"| node_vector_store
node_ui -->|"handles query"| node_query_flow
node_query_flow -->|"reads and updates"| node_chat_history
node_query_flow -->|"creates retriever"| node_vector_store
node_query_flow -->|"configures and invokes"| node_retriever
node_query_flow -->|"configures and invokes"| node_qa_chain
node_query_flow -->|"configures model"| node_groq
node_query_flow -->|"displays result"| node_answer_sources
node_retriever -->|"supplies context"| node_qa_chain

click node_ui "https://github.com/krishna-118/document_reader/blob/main/app.py"
click node_pdf_processing "https://github.com/krishna-118/document_reader/blob/main/utils.py"
click node_pdf_loader "https://github.com/krishna-118/document_reader/blob/main/utils.py"
click node_text_splitter "https://github.com/krishna-118/document_reader/blob/main/utils.py"
click node_embeddings "https://github.com/krishna-118/document_reader/blob/main/utils.py"
click node_vector_store "https://github.com/krishna-118/document_reader/blob/main/utils.py"
click node_query_flow "https://github.com/krishna-118/document_reader/blob/main/app.py"
click node_chat_history "https://github.com/krishna-118/document_reader/blob/main/app.py"
click node_retriever "https://github.com/krishna-118/document_reader/blob/main/app.py"
click node_qa_chain "https://github.com/krishna-118/document_reader/blob/main/app.py"
click node_answer_sources "https://github.com/krishna-118/document_reader/blob/main/app.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_ui,node_answer_sources,node_user toneBlue
class node_pdf_processing,node_pdf_loader,node_text_splitter,node_embeddings,node_vector_store toneAmber
class node_query_flow,node_chat_history,node_retriever,node_qa_chain toneMint
class node_groq toneIndigo
```

## Components

### User Interface

- [Streamlit App](https://github.com/krishna-118/document_reader/blob/main/app.py): `app.py`
- [Answer and Sources](https://github.com/krishna-118/document_reader/blob/main/app.py): `app.py`

### PDF Ingestion

- [PDF Processing](https://github.com/krishna-118/document_reader/blob/main/utils.py): `utils.py`
- [PDF Loader](https://github.com/krishna-118/document_reader/blob/main/utils.py): `utils.py`
- [Text Splitter](https://github.com/krishna-118/document_reader/blob/main/utils.py): `utils.py`
- [Text Embeddings](https://github.com/krishna-118/document_reader/blob/main/utils.py): `utils.py`
- [FAISS Index](https://github.com/krishna-118/document_reader/blob/main/utils.py): `utils.py`

### Question Answering

- [Query Orchestration](https://github.com/krishna-118/document_reader/blob/main/app.py): `app.py`
- [Chat History](https://github.com/krishna-118/document_reader/blob/main/app.py): `app.py`
- [History-Aware Retriever](https://github.com/krishna-118/document_reader/blob/main/app.py): `app.py`
- [Answer Chain](https://github.com/krishna-118/document_reader/blob/main/app.py): `app.py`

### Other components

- **User**
- **Groq LLM**

## Connections

- User → Streamlit App: uploads or asks (evidence: `app.py`)
- Streamlit App → PDF Processing: calls processing (evidence: `app.py`)
- PDF Processing → PDF Loader: loads PDFs (evidence: `utils.py`)
- PDF Processing → Text Splitter: splits documents (evidence: `utils.py`)
- PDF Processing → Text Embeddings: creates embeddings (evidence: `utils.py`)
- PDF Processing → FAISS Index: indexes chunks (evidence: `utils.py`)
- Streamlit App → Query Orchestration: handles query (evidence: `app.py`)
- Query Orchestration → Chat History: reads and updates (evidence: `app.py`)
- Query Orchestration → FAISS Index: creates retriever (evidence: `app.py`)
- Query Orchestration → History-Aware Retriever: configures and invokes (evidence: `app.py`)
- Query Orchestration → Answer Chain: configures and invokes (evidence: `app.py`)
- Query Orchestration → Groq LLM: configures model (evidence: `app.py`)
- Query Orchestration → Answer and Sources: displays result (evidence: `app.py`)
- History-Aware Retriever → Answer Chain: supplies context (evidence: `app.py`)
