# kalyanm45/docgenius-revolutionizing-pdfs-with-ai architecture

> Architecture diagram of the GitHub repository kalyanm45/docgenius-revolutionizing-pdfs-with-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai
- Repository: https://github.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai

## Overview

1. **Project shape**
   - This repository is a small Python, single-user PDF question-answering app.
   - The runtime entrypoint is `app.py`, which is launched with Streamlit.
   - Most of the document-QA logic appears to live in `DocGenius/PDFChat.py`, with `app.py` acting as the UI and orchestration layer.

2. **User interface boundary**
   - The visible application is the Streamlit interface.
   - Its job is to accept a PDF upload, collect a natural-language question, and display the answer.
   - The UI does not appear to own the document intelligence itself; it likely delegates that to the PDF chat module.

3. **Document ingestion subsystem**
   - PDF content is read from the uploaded file using `PyPDF2`.
   - The README describes a flow where the PDF text is extracted and then split into smaller chunks.
   - This ingestion stage is the first boundary between raw user input and searchable text data.

4. **Text preparation and chunking**
   - The application breaks the PDF text into chunks before sending anything to the model.
   - `tiktoken` is listed, which strongly suggests token-aware chunk sizing to stay within model limits.
   - This is an important architecture step because it shapes both retrieval quality and LLM prompt size.

5. **Embedding and vector indexing**
   - The repo uses OpenAI embeddings to convert text chunks into vector representations.
   - `faiss-cpu` is used as the local vector index for semantic search over those embeddings.
   - This creates a clear retrieval layer: raw PDF text is transformed into searchable vectors, separate from the UI and the final answer generation.

6. **Question answering flow**
   - When a user asks a question, the app embeds that question and searches the vector index for the most semantically similar chunks.
   - Only those retrieved chunks are forwarded to the LLM as context.
   - The README explicitly says the model is constrained to answer from the document, so retrieval is a gating mechanism, not just a convenience.

7. **LLM orchestration**
   - The LLM generates the final answer from the retrieved PDF chunks plus the user question.
   - The architecture is retrieval-augmented generation rather than direct free-form chat.
   - This means the system is dependent on both the vector search quality and the prompt/context assembly in the PDF chat logic.

8. **Main internal module boundary**
   - `DocGenius/PDFChat.py` is likely the core service module that encapsulates PDF loading, chunking, embedding, retrieval, and response generation.
   - `app.py` likely imports and calls into that module rather than implementing the full pipeline inline.
   - That separation matters for the diagram: UI at the top, document-processing engine below it.

9. **Configuration and secrets**
   - OpenAI access is configured through a `.env` file via `python-dotenv`.
   - The API key is an external dependency boundary, not hardcoded into the app.
   - This is the main runtime configuration hook and should be shown outside the core code path.

10. **Runtime dependencies that affect architecture**
   - `streamlit` defines the interaction model and makes the app a local interactive tool rather than a backend service.
   - `langchain` likely provides helper abstractions for chaining, prompting, or document handling, even if the core pattern is still RAG.
   - `faiss-cpu` means the vector search runs locally in-process or on the local machine, not via a managed vector database.

11. **Data flow summary**
   - The end-to-end flow is: user uploads PDF → text extraction → chunking → embeddings → FAISS index → question embedding → similarity search → selected chunks + question → LLM → answer displayed in Streamlit.
   - The data path is one-way from document ingestion into retrieval, then into generation.
   - There is no sign of persistent knowledge storage or long-term conversation memory in the repository structure.

12. **Artifacts and non-runtime assets**
   - The `Artifacts/` directory appears to store screenshots and image resources used for documentation or proof-of-concept presentation.
   - These assets are not part of the core execution path.
   - They are useful for understanding the intended UI/UX but should be excluded from the runtime architecture diagram.

13. **Overall architecture pattern**
   - This is a lightweight retrieval-augmented PDF chat application with three main layers: Streamlit UI, document processing/retrieval engine, and OpenAI-backed generation.
   - The system is local-first and single-process, with external dependence only on OpenAI services for embeddings and answer generation.
   - The key architectural boundary is between user-facing interaction and the internal semantic search/LLM pipeline.

