# pranavkombra/pdfragsystem architecture

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

- Interactive diagram: https://gitdiagram.com/pranavkombra/pdfragsystem
- Repository: https://github.com/pranavkombra/pdfragsystem

## Overview

#### Purpose and Entry Points
This repository is a Streamlit-based PDF question-answering system using retrieval-augmented generation (RAG). Users upload multiple PDFs, ask natural-language questions, and receive GPT-generated answers grounded in retrieved document chunks.

Primary entry point: `app.py`. A duplicate project directory, `ChatPDF-main/`, contains a parallel copy with its own `ChatPDF-main/app.py`.

#### Application UI and Session Control
The Streamlit application owns the interactive lifecycle: PDF upload, document-processing trigger, chat input, answer display, and conversational state. Streamlit session state is the likely boundary for retaining the RAG conversation chain between user turns.

Paths:
- `app.py`
- `ChatPDF-main/app.py`

#### PDF Ingestion and Text Extraction
Uploaded PDFs are accepted as a batch and transformed into extractable text before indexing. This ingestion stage is the boundary between unstructured user files and the retrieval pipeline; source PDFs are processed in-memory/application scope rather than represented by a separate storage subsystem in the repository.

Paths:
- `app.py`
- `ChatPDF-main/app.py`

#### Chunking, Embeddings, and Vector Retrieval
Extracted PDF text is split into retrieval-sized chunks, embedded with Hugging Face’s `all-MiniLM-L6-v2` model, and indexed in FAISS. At query time, the user’s question is embedded and used to retrieve relevant chunks from this vector store.

This is the repository’s core RAG knowledge boundary: PDFs become local vector representations rather than being sent wholesale to the generator.

Paths:
- `app.py`
- `ChatPDF-main/app.py`

#### Conversational RAG Generation
Retrieved context and accumulated conversation history are passed to a conversational retrieval chain. The chain uses conversation-buffer memory so follow-up questions can reference prior turns, then invokes OpenAI GPT-3.5 Turbo to generate the final response.

External service boundary:
- OpenAI API for GPT-3.5 Turbo generation
- Hugging Face embedding model for vector creation

Paths:
- `app.py`
- `ChatPDF-main/app.py`

#### Chat Presentation Layer
The UI renders user and assistant messages using reusable HTML/CSS template strings. This keeps chat formatting separate from the Streamlit orchestration and RAG pipeline.

Paths:
- `htmlTemplates.py`
- `ChatPDF-main/htmlTemplates.py`

#### Runtime and Dependencies
The system runs as a Python Streamlit process, launched with `streamlit run app.py`. Its material runtime dependencies include Streamlit, PDF parsing, LangChain-style RAG orchestration, FAISS vector search, Hugging Face embeddings, and OpenAI client access.

Paths:
- `requirements.txt`
- `ChatPDF-main/requirements.txt`
- `app.py`

