# amitgupta4407/all_about_pdf architecture

> Architecture diagram of the GitHub repository amitgupta4407/all_about_pdf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amitgupta4407/all_about_pdf
- Repository: https://github.com/amitgupta4407/all_about_pdf

## Overview

##### Project Type and Purpose
- AllAboutPDF is a monolithic, full-stack, web-based PDF manipulation and “Chat with PDF” application, built entirely in Python and delivered via the Streamlit framework.
- Core features: text/image/metadata extraction, PDF encryption, plus an interactive ChatPDF powered by LangChain and OpenAI.

##### File Structure
- Top level:
- app.py – main Streamlit app frontend + backend logic for PDF tasks
- FileQueryHub.py – alternate Streamlit entrypoint for multi-file chat feature
- requirements.txt – Python dependencies (Streamlit, PyPDF2, OpenAI, LangChain, etc.)
- .devcontainer/ – containerized development environment config
- No separate “frontend” or “backend” directories: the app is a single process combining UI and business logic.

##### README for Technical Insights
- UI: Streamlit handles HTTP layer, rendering widgets, file-upload, and download.
- PDF processing: PyPDF2 library for parsing, extracting, encrypting.
- ChatPDF: LangChain orchestrates document splitting, vector store, and query chain; OpenAI API provides LLM completions.

##### Main Components and Their Interactions
a. Streamlit App (app.py / FileQueryHub.py) [Web UI + Controller]
- Receives user requests (file upload, selected operation, chat query).
- Routes requests to appropriate service modules.
b. PDF Processing Module [Business Logic]
- Uses PyPDF2 for extract_text, extract_images, get_metadata, encrypt_pdf, etc.
- Returns processed PDF or extracted data to Streamlit for download/display.
c. ChatPDF Module [Business Logic]
- Document Loader and Text Splitter (LangChain)
- Vector Store (in-memory or lightweight store)
- RetrievalQA Chain (LangChain)
- Calls OpenAI REST API for embedding and LLM responses.
- Streams or returns answer back to the UI.
d. External Services
- OpenAI API (embeddings & chat completion)
- (Optionally) LangChain connectors, if extended to other vector stores.

##### Architectural Patterns and Design Principles
- Monolithic modular design: clearly separate modules for PDF tasks vs. chat tasks, even though they run in one process.
- MVC-like separation:
- View – Streamlit UI components
- Controller – Streamlit callbacks in app.py
- Model – PDFProcessing and ChatPDF modules
- Dependency injection via requirements.txt; containerized dev with .devcontainer.

##### Essential Details to Capture
- All external dependencies (PyPDF2, OpenAI, LangChain) so reviewers see tech stack.
- Flow of user data: upload → process → download/display.
- Chat flow: upload → vectorization → LLM call → answer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Client Browser"]:::external

    %% Streamlit App
    subgraph "Streamlit App"
        UI["UI Layer<br/>Streamlit Widgets"]:::frontend
        Controller["Controller Layer<br/>app.py callbacks"]:::controller
    end

    %% Alternate Entrypoint
    FileQueryHub["Alternate Entrypoint<br/>FileQueryHub.py"]:::controller

    %% Service Modules
    subgraph "Business Logic Modules"
        PDF["PDF Processing Module<br/>PyPDF2"]:::service
        ChatPDF["ChatPDF Module<br/>LangChain"]:::service
        VectorStore["Vector Store<br/>(in-memory)"]:::database
    end

    %% External API
    OpenAI["OpenAI API"]:::external

    %% Infra & Docs
    subgraph "Infrastructure & Docs"
        DevContainer[".devcontainer/"]:::infra
        Requirements["requirements.txt"]:::infra
        README["README.md"]:::infra
        License["LICENSE"]:::infra
    end

    %% Data Flows
    Browser -->|"upload file / send query"| UI
    UI -->|"invoke callback"| Controller
    Controller -->|"extract_text(), extract_images(), encrypt_pdf()"| PDF
    PDF -->|"return data / PDF"| Controller
    Controller -->|"render result"| UI
    UI -->|"download/display"| Browser

    UI -->|"chat_query()"| FileQueryHub
    FileQueryHub -->|"load_doc(), split_text()"| ChatPDF
    ChatPDF -->|"store embeddings"| VectorStore
    ChatPDF -->|"OpenAI.completions()"| OpenAI
    OpenAI -->|"response"| ChatPDF
    ChatPDF -->|"answer text"| FileQueryHub
    FileQueryHub -->|"render chat"| UI

    %% Click Events
    click Controller "https://github.com/amitgupta4407/all_about_pdf/blob/main/app.py"
    click FileQueryHub "https://github.com/amitgupta4407/all_about_pdf/blob/main/FileQueryHub.py"
    click DevContainer "https://github.com/amitgupta4407/all_about_pdf/tree/main/.devcontainer/"
    click Requirements "https://github.com/amitgupta4407/all_about_pdf/blob/main/requirements.txt"
    click README "https://github.com/amitgupta4407/all_about_pdf/blob/main/README.md"
    click License "https://github.com/amitgupta4407/all_about_pdf/tree/main/LICENSE"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1976D2,color:#0D47A1,stroke-width:2px;
    classDef controller fill:#FFF3E0,stroke:#FB8C00,color:#E65100,stroke-width:2px;
    classDef service fill:#E8F5E9,stroke:#43A047,color:#1B5E20,stroke-width:2px;
    classDef database fill:#F3E5F5,stroke:#8E24AA,color:#4A148C,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#FFEBEE,stroke:#E53935,color:#B71C1C,stroke-width:2px,stroke-dasharray: 2 2;
    classDef infra fill:#ECEFF1,stroke:#546E7A,color:#263238,stroke-width:2px,stroke-dasharray: 2 2;
```
