# yuta1984/ndlkotenocr-lite-web architecture

> Architecture diagram of the GitHub repository yuta1984/ndlkotenocr-lite-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuta1984/ndlkotenocr-lite-web
- Repository: https://github.com/yuta1984/ndlkotenocr-lite-web

## Overview

##### Project Type and Purpose
- This is a full-stack (in the sense of “frontend only”) single-page web application (SPA) that runs entirely in the browser.
- Purpose: perform OCR on classical Japanese books by detecting text regions and recognizing characters, all using ONNX models in WebAssembly.

##### Main Components
A. Client / Browser Environment
– HTML5/CSS/Canvas (index.html + Canvas API)
– JavaScript runtime + ONNX Runtime Web (WASM backend)
B. Application Logic (bundled by Webpack)
1. index.js (orchestrator / entry point)
2. layout-detector.js (text-region detection using RTMDet ONNX model)
3. reading-order.js (computes proper reading order for Japanese text blocks)
4. text-recognizer.js (character recognizer using Parseq NDL ONNX model)
5. output-generator.js (formats results into XML/JSON/TXT)
C. Machine-Learning Assets
– ONNX models in models/
- rtmdet-s-1280x1280.onnx
- parseq-ndl-32x384-tiny-10.onnx
D. Configuration
– YAML files in config/ for model parameters, thresholds, language specifics
E. Build & Deployment
– Webpack config + local dev server (npm start → localhost:9000)
– Static hosting (e.g., Netlify)

##### Data-flow & Interaction
1. User opens the page (index.html) → Webpack-bundled JS loads.
2. index.js initializes ONNX Runtime Web (WASM) and loads the two ONNX models over HTTP.
3. User supplies an image → drawn to HTML5 Canvas.
6. For each region: text-recognizer.js extracts the sub-image, runs parseq-ndl model in ONNXRuntime Web → yields recognized text.
8. Or download results.

##### Architectural Patterns & Principles
- Modular pipeline: each stage is an independent module with a defined input/output.
- Separation of concerns: detection, ordering, recognition, and output formatting are separate.
- Client-side inference: all ML runs in the browser (ONNX + WASM) → no server.
- Bundler-driven deployment: Webpack assembles code, assets, and models into static files.

– Clear component labels (e.g., “layout-detector.js”)
– Notes on any external dependencies (e.g., ONNX model download over HTTP)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Flow
    A["User opens Web Page: index.html + Canvas UI"]:::ui
    click A "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/index.html"
    B["App Orchestrator (src/index.js)"]:::ui
    click B "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/src/index.js"
    A -->|"loads JS bundle"| B

    B --> C["Layout Detector (src/layout-detector.js)"]:::ml
    click C "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/src/layout-detector.js"
    C -->|"BoundingBoxes"| D["Reading Order (src/reading-order.js)"]:::ml
    click D "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/src/reading-order.js"
    D -->|"OrderedBoxes"| E["Text Recognizer (src/text-recognizer.js)"]:::ml
    click E "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/src/text-recognizer.js"
    E -->|"RecognizedText"| F["Output Generator (src/output-generator.js)"]:::ui
    click F "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/src/output-generator.js"
    F -->|"XML/JSON/TXT"| G["Results: XML/JSON/TXT"]:::data

    %% ONNX Runtime and Models
    H["ONNX Runtime Web (WASM)"]:::ml
    I["rtmdet-s-1280x1280.onnx"]:::config
    click I "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/models/rtmdet-s-1280x1280.onnx"
    J["parseq-ndl-32x384-tiny-10.onnx"]:::config
    click J "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/models/parseq-ndl-32x384-tiny-10.onnx"

    I --> H
    J --> H
    H -.-> C
    H -.-> E

    %% Configuration Files
    K1["NDLmoji.yaml"]:::config
    click K1 "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/config/NDLmoji.yaml"
    K2["ndl.yaml"]:::config
    click K2 "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/config/ndl.yaml"

    K1 -.-> C
    K2 -.-> E

    %% Build & Deployment
    L["webpack.config.js"]:::data
    click L "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/webpack.config.js"
    M["package.json"]:::data
    click M "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/package.json"
    N["public/"]:::data
    click N "https://github.com/yuta1984/ndlkotenocr-lite-web/tree/main/public/"
    O["README.md"]:::data
    click O "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/README.md"
    P[".gitignore"]:::data
    click P "https://github.com/yuta1984/ndlkotenocr-lite-web/blob/main/.gitignore"

    L -.-> B
    M -.-> B
    N -.-> A
    O -.-> A
    P -.-> B

    %% Legend
    subgraph Legend
        UI_LEG["UI Components"]:::ui
        ML_LEG["ML Engine/Modules"]:::ml
        CFG_LEG["Config/Models"]:::config
        DAT_LEG["Data/Outputs"]:::data
    end

    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef ml fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef config fill:#FFD580,stroke:#000,stroke-width:1px;
    classDef data fill:#F0E68C,stroke:#000,stroke-width:1px;
```
