# adityasingh0912/pdf-document-analyzer architecture

> Architecture diagram of the GitHub repository adityasingh0912/pdf-document-analyzer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityasingh0912/pdf-document-analyzer
- Repository: https://github.com/adityasingh0912/pdf-document-analyzer

## Overview

##### Project Type & Purpose
- This is a modular, full-stack-ish Python application with a Streamlit front end and a series of back-end processing modules (PDF extraction, math detection, NER, summarization, optional LLM synthesis).
- It’s containerized via Docker, designed for scientific/technical PDF analysis.

##### High-Level Architecture Components
a. Frontend (Streamlit UI)
b. Orchestrator (analyzer.py)
c. Processing Modules:
- document_processor.py (PyMuPDF text extraction)
- math_detector.py (regex-based math detection)
- ner_processor.py (spaCy + Transformers NER)
- summary_generator.py (BERT extractive summarizer + optional Llama-3 Groq API)
d. External Services & Libraries:
- Groq LPU™ Inference Engine (LLM synthesis)
- Local ML frameworks (PyTorch, spaCy models)
- PyMuPDF
e. Deployment: Docker container

##### Data Flow & Interactions
- Streamlit UI → invokes analyzer.py → in sequence:
1. Text extraction → 2. Math detection → 3. NER → 4. Extractive summarization → (optional) 5. Abstractive LLM synthesis
- Each module returns results to the orchestrator, which passes aggregated data back to the UI for rendering (with highlights, summaries).
- If LLM synthesis is enabled, analyzer.py calls Groq SDK over HTTPS, passing extracted text+entities and receiving enhanced report.

- @startuml
- title AI Document Analyzer Architecture

- skinparam rectangle {
- BackgroundColor<<Module>> LightBlue
- BackgroundColor<<Service>> LightGreen
- BackgroundColor<<External>> LightOrange
- }

- rectangle "Streamlit UI\n(app.py)" <<Module>> as UI
- rectangle "Analyzer\n(analyzer.py)" <<Module>> as Orchestrator
- rectangle "PDF Extraction\n(document_processor.py)" <<Module>> as DocProc
- rectangle "Math Detector\n(math_detector.py)" <<Module>> as MathDet
- rectangle "NER Processor\n(ner_processor.py)" <<Module>> as NER
- rectangle "Summarizer\n(summary_generator.py)" <<Module>> as SumGen
- rectangle "Groq Inference\n(Groq SDK)" <<External>> as Groq

- UI --> Orchestrator : user request (PDF)
- Orchestrator --> DocProc : extract text
- Orchestrator --> MathDet : find math
- Orchestrator --> NER : detect entities
- Orchestrator --> SumGen : generate summary
- SumGen --> Groq : optional LLM synthesis
- Groq --> SumGen : enhanced report
- Orchestrator --> UI : JSON payload (text, math, entities, summaries)
- @enduml

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Docker Container"
        direction TB
        subgraph "Frontend"
            direction TB
            UI["Streamlit UI\n(app.py)"]:::module
        end
        subgraph "Orchestrator"
            direction TB
            Orchestrator["Analyzer\n(analyzer.py)"]:::module
        end
        subgraph "Processing Modules"
            direction TB
            DocProc["PDF Extraction\n(document_processor.py)"]:::module
            MathDet["Math Detection\n(math_detector.py)"]:::module
            NER["NER Processor\n(ner_processor.py)"]:::module
            SumGen["Summarization\n(summary_generator.py)"]:::module
        end
        subgraph "External Services & Libraries"
            direction TB
            PyMuPDF["PyMuPDF"]:::lib
            PyTorch["PyTorch"]:::lib
            spaCy["spaCy Models"]:::lib
            Groq["Groq LPU™ Inference"]:::external
        end
        Dockerfile["Dockerfile"]:::module
        Requirements["requirements.txt"]:::module
    end

    UI -->|"user uploads PDF\n(raw bytes)"| Orchestrator
    Orchestrator -->|"extract text"| DocProc
    DocProc -->|"extracted text"| Orchestrator
    Orchestrator -->|"detect math"| MathDet
    MathDet -->|"math spans"| Orchestrator
    Orchestrator -->|"detect entities"| NER
    NER -->|"entities"| Orchestrator
    Orchestrator -->|"generate summary"| SumGen
    SumGen -->|"extractive summary"| Orchestrator
    SumGen -.->|"optional LLM synthesis"| Groq
    Groq -->|"enhanced report"| SumGen
    Orchestrator -->|"aggregated payload\n(text, math, entities, summary)"| UI

    DocProc -.->|"uses"| PyMuPDF
    NER -.->|"uses"| spaCy
    SumGen -.->|"uses"| PyTorch

    click UI "https://github.com/adityasingh0912/pdf-document-analyzer/blob/main/app.py"
    click Orchestrator "https://github.com/adityasingh0912/pdf-document-analyzer/blob/main/analyzer.py"
    click DocProc "https://github.com/adityasingh0912/pdf-document-analyzer/blob/main/document_processor.py"
    click MathDet "https://github.com/adityasingh0912/pdf-document-analyzer/blob/main/math_detector.py"
    click NER "https://github.com/adityasingh0912/pdf-document-analyzer/blob/main/ner_processor.py"
    click SumGen "https://github.com/adityasingh0912/pdf-document-analyzer/blob/main/summary_generator.py"
    click Dockerfile "https://github.com/adityasingh0912/pdf-document-analyzer/tree/main/dockerfile"
    click Requirements "https://github.com/adityasingh0912/pdf-document-analyzer/blob/main/requirements.txt"

    classDef module fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef lib fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
```
