# vikasums/pdfqna architecture

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

- Interactive diagram: https://gitdiagram.com/vikasums/pdfqna
- Repository: https://github.com/vikasums/pdfqna

## Overview

##### Project type and purpose
- This is a full‑stack, single‑page web application (“PDF Chat Assistant”) whose goal is to let users upload a PDF, extract text, and ask natural‑language questions about its content via OpenAI’s GPT‑3.5 model.

##### File structure
- Top‑level files:
- upload_and_extract.py (Flask app entrypoint)
- requirements.txt, .env.example (environment & dependencies)
- templates/index.html (Jinja template hosting the Materialize UI)
- assets/images (demo screenshot)
- (Implicit at runtime) uploads/ directory for storing user‑uploaded PDFs
- No separate “frontend” folder—static assets and the HTML template live under “templates” and “assets.”
- The single Python script defines both HTTP endpoints and calls into PyPDF2 and the OpenAI API.

##### README for additional insights
- Tech stack: Python/Flask backend, Materialize CSS + JavaScript frontend, PyPDF2 for PDF parsing, OpenAI GPT‑3.5 Turbo for AI responses.
- Usage flow described: browser → upload → server extracts text → server forwards query+context to OpenAI → server returns AI response → browser displays it.

- Clear component labels (e.g., “Flask App,” “PyPDF2 Module,” “OpenAI GPT‑3.5 API”)
- Upload PDF → Flask route → Save to uploads/
- Flask → PyPDF2 → extracted text
- Flask → OpenAI API → AI response
- Flask → Client UI → display chat message
- Rectangles for internal components

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Client Browser)"
        Browser["Client Browser"]:::frontend
        Index["templates/index.html"]:::frontend
        Assets["assets/"]:::frontend
        Images["assets/images/"]:::frontend
    end

    subgraph "Backend (Flask Service)"
        FlaskApp["Flask App\nupload_and_extract.py"]:::backend
        PDFModule["PDF Processing Module\n(PyPDF2)"]:::backend
        AIIntegration["OpenAI Integration"]:::backend
        Env[".env.example"]:::backend
        Req["requirements.txt"]:::backend
        FileStorage["File Storage\nuploads/"]:::storage
    end

    OpenAI["OpenAI GPT-3.5 API"]:::external

    %% Data flow
    Browser -->|HTTP GET index.html| FlaskApp
    FlaskApp -->|renders| Index
    Browser -->|GET assets| FlaskApp
    FlaskApp -->|serves| Assets
    FlaskApp -->|serves| Images

    Browser -->|HTTP POST /upload| FlaskApp
    FlaskApp -->|write file| FileStorage
    FlaskApp -->|invoke| PDFModule
    PDFModule -->|extracted text| FlaskApp
    FlaskApp -->|REST API call| OpenAI
    OpenAI -->|AI response| FlaskApp
    FlaskApp -->|HTTP response JSON| Browser

    Env -->|loaded by| FlaskApp
    Req -->|loaded by| FlaskApp

    %% Click Events
    click Index "https://github.com/vikasums/pdfqna/blob/main/templates/index.html"
    click Assets "https://github.com/vikasums/pdfqna/tree/main/assets/"
    click Images "https://github.com/vikasums/pdfqna/tree/main/assets/images/"
    click FlaskApp "https://github.com/vikasums/pdfqna/blob/main/upload_and_extract.py"
    click PDFModule "https://github.com/vikasums/pdfqna/blob/main/upload_and_extract.py"
    click AIIntegration "https://github.com/vikasums/pdfqna/blob/main/upload_and_extract.py"
    click Env "https://github.com/vikasums/pdfqna/blob/main/.env.example"
    click Req "https://github.com/vikasums/pdfqna/blob/main/requirements.txt"
    click FileStorage "https://github.com/vikasums/pdfqna/tree/main/uploads/"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#3498DB,color:#1B4F72
    classDef backend fill:#D5F5E3,stroke:#27AE60,color:#145A32
    classDef storage fill:#FCF3CF,stroke:#F1C40F,color:#7D6608
    classDef external fill:#FDEDEC,stroke:#E74C3C,color:#641E16
```