Main entry points: [`app.py`](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py) (Conversational retrieval chain), [`requirements.txt`](https://github.com/pranavkombra/pdfragsystem/blob/main/requirements.txt) (Python dependencies), [`htmlTemplates.py`](https://github.com/pranavkombra/pdfragsystem/blob/main/htmlTemplates.py) (Chat templates), [`ChatPDF-main/app.py`](https://github.com/pranavkombra/pdfragsystem/blob/main/ChatPDF-main/app.py) (Duplicate Streamlit app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_primary["Primary Streamlit app"]
  node_requirements["Python dependencies<br/>runtime manifest<br/>[requirements.txt]"]
  node_app["Streamlit application<br/>Python entry point<br/>[app.py]"]
  node_ui["Upload and chat UI<br/>Streamlit UI<br/>[app.py]"]
  node_templates["Chat templates<br/>HTML/CSS templates<br/>[htmlTemplates.py]"]
  node_session["Conversation state<br/>Streamlit session state<br/>[app.py]"]
  node_pdf_ingestion["PDF text extraction<br/>ingestion stage<br/>[app.py]"]
  node_chunking["Text chunking<br/>retrieval preparation<br/>[app.py]"]
  node_embeddings{{"Hugging Face embeddings<br/>embedding model<br/>[app.py]"}}
  node_faiss[("FAISS vector index<br/>local vector store<br/>[app.py]")]
  node_rag_chain["Conversational retrieval chain<br/>RAG orchestration<br/>[app.py]"]
  node_memory["Conversation buffer<br/>chain memory<br/>[app.py]"]
end

subgraph group_duplicate["Parallel copy"]
  node_duplicate_app["Duplicate Streamlit app<br/>parallel entry point<br/>[app.py]"]
  node_duplicate_templates["Duplicate chat templates<br/>HTML/CSS templates<br/>[htmlTemplates.py]"]
  node_duplicate_requirements["Duplicate dependencies<br/>runtime manifest<br/>[requirements.txt]"]
end

node_openai{{"OpenAI GPT-3.5 Turbo<br/>external generation API"}}

node_requirements -->|"provides runtime"| node_app
node_app -->|"renders"| node_ui
node_ui -->|"uploads PDFs"| node_pdf_ingestion
node_pdf_ingestion -->|"extracts text"| node_chunking
node_chunking -->|"embeds chunks"| node_embeddings
node_embeddings -->|"indexes vectors"| node_faiss
node_ui -->|"submits question"| node_rag_chain
node_rag_chain -->|"embeds query"| node_embeddings
node_faiss -->|"retrieved chunks"| node_rag_chain
node_session -->|"retains chain"| node_rag_chain
node_memory -->|"conversation history"| node_rag_chain
node_rag_chain -->|"records turns"| node_memory
node_rag_chain -->|"generates answer"| node_openai
node_openai -->|"answer"| node_ui
node_templates -->|"formats messages"| node_ui
node_duplicate_app -.->|"parallel copy"| node_app
node_duplicate_templates -.->|"parallel copy"| node_templates
node_duplicate_requirements -.->|"parallel copy"| node_requirements

click node_requirements "https://github.com/pranavkombra/pdfragsystem/blob/main/requirements.txt"
click node_app "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_ui "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_templates "https://github.com/pranavkombra/pdfragsystem/blob/main/htmlTemplates.py"
click node_session "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_pdf_ingestion "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_chunking "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_embeddings "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_faiss "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_rag_chain "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_memory "https://github.com/pranavkombra/pdfragsystem/blob/main/app.py"
click node_duplicate_app "https://github.com/pranavkombra/pdfragsystem/blob/main/ChatPDF-main/app.py"
click node_duplicate_templates "https://github.com/pranavkombra/pdfragsystem/blob/main/ChatPDF-main/htmlTemplates.py"
click node_duplicate_requirements "https://github.com/pranavkombra/pdfragsystem/blob/main/ChatPDF-main/requirements.txt"

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_requirements,node_app,node_ui,node_templates,node_session,node_pdf_ingestion,node_chunking,node_embeddings,node_faiss,node_rag_chain,node_memory toneBlue
class node_duplicate_app,node_duplicate_templates,node_duplicate_requirements toneAmber
class node_openai toneNeutral
```

## Components

### Primary Streamlit app

- [Python dependencies](https://github.com/pranavkombra/pdfragsystem/blob/main/requirements.txt): runtime manifest · `requirements.txt`
- [Streamlit application](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): Python entry point · Launched with streamlit run app.py. · `app.py`
- [Upload and chat UI](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): Streamlit UI · Owns upload, processing trigger, chat input, and answer display. · `app.py`
- [Chat templates](https://github.com/pranavkombra/pdfragsystem/blob/main/htmlTemplates.py): HTML/CSS templates · Reusable user and assistant message formatting. · `htmlTemplates.py`
- [Conversation state](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): Streamlit session state · Retains the RAG chain between user turns. · `app.py`
- [PDF text extraction](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): ingestion stage · Processes uploaded PDF batches in application memory. · `app.py`
- [Text chunking](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): retrieval preparation · `app.py`
- [Hugging Face embeddings](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): embedding model · Uses all-MiniLM-L6-v2 for document and question vectors. · `app.py`
- [FAISS vector index](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): local vector store · Stores chunk embeddings and returns relevant chunks. · `app.py`
- [Conversational retrieval chain](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): RAG orchestration · Combines retrieved context with conversation history. · `app.py`
- [Conversation buffer](https://github.com/pranavkombra/pdfragsystem/blob/main/app.py): chain memory · Provides prior turns for follow-up questions. · `app.py`

### Parallel copy

- [Duplicate Streamlit app](https://github.com/pranavkombra/pdfragsystem/blob/main/ChatPDF-main/app.py): parallel entry point · Parallel copy of the primary application architecture. · `ChatPDF-main/app.py`
- [Duplicate chat templates](https://github.com/pranavkombra/pdfragsystem/blob/main/ChatPDF-main/htmlTemplates.py): HTML/CSS templates · `ChatPDF-main/htmlTemplates.py`
- [Duplicate dependencies](https://github.com/pranavkombra/pdfragsystem/blob/main/ChatPDF-main/requirements.txt): runtime manifest · `ChatPDF-main/requirements.txt`

### Other components

- **OpenAI GPT-3.5 Turbo**: external generation API

## Connections

- Python dependencies → Streamlit application: provides runtime
- Streamlit application → Upload and chat UI: renders
- Upload and chat UI → PDF text extraction: uploads PDFs
- PDF text extraction → Text chunking: extracts text
- Text chunking → Hugging Face embeddings: embeds chunks
- Hugging Face embeddings → FAISS vector index: indexes vectors
- Upload and chat UI → Conversational retrieval chain: submits question
- Conversational retrieval chain → Hugging Face embeddings: embeds query
- FAISS vector index → Conversational retrieval chain: retrieved chunks
- Conversation state → Conversational retrieval chain: retains chain
- Conversation buffer → Conversational retrieval chain: conversation history
- Conversational retrieval chain → Conversation buffer: records turns
- Conversational retrieval chain → OpenAI GPT-3.5 Turbo: generates answer
- OpenAI GPT-3.5 Turbo → Upload and chat UI: answer
- Chat templates → Upload and chat UI: formats messages
- Duplicate Streamlit app → Streamlit application: parallel copy
- Duplicate chat templates → Chat templates: parallel copy
- Duplicate dependencies → Python dependencies: parallel copy
