# dhanush0959/geminidecode architecture

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

- Interactive diagram: https://gitdiagram.com/dhanush0959/geminidecode
- Repository: https://github.com/dhanush0959/geminidecode

## Overview

1. **System shape**
   - This is a single-service Flask application with a browser UI and a backend translation pipeline.
   - The main boundary is between the HTTP layer in `app.py` and the document-processing engine in `translate.py`.

2. **Request/response entry point**
   - The web app is served from `app.py`, with the homepage rendered from `templates/index.html`.
   - Static assets are split into `static/js/main.js` for UI behavior and `static/css/style.css` for presentation.

3. **User interaction flow**
   - A user uploads a PDF through the web interface.
   - The backend stores the uploaded file under a per-document folder in `./data/`.
   - The frontend then polls for progress and refreshes the UI while translation runs.

4. **Translation pipeline boundary**
   - `translate.py` is the core processing subsystem.
   - Its job is to take the uploaded PDF, extract page content, call Gemini for transcription/translation, and assemble the final translated document.
   - The README describes a multi-stage pipeline: transcription, translation, and compilation.

5. **AI and document-processing dependencies**
   - Google Gemini is the external AI service that performs the language conversion.
   - PyMuPDF and Pillow are used for PDF/page extraction and image handling.
   - WeasyPrint and python-docx are used to generate output artifacts in multiple formats.

6. **Document storage model**
   - Each translation appears to be isolated in its own directory under `data/<document-name>/`.
   - That directory contains the original PDF, intermediate transcription files, intermediate translation files, and a final `translated.md`.
   - This directory-per-job structure is the main persistence boundary in the app.

7. **Output and retrieval paths**
   - The app exposes endpoints for viewing the translated result in-browser, downloading it in several formats, and accessing the original PDF.
   - The supported download targets are Markdown, TXT, DOCX, and PDF.
   - This makes the final compiled translation the source artifact, with other formats generated from it.

8. **Progress and concurrency model**
   - The README indicates live progress tracking and concurrent translation of up to 8 pages simultaneously.
   - That means translation is not a simple single blocking operation; it is a job-like process with intermediate state exposed to the UI.
   - The progress endpoint is a key integration point between backend processing and frontend polling.

9. **Operational/runtime boundary**
   - The project is containerized with Docker and Docker Compose.
   - The runtime is Python/Flask, with file-backed persistence mounted via a `data` volume and logs managed separately.
   - This suggests the service is designed to be deployed as one container rather than a distributed system.

10. **API surface**
   - The repository exposes a small HTTP API in addition to the UI: upload, progress, file listing, view, download, original-file access, delete, and health check.
   - These endpoints form the control plane around the translation jobs and the file store.
   - The health endpoint is the main operational signal for container/platform monitoring.

11. **Frontend architecture**
   - The frontend is intentionally lightweight: server-rendered HTML plus vanilla JavaScript.
   - JavaScript likely handles upload interaction, progress polling, preview updates, and deletion/download actions.
   - There is no separate frontend framework or SPA boundary here.

12. **Deployment and security assumptions**
   - Configuration is environment-driven, especially the Gemini API key.
   - The README notes the app is intended to run behind Cloudflare with Google Authentication, but internal auth is not implemented in the codebase itself.
   - For an architecture diagram, treat authentication as an external deployment concern, not an application subsystem.

