# sokhengdin/anaksor-ocr architecture

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

- Interactive diagram: https://gitdiagram.com/sokhengdin/anaksor-ocr
- Repository: https://github.com/sokhengdin/anaksor-ocr

## Overview

Anaksor is a Khmer OCR product for images, scans, and PDFs. Its main workflow accepts a page, detects text-line boxes, recognizes cropped lines, arranges them into reading order and paragraphs, then returns text/structured results or exports Word and searchable PDF. The repository also includes a browser demo and bilingual documentation. Edges reflect the README and shown source references; the browser-to-OCR service wiring and several unsampled implementation details are not verified here.

Main entry points: [`src/anaksor/ocr.py`](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/ocr.py) (OCR orchestration), [`src/anaksor/detector.py`](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/detector.py) (Line detection), [`src/anaksor/recognizer.py`](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/recognizer.py) (Line recognition), [`web/src/components/Demo.tsx`](https://github.com/sokhengdin/anaksor-ocr/blob/master/web/src/components/Demo.tsx) (Interactive demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["Command line<br/>[cli.py]"]
  node_ocr["OCR orchestration<br/>[ocr.py]"]
end

subgraph group_vision["OCR pipeline"]
  node_inputs["Image and PDF input<br/>[inputs.py]"]
  node_detector["Line detection<br/>[detector.py]"]
  node_dbboxes["Box extraction<br/>[db_boxes.py]"]
  node_geometry["Crop geometry<br/>[geometry.py]"]
  node_recognizer["Line recognition<br/>[recognizer.py]"]
  node_longline["Long-line stitching<br/>[longline.py]"]
  node_layout["Reading-order layout<br/>[layout.py]"]
  node_text["Khmer normalization<br/>[text.py]"]
end

subgraph group_models["Models and runtime"]
  node_modelweights["Specs and weights<br/>[models.py]"]
  node_runtime["Inference backends<br/>[runtime.py]"]
  node_detnet["DBNet architectures<br/>[dbnet.py]"]
  node_backbones["Backbone networks<br/>[repvit.py]"]
  node_netlayers["Network layers<br/>[layers.py]"]
  node_fuse["Inference fusion<br/>[fuse.py]"]
  node_decoding["Recognition decoding<br/>[decoding.py]"]
end

subgraph group_outputs["Results and exports"]
  node_results["OCR results<br/>[ocr.py]"]
  node_pdfexport["Searchable PDF<br/>[searchable_pdf.py]"]
  node_wordexport["Word export<br/>[word.py]"]
end

subgraph group_web["Browser product"]
  node_demo["Interactive demo<br/>[Demo.tsx]"]
  node_apiclient["Demo API client<br/>[api.ts]"]
  node_docs["Bilingual documentation<br/>[docs-en.tsx]"]
end

node_user(("User"))
node_browser(("Browser user"))
node_externalocr(("OCR service"))

node_user -->|"submits pages"| node_cli
node_cli -.->|"runs OCR"| node_ocr
node_ocr -->|"reads pages"| node_inputs
node_ocr -->|"detects lines"| node_detector
node_detector -->|"resolves weights"| node_modelweights
node_detector -->|"runs inference"| node_runtime
node_detector -->|"extracts boxes"| node_dbboxes
node_detector -->|"uses geometry"| node_geometry
node_detector -->|"builds detector"| node_detnet
node_detnet -->|"uses backbone"| node_backbones
node_backbones -->|"uses layers"| node_netlayers
node_detector -->|"fuses modules"| node_fuse
node_ocr -->|"recognizes crops"| node_recognizer
node_recognizer -->|"resolves weights"| node_modelweights
node_recognizer -->|"runs inference"| node_runtime
node_recognizer -->|"decodes output"| node_decoding
node_recognizer -->|"normalizes text"| node_text
node_ocr -->|"stitches long lines"| node_longline
node_ocr -->|"orders lines"| node_layout
node_ocr -->|"crops lines"| node_geometry
node_ocr -->|"returns results"| node_results
node_results -->|"exports PDF"| node_pdfexport
node_results -->|"exports Word"| node_wordexport
node_browser -->|"uploads pages"| node_demo
node_demo -->|"requests OCR"| node_apiclient
node_apiclient -.->|"sends OCR request"| node_externalocr
node_demo -.->|"requests export"| node_pdfexport
node_browser -->|"reads guides"| node_docs

click node_cli "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/cli.py"
click node_ocr "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/ocr.py"
click node_inputs "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/inputs.py"
click node_detector "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/detector.py"
click node_dbboxes "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/db_boxes.py"
click node_geometry "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/geometry.py"
click node_recognizer "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/recognizer.py"
click node_longline "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/longline.py"
click node_layout "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/layout.py"
click node_text "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/text.py"
click node_modelweights "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/models.py"
click node_runtime "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/runtime.py"
click node_detnet "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/dbnet.py"
click node_backbones "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/repvit.py"
click node_netlayers "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/layers.py"
click node_fuse "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/fuse.py"
click node_decoding "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/decoding.py"
click node_results "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/ocr.py"
click node_pdfexport "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/export/searchable_pdf.py"
click node_wordexport "https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/export/word.py"
click node_demo "https://github.com/sokhengdin/anaksor-ocr/blob/master/web/src/components/Demo.tsx"
click node_apiclient "https://github.com/sokhengdin/anaksor-ocr/blob/master/web/src/lib/api.ts"
click node_docs "https://github.com/sokhengdin/anaksor-ocr/blob/master/web/src/content/docs-en.tsx"

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_cli,node_ocr,node_user,node_browser toneBlue
class node_inputs,node_detector,node_dbboxes,node_geometry,node_recognizer,node_longline,node_layout,node_text toneAmber
class node_modelweights,node_runtime,node_detnet,node_backbones,node_netlayers,node_fuse,node_decoding toneMint
class node_results,node_pdfexport,node_wordexport toneRose
class node_demo,node_apiclient,node_docs,node_externalocr toneIndigo
```

## Components

### Entry points

- [Command line](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/cli.py): `src/anaksor/cli.py`
- [OCR orchestration](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/ocr.py): `src/anaksor/ocr.py`

### OCR pipeline

- [Image and PDF input](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/inputs.py): `src/anaksor/inputs.py`
- [Line detection](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/detector.py): `src/anaksor/detector.py`
- [Box extraction](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/db_boxes.py): `src/anaksor/db_boxes.py`
- [Crop geometry](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/geometry.py): `src/anaksor/geometry.py`
- [Line recognition](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/recognizer.py): `src/anaksor/recognizer.py`
- [Long-line stitching](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/longline.py): `src/anaksor/longline.py`
- [Reading-order layout](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/layout.py): `src/anaksor/layout.py`
- [Khmer normalization](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/text.py): `src/anaksor/text.py`

### Models and runtime

- [Specs and weights](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/models.py): `src/anaksor/models.py`
- [Inference backends](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/runtime.py): `src/anaksor/runtime.py`
- [DBNet architectures](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/dbnet.py): `src/anaksor/nets/dbnet.py`
- [Backbone networks](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/repvit.py): `src/anaksor/nets/repvit.py`
- [Network layers](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/layers.py): `src/anaksor/nets/layers.py`
- [Inference fusion](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/nets/fuse.py): `src/anaksor/nets/fuse.py`
- [Recognition decoding](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/decoding.py): `src/anaksor/decoding.py`

### Results and exports

- [OCR results](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/ocr.py): `src/anaksor/ocr.py`
- [Searchable PDF](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/export/searchable_pdf.py): `src/anaksor/export/searchable_pdf.py`
- [Word export](https://github.com/sokhengdin/anaksor-ocr/blob/master/src/anaksor/export/word.py): `src/anaksor/export/word.py`

### Browser product

- [Interactive demo](https://github.com/sokhengdin/anaksor-ocr/blob/master/web/src/components/Demo.tsx): `web/src/components/Demo.tsx`
- [Demo API client](https://github.com/sokhengdin/anaksor-ocr/blob/master/web/src/lib/api.ts): `web/src/lib/api.ts`
- [Bilingual documentation](https://github.com/sokhengdin/anaksor-ocr/blob/master/web/src/content/docs-en.tsx): `web/src/content/docs-en.tsx`

### Other components

- **User**
- **Browser user**
- **OCR service**

## Connections

- User → Command line: submits pages (evidence: `README.md`)
- Command line → OCR orchestration: runs OCR
- OCR orchestration → Image and PDF input: reads pages (evidence: `src/anaksor/ocr.py`)
- OCR orchestration → Line detection: detects lines (evidence: `src/anaksor/ocr.py`)
- Line detection → Specs and weights: resolves weights (evidence: `src/anaksor/detector.py`)
- Line detection → Inference backends: runs inference (evidence: `src/anaksor/detector.py`)
- Line detection → Box extraction: extracts boxes (evidence: `src/anaksor/detector.py`)
- Line detection → Crop geometry: uses geometry (evidence: `src/anaksor/detector.py`)
- Line detection → DBNet architectures: builds detector
- DBNet architectures → Backbone networks: uses backbone (evidence: `src/anaksor/nets/dbnet.py`)
- Backbone networks → Network layers: uses layers (evidence: `src/anaksor/nets/repvit.py`)
- Line detection → Inference fusion: fuses modules (evidence: `src/anaksor/detector.py`)
- OCR orchestration → Line recognition: recognizes crops (evidence: `src/anaksor/ocr.py`)
- Line recognition → Specs and weights: resolves weights (evidence: `src/anaksor/recognizer.py`)
- Line recognition → Inference backends: runs inference (evidence: `src/anaksor/recognizer.py`)
- Line recognition → Recognition decoding: decodes output (evidence: `src/anaksor/recognizer.py`)
- Line recognition → Khmer normalization: normalizes text (evidence: `src/anaksor/recognizer.py`)
- OCR orchestration → Long-line stitching: stitches long lines (evidence: `src/anaksor/ocr.py`)
- OCR orchestration → Reading-order layout: orders lines (evidence: `src/anaksor/ocr.py`)
- OCR orchestration → Crop geometry: crops lines (evidence: `src/anaksor/ocr.py`)
- OCR orchestration → OCR results: returns results (evidence: `src/anaksor/ocr.py`)
- OCR results → Searchable PDF: exports PDF (evidence: `README.md`)
- OCR results → Word export: exports Word (evidence: `README.md`)
- Browser user → Interactive demo: uploads pages (evidence: `README.md`)
- Interactive demo → Demo API client: requests OCR (evidence: `web/src/components/Demo.tsx`)
- Demo API client → OCR service: sends OCR request
- Interactive demo → Searchable PDF: requests export
- Browser user → Bilingual documentation: reads guides (evidence: `README.md`)
