# harisnae/offlinewebocr architecture

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

- Interactive diagram: https://gitdiagram.com/harisnae/offlinewebocr
- Repository: https://github.com/harisnae/offlinewebocr

## Overview

This is a static, browser-based OCR demo: users load an image, optionally crop it, select and load a model, then run OCR in a web worker and view raw and decoded output. The worker uses Transformers.js for TrOCR-style image-to-text or Donut document-question-answering inference; the UI also supports copying decoded text. The README documents offline processing after model loading and browser caching. Edges reflect the shown script/worker messaging and calls; other capabilities are included where documented, without inferring unsampled implementation details.

Main entry points: [`worker.js`](https://github.com/harisnae/offlinewebocr/blob/main/worker.js) (OCR Worker), [`script.js`](https://github.com/harisnae/offlinewebocr/blob/main/script.js) (Image Canvas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_image_input["Image Input"]
  node_image_intake["Image Intake<br/>[script.js]"]
  node_image_canvas["Image Canvas<br/>[script.js]"]
  node_crop_tool["Crop Tool<br/>[script.js]"]
end

subgraph group_model_setup["Model Setup"]
  node_model_picker["Model Selection<br/>[script.js]"]
end

subgraph group_ocr_runtime["OCR Runtime"]
  node_model_loader["Model Loader<br/>[worker.js]"]
  node_ocr_worker["OCR Worker<br/>[worker.js]"]
  node_transformers["Transformers.js"]
  node_trocr["TrOCR Inference<br/>[worker.js]"]
  node_donut["Donut Inference<br/>[worker.js]"]
end

subgraph group_results["Results"]
  node_progress_ui["Progress Status<br/>[script.js]"]
  node_raw_output["Raw JSON Output<br/>[script.js]"]
  node_decoded_output["Decoded Text<br/>[script.js]"]
end

node_user(("User"))
node_clipboard["Clipboard"]

node_user -->|"uploads or selects"| node_image_intake
node_image_intake -->|"displays image"| node_image_canvas
node_user -->|"selects region"| node_crop_tool
node_crop_tool -->|"draws selection"| node_image_canvas
node_user -->|"chooses model"| node_model_picker
node_model_picker -->|"sends model ID"| node_model_loader
node_model_loader -->|"loads pipeline"| node_transformers
node_transformers -.->|"reports progress"| node_model_loader
node_model_loader -->|"posts progress"| node_progress_ui
node_user -->|"runs OCR on"| node_image_canvas
node_image_canvas -->|"sends image data"| node_ocr_worker
node_ocr_worker -->|"dispatches image task"| node_trocr
node_ocr_worker -->|"dispatches document task"| node_donut
node_trocr -->|"runs pipeline"| node_transformers
node_donut -->|"runs pipeline"| node_transformers
node_ocr_worker -->|"posts raw result"| node_raw_output
node_ocr_worker -->|"posts decoded text"| node_decoded_output
node_user -->|"copies text"| node_clipboard

click node_image_intake "https://github.com/harisnae/offlinewebocr/blob/main/script.js"
click node_image_canvas "https://github.com/harisnae/offlinewebocr/blob/main/script.js"
click node_crop_tool "https://github.com/harisnae/offlinewebocr/blob/main/script.js"
click node_model_picker "https://github.com/harisnae/offlinewebocr/blob/main/script.js"
click node_model_loader "https://github.com/harisnae/offlinewebocr/blob/main/worker.js"
click node_ocr_worker "https://github.com/harisnae/offlinewebocr/blob/main/worker.js"
click node_trocr "https://github.com/harisnae/offlinewebocr/blob/main/worker.js"
click node_donut "https://github.com/harisnae/offlinewebocr/blob/main/worker.js"
click node_progress_ui "https://github.com/harisnae/offlinewebocr/blob/main/script.js"
click node_raw_output "https://github.com/harisnae/offlinewebocr/blob/main/script.js"
click node_decoded_output "https://github.com/harisnae/offlinewebocr/blob/main/script.js"

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_image_intake,node_image_canvas,node_crop_tool,node_user toneBlue
class node_model_picker toneAmber
class node_model_loader,node_ocr_worker,node_transformers,node_trocr,node_donut toneMint
class node_progress_ui,node_raw_output,node_decoded_output toneRose
class node_clipboard toneIndigo
```

## Components

### Image Input

- [Image Intake](https://github.com/harisnae/offlinewebocr/blob/main/script.js): `script.js`
- [Image Canvas](https://github.com/harisnae/offlinewebocr/blob/main/script.js): `script.js`
- [Crop Tool](https://github.com/harisnae/offlinewebocr/blob/main/script.js): `script.js`

### Model Setup

- [Model Selection](https://github.com/harisnae/offlinewebocr/blob/main/script.js): `script.js`

### OCR Runtime

- [Model Loader](https://github.com/harisnae/offlinewebocr/blob/main/worker.js): `worker.js`
- [OCR Worker](https://github.com/harisnae/offlinewebocr/blob/main/worker.js): `worker.js`
- **Transformers.js**
- [TrOCR Inference](https://github.com/harisnae/offlinewebocr/blob/main/worker.js): `worker.js`
- [Donut Inference](https://github.com/harisnae/offlinewebocr/blob/main/worker.js): `worker.js`

### Results

- [Progress Status](https://github.com/harisnae/offlinewebocr/blob/main/script.js): `script.js`
- [Raw JSON Output](https://github.com/harisnae/offlinewebocr/blob/main/script.js): `script.js`
- [Decoded Text](https://github.com/harisnae/offlinewebocr/blob/main/script.js): `script.js`

### Other components

- **User**
- **Clipboard**

## Connections

- User → Image Intake: uploads or selects (evidence: `script.js`)
- Image Intake → Image Canvas: displays image (evidence: `script.js`)
- User → Crop Tool: selects region (evidence: `script.js`)
- Crop Tool → Image Canvas: draws selection (evidence: `script.js`)
- User → Model Selection: chooses model (evidence: `script.js`)
- Model Selection → Model Loader: sends model ID (evidence: `script.js`)
- Model Loader → Transformers.js: loads pipeline (evidence: `worker.js`)
- Transformers.js → Model Loader: reports progress
- Model Loader → Progress Status: posts progress (evidence: `worker.js`)
- User → Image Canvas: runs OCR on (evidence: `script.js`)
- Image Canvas → OCR Worker: sends image data (evidence: `script.js`)
- OCR Worker → TrOCR Inference: dispatches image task (evidence: `worker.js`)
- OCR Worker → Donut Inference: dispatches document task (evidence: `worker.js`)
- TrOCR Inference → Transformers.js: runs pipeline (evidence: `worker.js`)
- Donut Inference → Transformers.js: runs pipeline (evidence: `worker.js`)
- OCR Worker → Raw JSON Output: posts raw result (evidence: `script.js`)
- OCR Worker → Decoded Text: posts decoded text (evidence: `script.js`)
- User → Clipboard: copies text