Main entry points: [`DocGenius/PDFChat.py`](https://github.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai/blob/main/DocGenius/PDFChat.py) (PDF chat), [`app.py`](https://github.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai/blob/main/app.py) (Streamlit app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI"]
  node_app["Streamlit app<br/>entrypoint<br/>[app.py]"]
  node_upload["PDF upload<br/>input boundary"]
  node_question["User question<br/>input boundary"]
  node_answer["Rendered answer<br/>output"]
end

subgraph group_engine["PDF engine"]
  node_pdfchat["PDF chat<br/>core module<br/>[PDFChat.py]"]
  node_extract["Text extraction<br/>ingestion"]
  node_chunk["Chunking<br/>preprocessing"]
  node_embed_docs(("Doc embeddings<br/>vectorization"))
  node_index[("FAISS index<br/>vector search")]
  node_embed_q(("Query embedding<br/>vectorization"))
  node_retrieve["Similarity search<br/>retrieval"]
  node_prompt["Context assembly<br/>prompting"]
  node_generate{{"LLM answer<br/>generation"}}
end

subgraph group_deps["Dependencies"]
  node_streamlit["Streamlit<br/>ui framework"]
  node_pypdf2["PyPDF2<br/>pdf parser"]
  node_tiktoken["tiktoken<br/>tokenizer"]
  node_langchain["LangChain<br/>llm toolkit"]
  node_openai(("OpenAI API<br/>model service"))
  node_dotenv[".env config<br/>runtime config"]
end

node_app -->|"accepts"| node_upload
node_app -->|"collects"| node_question
node_app -->|"delegates"| node_pdfchat
node_upload -->|"ingests"| node_extract
node_extract -->|"uses"| node_pypdf2
node_extract -->|"feeds"| node_chunk
node_chunk -->|"sizes"| node_tiktoken
node_chunk -->|"prepares"| node_embed_docs
node_embed_docs -->|"embeds"| node_openai
node_embed_docs -->|"stores"| node_index
node_index -->|"queries"| node_retrieve
node_question -->|"embeds"| node_embed_q
node_embed_q -->|"embeds"| node_openai
node_embed_q -->|"searches"| node_retrieve
node_retrieve -->|"selects"| node_prompt
node_prompt -->|"feeds"| node_generate
node_generate -->|"calls"| node_openai
node_generate -->|"returns"| node_answer
node_pdfchat -->|"orchestrates"| node_extract
node_pdfchat -->|"orchestrates"| node_retrieve
node_pdfchat -->|"orchestrates"| node_generate
node_app -->|"runs on"| node_streamlit
node_pdfchat -.->|"leverages"| node_langchain
node_dotenv -.->|"configures"| node_app

click node_app "https://github.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai/blob/main/app.py"
click node_pdfchat "https://github.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai/blob/main/DocGenius/PDFChat.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_app,node_upload,node_question,node_answer toneBlue
class node_pdfchat,node_extract,node_chunk,node_embed_docs,node_index,node_embed_q,node_retrieve,node_prompt,node_generate toneAmber
class node_streamlit,node_pypdf2,node_tiktoken,node_langchain,node_openai,node_dotenv toneMint
```

## Components

### UI

Streamlit entrypoint and user interaction layer

- [Streamlit app](https://github.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai/blob/main/app.py): entrypoint · Launches the interactive PDF Q&A UI and orchestrates user flow · `app.py`
- **PDF upload**: input boundary · Uploaded document enters the application through the UI
- **User question**: input boundary · Natural-language query provided by the user
- **Rendered answer**: output · Final response shown back in the Streamlit interface

### PDF engine

Document ingestion, retrieval, and answer generation

- [PDF chat](https://github.com/kalyanm45/docgenius-revolutionizing-pdfs-with-ai/blob/main/DocGenius/PDFChat.py): core module · Central document-QA pipeline for loading, indexing, retrieving, and answering · `DocGenius/PDFChat.py`
- **Text extraction**: ingestion · Reads PDF content from the uploaded file
- **Chunking**: preprocessing · Splits extracted text into token-aware chunks
- **Doc embeddings**: vectorization · Converts text chunks into vector representations
- **FAISS index**: vector search · Local semantic index over embedded chunks
- **Query embedding**: vectorization · Embeds the user question for retrieval
- **Similarity search**: retrieval · Finds the most relevant document chunks for the question
- **Context assembly**: prompting · Combines retrieved chunks with the question for the model
- **LLM answer**: generation · Produces the final answer using document-grounded context

### Dependencies

External libraries and runtime services

- **Streamlit**: ui framework · Interactive local web UI runtime
- **PyPDF2**: pdf parser · Library used to read and extract text from PDFs
- **tiktoken**: tokenizer · Token-aware sizing for chunking and prompt limits
- **LangChain**: llm toolkit · Helper abstractions for chaining and document orchestration
- **OpenAI API**: model service · External embeddings and answer generation backend
- **.env config**: runtime config · Loads API credentials and local configuration

## Connections

- Streamlit app → PDF upload: accepts · The UI receives the uploaded PDF from the user
- Streamlit app → User question: collects · The UI captures the user's question
- Streamlit app → PDF chat: delegates · The Streamlit layer calls into the PDF chat engine
- PDF upload → Text extraction: ingests · Uploaded PDF becomes extracted text
- Text extraction → PyPDF2: uses · PDF parsing is handled by PyPDF2
- Text extraction → Chunking: feeds · Extracted text is prepared for chunking
- Chunking → tiktoken: sizes · Chunking is guided by token limits
- Chunking → Doc embeddings: prepares · Text chunks are converted into vectors
- Doc embeddings → OpenAI API: embeds · OpenAI embeddings create document vectors
- Doc embeddings → FAISS index: stores · Chunk vectors are added to the local index
- FAISS index → Similarity search: queries · Similarity search runs against the FAISS index
- User question → Query embedding: embeds · The user question is vectorized for retrieval
- Query embedding → OpenAI API: embeds · OpenAI embeddings create the query vector
- Query embedding → Similarity search: searches · Query vector drives semantic retrieval
- Similarity search → Context assembly: selects · Relevant chunks are assembled into model context
- Context assembly → LLM answer: feeds · Context plus question are passed to the LLM
- LLM answer → OpenAI API: calls · OpenAI produces the grounded final answer
- LLM answer → Rendered answer: returns · Answer is sent back to the UI for display
- PDF chat → Text extraction: orchestrates · Core module coordinates document ingestion
- PDF chat → Similarity search: orchestrates · Core module coordinates retrieval
- PDF chat → LLM answer: orchestrates · Core module coordinates response generation
- Streamlit app → Streamlit: runs on · The application is launched under Streamlit
- PDF chat → LangChain: leverages · Document and chain helpers support the RAG flow
- .env config → Streamlit app: configures · Environment variables supply runtime credentials
