# sriram-2090/ocr-features architecture

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

- Interactive diagram: https://gitdiagram.com/sriram-2090/ocr-features
- Repository: https://github.com/sriram-2090/ocr-features

## Overview

This repository digitizes cropped handwritten dates, postal PINs, and short codes, then routes results toward automated acceptance or operator review. Its principal workflow runs from a form image through segmentation, CNN character recognition, grammar and semantic correction, and confidence gating; the web interfaces expose predictions and review controls. The README also documents benchmark evaluation and model training. The graph reflects those documented capabilities; some server and UI internals were not sampled, so unsupported storage and dispatch details are omitted.

Main entry points: [`src/field_reader/pipeline.py`](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/pipeline.py) (Field reader pipeline), [`src/field_reader/dataset.py`](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/dataset.py) (Glyph dataset generator), [`evaluate_field_reader.py`](https://github.com/sriram-2090/ocr-features/blob/main/evaluate_field_reader.py) (Benchmark evaluation), [`web/js/app.js`](https://github.com/sriram-2090/ocr-features/blob/main/web/js/app.js) (Web operator UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Operator interfaces"]
  node_web_ui["Web operator UI<br/>[app.js]"]
  node_gradio_ui["Gradio interface"]
end

subgraph group_recognition["Recognition pipeline"]
  node_pipeline["Field reader pipeline<br/>[pipeline.py]"]
  node_segmenter["Glyph segmentation<br/>[segmenter.py]"]
  node_cnn["Character CNN<br/>[model.py]"]
  node_decoder["Grammar decoder<br/>[decoder.py]"]
  node_verifier["Semantic verifier"]
end

subgraph group_learning["Model preparation"]
  node_dataset["Glyph dataset generator<br/>[dataset.py]"]
  node_weights["CNN weights<br/>[field_cnn.pth]"]
end

subgraph group_operations["Serving and evaluation"]
  node_api["FastAPI service<br/>[server.py]"]
  node_benchmark["Benchmark evaluation"]
  node_fields["Benchmark field data<br/>[metadata.csv]"]
end

node_operator(("Form operator"))

node_operator -->|"uses"| node_web_ui
node_operator -->|"uses"| node_gradio_ui
node_web_ui -->|"requests predictions"| node_api
node_api -->|"processes fields"| node_pipeline
node_gradio_ui -->|"processes fields"| node_pipeline
node_pipeline -->|"segments glyphs"| node_segmenter
node_pipeline -->|"classifies glyphs"| node_cnn
node_pipeline -->|"decodes candidates"| node_decoder
node_pipeline -.->|"verifies semantics"| node_verifier
node_dataset -->|"normalizes training glyphs"| node_segmenter
node_dataset -->|"uses vocabulary"| node_cnn
node_benchmark -->|"evaluates modes"| node_pipeline
node_benchmark -->|"reads benchmark fields"| node_fields
node_pipeline -.->|"loads model weights"| node_weights

click node_web_ui "https://github.com/sriram-2090/ocr-features/blob/main/web/js/app.js"
click node_gradio_ui "https://github.com/sriram-2090/ocr-features/blob/main/ocr_standalone_app.py"
click node_api "https://github.com/sriram-2090/ocr-features/blob/main/server.py"
click node_pipeline "https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/pipeline.py"
click node_segmenter "https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/segmenter.py"
click node_cnn "https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/model.py"
click node_decoder "https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/decoder.py"
click node_verifier "https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/semantic_verifier.py"
click node_dataset "https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/dataset.py"
click node_benchmark "https://github.com/sriram-2090/ocr-features/blob/main/evaluate_field_reader.py"
click node_fields "https://github.com/sriram-2090/ocr-features/blob/main/data/form_fields/metadata.csv"
click node_weights "https://github.com/sriram-2090/ocr-features/blob/main/models/field_cnn.pth"

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_ui,node_gradio_ui toneBlue
class node_pipeline,node_segmenter,node_cnn,node_decoder,node_verifier toneAmber
class node_dataset,node_weights toneMint
class node_api,node_benchmark,node_fields toneRose
class node_operator toneIndigo
```

## Components

### Operator interfaces

- [Web operator UI](https://github.com/sriram-2090/ocr-features/blob/main/web/js/app.js): `web/js/app.js`
- [Gradio interface](https://github.com/sriram-2090/ocr-features/blob/main/ocr_standalone_app.py): `ocr_standalone_app.py`

### Recognition pipeline

- [Field reader pipeline](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/pipeline.py): `src/field_reader/pipeline.py`
- [Glyph segmentation](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/segmenter.py): `src/field_reader/segmenter.py`
- [Character CNN](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/model.py): `src/field_reader/model.py`
- [Grammar decoder](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/decoder.py): `src/field_reader/decoder.py`
- [Semantic verifier](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/semantic_verifier.py): `src/field_reader/semantic_verifier.py`

### Model preparation

- [Glyph dataset generator](https://github.com/sriram-2090/ocr-features/blob/main/src/field_reader/dataset.py): `src/field_reader/dataset.py`
- [CNN weights](https://github.com/sriram-2090/ocr-features/blob/main/models/field_cnn.pth): `models/field_cnn.pth`

### Serving and evaluation

- [FastAPI service](https://github.com/sriram-2090/ocr-features/blob/main/server.py): `server.py`
- [Benchmark evaluation](https://github.com/sriram-2090/ocr-features/blob/main/evaluate_field_reader.py): `evaluate_field_reader.py`
- [Benchmark field data](https://github.com/sriram-2090/ocr-features/blob/main/data/form_fields/metadata.csv): `data/form_fields/metadata.csv`

### Other components

- **Form operator**

## Connections

- Form operator → Web operator UI: uses (evidence: `web/js/app.js`)
- Form operator → Gradio interface: uses (evidence: `ocr_standalone_app.py`)
- Web operator UI → FastAPI service: requests predictions (evidence: `web/js/app.js`)
- FastAPI service → Field reader pipeline: processes fields (evidence: `server.py`)
- Gradio interface → Field reader pipeline: processes fields (evidence: `ocr_standalone_app.py`)
- Field reader pipeline → Glyph segmentation: segments glyphs (evidence: `src/field_reader/pipeline.py`)
- Field reader pipeline → Character CNN: classifies glyphs (evidence: `src/field_reader/pipeline.py`)
- Field reader pipeline → Grammar decoder: decodes candidates (evidence: `src/field_reader/pipeline.py`)
- Field reader pipeline → Semantic verifier: verifies semantics (evidence: `README.md`)
- Glyph dataset generator → Glyph segmentation: normalizes training glyphs (evidence: `src/field_reader/dataset.py`)
- Glyph dataset generator → Character CNN: uses vocabulary (evidence: `src/field_reader/dataset.py`)
- Benchmark evaluation → Field reader pipeline: evaluates modes (evidence: `evaluate_field_reader.py`)
- Benchmark evaluation → Benchmark field data: reads benchmark fields (evidence: `evaluate_field_reader.py`)
- Field reader pipeline → CNN weights: loads model weights (evidence: `README.md`)