Main entry points: [`app.py`](https://github.com/dhanush0959/geminidecode/blob/main/app.py) (Flask app), [`translate.py`](https://github.com/dhanush0959/geminidecode/blob/main/translate.py) (Translator), [`templates/index.html`](https://github.com/dhanush0959/geminidecode/blob/main/templates/index.html) (Homepage), [`static/js/main.js`](https://github.com/dhanush0959/geminidecode/blob/main/static/js/main.js) (Main JS)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Web UI"]
  node_page["Homepage<br/>HTML template<br/>[index.html]"]
  node_js["Main JS<br/>browser script<br/>[main.js]"]
  node_css["Stylesheet<br/>presentation<br/>[style.css]"]
end

subgraph group_backend["Backend"]
  node_app["Flask app<br/>HTTP server<br/>[app.py]"]
  node_pipeline{{"Translator<br/>pipeline core<br/>[translate.py]"}}
  node_extract["Page extract<br/>pdf parsing<br/>[translate.py]"]
  node_gemini["Gemini pass<br/>ai transcription<br/>[translate.py]"]
  node_compile["Compile doc<br/>document assembly<br/>[translate.py]"]
  node_exports["Format export<br/>multi-format output<br/>[translate.py]"]
  node_progress(("Progress API<br/>job status<br/>[app.py]"))
  node_downloads["Download API<br/>file delivery<br/>[app.py]"]
end

subgraph group_storage["Job Storage"]
  node_jobdir[("Job folder<br/>document store")]
  node_orig["Original PDF<br/>input artifact"]
  node_transmd["Translated MD<br/>result artifact"]
end

subgraph group_runtime["Runtime"]
  node_health(("Health check<br/>ops endpoint<br/>[app.py]"))
  node_docker["Docker runtime<br/>container"]
  node_compose["Compose setup<br/>deployment config<br/>[docker-compose.yml]"]
  node_geminiapi(("Gemini API<br/>external ai service"))
  node_pdfdoc(("PDF/Doc libs<br/>libraries"))
end

node_page -->|"renders"| node_app
node_js -->|"calls API"| node_app
node_css -->|"styles"| node_page
node_app -->|"starts job"| node_pipeline
node_pipeline -->|"reads pages"| node_extract
node_extract -->|"feeds text"| node_gemini
node_gemini -->|"returns translation"| node_compile
node_compile -->|"produces outputs"| node_exports
node_pipeline -->|"writes state"| node_jobdir
node_orig -->|"stored in"| node_jobdir
node_exports -->|"derives"| node_transmd
node_app -->|"reports status"| node_progress
node_progress -->|"polled by"| node_js
node_app -->|"serves files"| node_downloads
node_downloads -->|"reads from"| node_jobdir
node_app -->|"exposes"| node_health
node_pipeline -->|"uses"| node_geminiapi
node_pipeline -->|"uses"| node_pdfdoc
node_docker -->|"runs"| node_app
node_compose -->|"orchestrates"| node_docker

click node_app "https://github.com/dhanush0959/geminidecode/blob/main/app.py"
click node_page "https://github.com/dhanush0959/geminidecode/blob/main/templates/index.html"
click node_js "https://github.com/dhanush0959/geminidecode/blob/main/static/js/main.js"
click node_css "https://github.com/dhanush0959/geminidecode/blob/main/static/css/style.css"
click node_pipeline "https://github.com/dhanush0959/geminidecode/blob/main/translate.py"
click node_extract "https://github.com/dhanush0959/geminidecode/blob/main/translate.py"
click node_gemini "https://github.com/dhanush0959/geminidecode/blob/main/translate.py"
click node_compile "https://github.com/dhanush0959/geminidecode/blob/main/translate.py"
click node_exports "https://github.com/dhanush0959/geminidecode/blob/main/translate.py"
click node_progress "https://github.com/dhanush0959/geminidecode/blob/main/app.py"
click node_downloads "https://github.com/dhanush0959/geminidecode/blob/main/app.py"
click node_health "https://github.com/dhanush0959/geminidecode/blob/main/app.py"
click node_docker "https://github.com/dhanush0959/geminidecode/tree/main/Dockerfile"
click node_compose "https://github.com/dhanush0959/geminidecode/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_page,node_js,node_css toneBlue
class node_app,node_pipeline,node_extract,node_gemini,node_compile,node_exports,node_progress,node_downloads toneAmber
class node_jobdir,node_orig,node_transmd toneMint
class node_health,node_docker,node_compose,node_geminiapi,node_pdfdoc toneRose
```

## Components

### Web UI

Server-rendered interface plus browser behavior

- [Homepage](https://github.com/dhanush0959/geminidecode/blob/main/templates/index.html): HTML template · Server-rendered entry page for uploads and results · `templates/index.html`
- [Main JS](https://github.com/dhanush0959/geminidecode/blob/main/static/js/main.js): browser script · Handles upload actions, polling, previews, and file actions · `static/js/main.js`
- [Stylesheet](https://github.com/dhanush0959/geminidecode/blob/main/static/css/style.css): presentation · UI styling for the web interface · `static/css/style.css`

### Backend

Flask routes and translation pipeline

- [Flask app](https://github.com/dhanush0959/geminidecode/blob/main/app.py): HTTP server · Serves pages and exposes the upload/progress/download API · `app.py`
- [Translator](https://github.com/dhanush0959/geminidecode/blob/main/translate.py): pipeline core · Coordinates document processing from PDF to translated outputs · `translate.py`
- [Page extract](https://github.com/dhanush0959/geminidecode/blob/main/translate.py): pdf parsing · Reads PDF pages and prepares page content for processing · `translate.py`
- [Gemini pass](https://github.com/dhanush0959/geminidecode/blob/main/translate.py): ai transcription · Calls Gemini to transcribe and translate page content · `translate.py`
- [Compile doc](https://github.com/dhanush0959/geminidecode/blob/main/translate.py): document assembly · Merges translated content into the final translated document · `translate.py`
- [Format export](https://github.com/dhanush0959/geminidecode/blob/main/translate.py): multi-format output · Generates Markdown, TXT, DOCX, and PDF artifacts · `translate.py`
- [Progress API](https://github.com/dhanush0959/geminidecode/blob/main/app.py): job status · Exposes live translation progress for frontend polling · `app.py`
- [Download API](https://github.com/dhanush0959/geminidecode/blob/main/app.py): file delivery · Serves translated artifacts in multiple formats and the original PDF · `app.py`

### Job Storage

Per-document file-backed persistence

- **Job folder**: document store · Per-document directory under data/<name>/ with intermediates and outputs
- **Original PDF**: input artifact · Uploaded source document stored with each job
- **Translated MD**: result artifact · Canonical translated output used to derive other formats

### Runtime

Container and deployment boundary

- [Health check](https://github.com/dhanush0959/geminidecode/blob/main/app.py): ops endpoint · Operational signal for container monitoring · `app.py`
- [Docker runtime](https://github.com/dhanush0959/geminidecode/tree/main/Dockerfile): container · Containerized Flask deployment with mounted data volume · `Dockerfile`
- [Compose setup](https://github.com/dhanush0959/geminidecode/blob/main/docker-compose.yml): deployment config · Local orchestration and service wiring for the container · `docker-compose.yml`
- **Gemini API**: external ai service · External model service used for transcription and translation
- **PDF/Doc libs**: libraries · PyMuPDF, Pillow, WeasyPrint, and python-docx processing layer

## Connections

- Homepage → Flask app: renders · Homepage is served by the Flask app
- Main JS → Flask app: calls API · Browser script invokes upload, progress, view, download, and delete endpoints
- Stylesheet → Homepage: styles · Presentation is applied to the rendered page
- Flask app → Translator: starts job · Upload handling hands the document to the translation engine
- Translator → Page extract: reads pages · Pipeline extracts page content from the source PDF
- Page extract → Gemini pass: feeds text · Extracted page material is prepared for model conversion
- Gemini pass → Compile doc: returns translation · Translated/transcribed content is assembled into document form
- Compile doc → Format export: produces outputs · Compiled content is exported into multiple deliverable formats
- Translator → Job folder: writes state · Intermediate and final artifacts are stored in the per-job directory
- Original PDF → Job folder: stored in · Uploaded PDF is persisted with the job folder
- Format export → Translated MD: derives · Markdown acts as the canonical generated artifact
- Flask app → Progress API: reports status · Backend exposes live progress for polling UI updates
- Progress API → Main JS: polled by · Frontend repeatedly checks job status
- Flask app → Download API: serves files · Backend returns translated outputs and the original PDF
- Download API → Job folder: reads from · Download endpoints pull artifacts from the job directory
- Flask app → Health check: exposes · Health endpoint is served for platform checks
- Translator → Gemini API: uses · Translation depends on the external Gemini service
- Translator → PDF/Doc libs: uses · Document extraction and export rely on PDF/document libraries
- Docker runtime → Flask app: runs · Container launches the Flask application
- Compose setup → Docker runtime: orchestrates · Compose defines the local deployment wiring
