# rahid-khan/fast-api-ocr architecture

> Architecture diagram of the GitHub repository rahid-khan/fast-api-ocr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahid-khan/fast-api-ocr
- Repository: https://github.com/rahid-khan/fast-api-ocr

## Overview

Unlimited OCR is a browser-based document digitizer: users upload PDFs or images, follow job progress and streamed OCR text, then view or download results in text, Markdown, or JSON. The API validates and records uploads, schedules processing, converts PDF pages, and invokes the OCR engine; job records and results support history and status queries. The dashboard presents GPU, memory, and inference statistics. The README documents these capabilities; sampled backend and frontend excerpts support the principal wiring, while some dashboard and progress endpoints are represented only by their enclosing router paths.

Main entry points: [`static/js/app.js`](https://github.com/rahid-khan/fast-api-ocr/blob/main/static/js/app.js) (Upload and dashboard), [`app/job_manager.py`](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/job_manager.py) (Job orchestration), [`app/ocr_engine.py`](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/ocr_engine.py) (OCR engine), [`app/routers/jobs.py`](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/routers/jobs.py) (Jobs API and SSE)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser interface"]
  node_web["Web application<br/>[index.html]"]
  node_appjs["Upload and dashboard<br/>[app.js]"]
  node_results["Results and history<br/>[result-viewer.js]"]
  node_viz["Dashboard charts<br/>[visualization.js]"]
end

subgraph group_api["API and jobs"]
  node_main["FastAPI application<br/>[main.py]"]
  node_upload["Upload endpoint<br/>[upload.py]"]
  node_jobs["Jobs API and SSE<br/>[jobs.py]"]
  node_manager["Job orchestration<br/>[job_manager.py]"]
  node_health["Health and metrics API<br/>[health.py]"]
  node_models["Job response schemas<br/>[models.py]"]
end

subgraph group_ocr["OCR processing"]
  node_pdf["PDF page conversion<br/>[pdf_converter.py]"]
  node_engine["OCR engine<br/>[ocr_engine.py]"]
end

subgraph group_state["State and monitoring"]
  node_database[("SQLite job records<br/>[database.py]")]
  node_files["Uploaded and result files"]
end

node_user(("Document user"))
node_model{{"Unlimited-OCR model"}}
node_gpu(("GPU or CPU"))

node_user -->|"uses"| node_web
node_main -->|"serves"| node_web
node_web -->|"loads"| node_appjs
node_appjs -->|"uploads file"| node_upload
node_appjs -->|"requests jobs"| node_jobs
node_appjs -->|"requests metrics"| node_health
node_jobs -->|"returns results"| node_results
node_results -->|"renders history"| node_appjs
node_appjs -->|"renders metrics"| node_viz
node_main -->|"mounts route"| node_upload
node_main -->|"mounts route"| node_jobs
node_main -->|"mounts route"| node_health
node_main -->|"initializes"| node_database
node_upload -->|"saves upload"| node_files
node_upload -->|"creates and schedules"| node_manager
node_upload -->|"returns job"| node_models
node_manager -->|"reads and updates"| node_database
node_manager -->|"converts PDFs"| node_pdf
node_manager -->|"runs OCR"| node_engine
node_manager -->|"stores outputs"| node_files
node_pdf -->|"writes page images"| node_files
node_engine -->|"runs inference"| node_model
node_engine -->|"uses when available"| node_gpu
node_engine -->|"reads and writes outputs"| node_files
node_engine -->|"provides stream chunks"| node_jobs
node_jobs -->|"queries and deletes"| node_database
node_jobs -->|"deletes job files"| node_manager
node_health -->|"reads runtime metrics"| node_engine
node_health -->|"reads job statistics"| node_database

click node_web "https://github.com/rahid-khan/fast-api-ocr/blob/main/static/index.html"
click node_appjs "https://github.com/rahid-khan/fast-api-ocr/blob/main/static/js/app.js"
click node_results "https://github.com/rahid-khan/fast-api-ocr/blob/main/static/js/result-viewer.js"
click node_viz "https://github.com/rahid-khan/fast-api-ocr/blob/main/static/js/visualization.js"
click node_main "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/main.py"
click node_upload "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/routers/upload.py"
click node_jobs "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/routers/jobs.py"
click node_manager "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/job_manager.py"
click node_health "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/routers/health.py"
click node_models "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/models.py"
click node_pdf "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/pdf_converter.py"
click node_engine "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/ocr_engine.py"
click node_database "https://github.com/rahid-khan/fast-api-ocr/blob/main/app/database.py"

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_web,node_appjs,node_results,node_viz,node_user toneBlue
class node_main,node_upload,node_jobs,node_manager,node_health,node_models toneAmber
class node_pdf,node_engine toneMint
class node_database,node_files toneRose
class node_model,node_gpu toneIndigo
```

## Components

### Browser interface

- [Web application](https://github.com/rahid-khan/fast-api-ocr/blob/main/static/index.html): `static/index.html`
- [Upload and dashboard](https://github.com/rahid-khan/fast-api-ocr/blob/main/static/js/app.js): `static/js/app.js`
- [Results and history](https://github.com/rahid-khan/fast-api-ocr/blob/main/static/js/result-viewer.js): `static/js/result-viewer.js`
- [Dashboard charts](https://github.com/rahid-khan/fast-api-ocr/blob/main/static/js/visualization.js): `static/js/visualization.js`

### API and jobs

- [FastAPI application](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/main.py): `app/main.py`
- [Upload endpoint](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/routers/upload.py): `app/routers/upload.py`
- [Jobs API and SSE](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/routers/jobs.py): `app/routers/jobs.py`
- [Job orchestration](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/job_manager.py): `app/job_manager.py`
- [Health and metrics API](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/routers/health.py): `app/routers/health.py`
- [Job response schemas](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/models.py): `app/models.py`

### OCR processing

- [PDF page conversion](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/pdf_converter.py): `app/pdf_converter.py`
- [OCR engine](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/ocr_engine.py): `app/ocr_engine.py`

### State and monitoring

- [SQLite job records](https://github.com/rahid-khan/fast-api-ocr/blob/main/app/database.py): `app/database.py`
- **Uploaded and result files**

### Other components

- **Document user**
- **Unlimited-OCR model**
- **GPU or CPU**

## Connections

- Document user → Web application: uses
- FastAPI application → Web application: serves
- Web application → Upload and dashboard: loads
- Upload and dashboard → Upload endpoint: uploads file
- Upload and dashboard → Jobs API and SSE: requests jobs
- Upload and dashboard → Health and metrics API: requests metrics
- Jobs API and SSE → Results and history: returns results
- Results and history → Upload and dashboard: renders history
- Upload and dashboard → Dashboard charts: renders metrics
- FastAPI application → Upload endpoint: mounts route
- FastAPI application → Jobs API and SSE: mounts route
- FastAPI application → Health and metrics API: mounts route
- FastAPI application → SQLite job records: initializes
- Upload endpoint → Uploaded and result files: saves upload
- Upload endpoint → Job orchestration: creates and schedules
- Upload endpoint → Job response schemas: returns job
- Job orchestration → SQLite job records: reads and updates
- Job orchestration → PDF page conversion: converts PDFs
- Job orchestration → OCR engine: runs OCR
- Job orchestration → Uploaded and result files: stores outputs
- PDF page conversion → Uploaded and result files: writes page images
- OCR engine → Unlimited-OCR model: runs inference
- OCR engine → GPU or CPU: uses when available
- OCR engine → Uploaded and result files: reads and writes outputs
- OCR engine → Jobs API and SSE: provides stream chunks
- Jobs API and SSE → SQLite job records: queries and deletes
- Jobs API and SSE → Job orchestration: deletes job files
- Health and metrics API → OCR engine: reads runtime metrics
- Health and metrics API → SQLite job records: reads job statistics
