# ppisljar/pdf_translator architecture

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

- Interactive diagram: https://gitdiagram.com/ppisljar/pdf_translator
- Repository: https://github.com/ppisljar/pdf_translator

## Overview

##### Project type and purpose
- This is a full-stack “PDF Translator” application with both a Web UI and a CLI.
- It accepts PDF files, runs layout analysis + OCR + translation, then renders a translated PDF preserving the original layout.
- Translation engines supported: Google Translate (default) and OpenAI GPT.
- Layout engines: UniLM DiT (and planned VGT). OCR engine: PaddleOCR.

##### File structure
- Top-level entries:
- Dockerfile, Makefile, config.yaml, requirements.txt – build, config, dependencies, deployment
- server.py – backend HTTP server / API entry point
- cli.py – command-line interface entry point
- assets/ – static files (HTML/CSS/JS) for Web UI
- models/ – pre-trained model binaries and YAML configs for DiT, VGT, PaddleOCR
- modules/ – pluggable implementation of engines:
– modules/layout (e.g. ditod.py)
– modules/ocr (paddle.py)
– modules/translate (openai_gpt.py)
– modules/font (simple.py)
- utils/ – lower-level helpers for GUI, model loading, inference pipelines, dataset mapping, evaluation, etc.

##### README for additional insights
- Describes feature set, install steps, Docker and venv workflows.
- Emphasizes GPU dependency, Docker­based deployment, port 8765 for GUI.
- Mentions future goals (VGT support, font detection, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Clients"
        UI["Web UI"]:::client
        CLI["CLI Client"]:::client
    end

    UI -->|HTTP/HTTPS| API
    CLI -->|CLI Request| API

    API["Backend API Server"]:::api
    CONFIG["Configuration Loader"]:::config
    API -->|loads config| CONFIG

    subgraph "Processing Pipeline"
        Layout["Layout Detection (DiT/VGT)"]:::process
        OCR["OCR (PaddleOCR)"]:::process
        Translate["Translation (Google/OpenAI)"]:::process
        Font["Font Handling"]:::process
        Render["PDF Rendering"]:::process
    end

    API -->|submit PDF| Layout
    Layout -->|layout data| OCR
    OCR -->|text data| Translate
    Translate -->|translated text| Font
    Font -->|font-aware layout| Render
    Render -->|translated PDF| API

    subgraph "Model Storage"
        PDFModels["Layout Models"]:::storage
        OCRModels["OCR Models"]:::storage
    end

    PDFModels --> Layout
    OCRModels --> OCR

    subgraph "External Services"
        OpenAI["OpenAI GPT"]:::external
        Google["Google Translate"]:::external
    end

    Translate -->|API call| OpenAI
    Translate -->|API call| Google

    classDef client fill:#AED6F1,stroke:#1F618D,color:#1B4F72
    classDef api fill:#ABEBC6,stroke:#1D8348,color:#145A32
    classDef process fill:#F9E79F,stroke:#B7950B,color:#7E5109
    classDef storage fill:#D5D8DC,stroke:#797D7F,color:#2C3E50
    classDef external fill:#E8DAEF,stroke:#884EA0,color:#512E5F
    classDef config fill:#D6DBDF,stroke:#424949,color:#1A5276

    click UI "https://github.com/ppisljar/pdf_translator/tree/main/assets/"
    click CLI "https://github.com/ppisljar/pdf_translator/blob/main/cli.py"
    click API "https://github.com/ppisljar/pdf_translator/blob/main/server.py"
    click CONFIG "https://github.com/ppisljar/pdf_translator/blob/main/config.yaml"
    click PDFModels "https://github.com/ppisljar/pdf_translator/tree/main/models/unilm/"
    click PDFModels "https://github.com/ppisljar/pdf_translator/tree/main/models/vgt/"
    click OCRModels "https://github.com/ppisljar/pdf_translator/tree/main/models/paddle-ocr/"
    click Layout "https://github.com/ppisljar/pdf_translator/blob/main/modules/layout/base.py"
    click Layout "https://github.com/ppisljar/pdf_translator/blob/main/modules/layout/ditod.py"
    click Layout "https://github.com/ppisljar/pdf_translator/tree/main/utils/ditod/"
    click Layout "https://github.com/ppisljar/pdf_translator/tree/main/utils/ditod_vgt/"
    click OCR "https://github.com/ppisljar/pdf_translator/blob/main/modules/ocr/base.py"
    click OCR "https://github.com/ppisljar/pdf_translator/blob/main/modules/ocr/paddle.py"
    click OCR "https://github.com/ppisljar/pdf_translator/tree/main/utils/ocr_model/ppocr_onnx/"
    click Translate "https://github.com/ppisljar/pdf_translator/blob/main/modules/translate/base.py"
    click Translate "https://github.com/ppisljar/pdf_translator/blob/main/modules/translate/openai_gpt.py"
    click Font "https://github.com/ppisljar/pdf_translator/blob/main/modules/font/base.py"
    click Font "https://github.com/ppisljar/pdf_translator/blob/main/modules/font/simple.py"
    click Render "https://github.com/ppisljar/pdf_translator/blob/main/utils/layout_model.py"
    click UI "https://github.com/ppisljar/pdf_translator/blob/main/utils/gui.py"
    click deploymentDocker "https://github.com/ppisljar/pdf_translator/tree/main/Dockerfile"
    click deploymentMake "https://github.com/ppisljar/pdf_translator/tree/main/Makefile"
    click deploymentReq "https://github.com/ppisljar/pdf_translator/blob/main/requirements.txt"
```
