# siddharthakosti/genai-doc2qa architecture

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

- Interactive diagram: https://gitdiagram.com/siddharthakosti/genai-doc2qa
- Repository: https://github.com/siddharthakosti/genai-doc2qa

## Overview

##### Project type and purpose
- This is a single-page Streamlit application (“GenAI-Doc2QA”) whose primary purpose is to let users upload a PDF, specify how many question/answer pairs they want, and then generate those pairs by calling OpenAI’s GPT-4 model.

##### File structure
- Top-level files:
- app.py: the Streamlit entrypoint (UI + orchestration)
- template.py: any custom rendering or UI helpers
- setup.py + requirements.txt: packaging and dependencies
- data/: static assets (e.g., screenshots, sample files)
- research/: Jupyter notebook for offline model/ prompt experiments
- src/ directory:
- src/helper.py: handles PDF ingestion and text extraction
- src/prompt.py: builds/ formats the prompts sent to OpenAI
- No separate “backend” folder—Streamlit acts as both front-end and lightweight server.

##### README for additional insights
- Confirms the Streamlit UI flow: upload PDF → choose count → click “Generate” → calls OpenAI API → displays Q/A pairs.
- Environment variable OPENAI_API_KEY is required.
- No database or persistent storage—file I/O is ephemeral in-memory.

##### Detail without overcomplicating
- Environment variable store (.env / OPENAI_API_KEY) as a configuration artifact
- Retry logic, error handling, or logging that occurs around the API call

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    Browser["User Browser"]:::ui

    %% Streamlit Process Layer
    subgraph "Streamlit Application (Frontend & Server)"
        direction TB
        StreamlitApp["Streamlit App\n(app.py)"]:::process
        Template["UI Helpers & Rendering\n(template.py)"]:::process
        Helper["PDF Ingestion & Text Extraction\n(src/helper.py)"]:::process
        Prompt["Prompt Construction Module\n(src/prompt.py)"]:::process
        Env["Config: OPENAI_API_KEY"]:::config
        TempStore["Temp PDF Store\n(optional I/O)"]:::io
    end

    %% External Service
    API["OpenAI GPT-4 API"]:::external

    %% Supporting Artifacts
    subgraph "Supporting Artifacts"
        direction TB
        Static["Static Assets & Samples\n(data/)"]:::io
        Notebook["Experimentation Notebook\n(research/trials.ipynb)"]:::io
        Setup["Packaging & Dependencies\n(setup.py,\nrequirements.txt)"]:::config
    end

    %% Data Flow
    Browser -->|"upload PDF\n& select count"| StreamlitApp
    StreamlitApp -->|"uses"| Template
    StreamlitApp -->|"send PDF"| Helper
    Helper -->|"return text"| StreamlitApp
    StreamlitApp -->|"build prompts"| Prompt
    StreamlitApp -->|"reads"| Env
    StreamlitApp -->|"optional store"| TempStore
    StreamlitApp -->|"call API"| API
    API -->|"Q/A pairs"| StreamlitApp
    StreamlitApp -->|"render Q/A"| Browser

    %% Click Events
    click StreamlitApp "https://github.com/siddharthakosti/genai-doc2qa/blob/main/app.py"
    click Template "https://github.com/siddharthakosti/genai-doc2qa/blob/main/template.py"
    click Helper "https://github.com/siddharthakosti/genai-doc2qa/blob/main/src/helper.py"
    click Prompt "https://github.com/siddharthakosti/genai-doc2qa/blob/main/src/prompt.py"
    click Static "https://github.com/siddharthakosti/genai-doc2qa/tree/main/data/"
    click Notebook "https://github.com/siddharthakosti/genai-doc2qa/blob/main/research/trials.ipynb"
    click Setup "https://github.com/siddharthakosti/genai-doc2qa/blob/main/setup.py"

    %% Styles
    classDef ui fill:#ccffcc,stroke:#006600,color:#000000
    classDef process fill:#cce5ff,stroke:#0050a0,color:#000000
    classDef external fill:#ffe0b3,stroke:#cc8400,color:#000000
    classDef io fill:#e0e0e0,stroke:#888888,color:#000000
    classDef config fill:#f2ccff,stroke:#a64ca6,color:#000000
```
