# sahacha/chamomind-ocr architecture

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

- Interactive diagram: https://gitdiagram.com/sahacha/chamomind-ocr
- Repository: https://github.com/sahacha/chamomind-ocr

## Overview

##### Main Components
a. Core Orchestrator:
- main.py: Likely the entry point that ties all the components together.
b. OCR Engine:
- ocr_engine.py: The module that probably conducts the core text recognition operations.
c. Preprocessing/Processing Modules:
- image_processing.py: Likely handles image preprocessing (e.g., filtering, resizing, adjustments) to prepare images for OCR.
- document_processing.py: Likely responsible for processing documents post-OCR (such as formatting, post-processing text, or extracting structured fields).
- anylabel_utils.py: Might handle label interpretation, utility functions for managing or annotating images/documents.
d. Evaluation and Utilities:
- eval.py: Seems to be an evaluation module – maybe to assess OCR accuracy or compare outputs.
- utils.py: General-purpose helper functions used across the project.
e. Supporting Data:
- field_positions folder with a CSV file (juris_record_fields_manual_backup.csv): Indicates that specific fields or positions are predefined (perhaps for form processing or region-based OCR extraction).
- font folder: This might supply custom fonts that are used either both for rendering or for analysis aspects in the OCR process.
f. Dependency Management:
- requirements.txt: Contains Python library dependencies needed for the application.
g. Configuration/Version Control:
- .gitignore: Ensures proper version control hygiene by excluding unnecessary files.

##### Relationships and Interactions
- The main.py file serves as the orchestrator, triggering the overall workflow.
- Input images or documents come into the system (likely provided externally) and first pass through image_processing.py for necessary pre-OCR adjustments.
- The processed data may then be passed to the ocr_engine.py, which extracts textual information.
- Document_processing.py and anylabel_utils.py can then process or annotate the recognized text, possibly cross-referencing the CSV-based field positions.
- Post extraction, eval.py can be used to perform evaluations of the OCR accuracy.
- Shared functions and helper routines reside in utils.py.

##### Architectural Patterns & Design Principles
- Modularity: Each major concern (image preprocessing, OCR, post-processing/evaluation) has its dedicated module. Emphasize clear interface definitions between modules.
- Separation of concerns: By separating the OCR engine from preprocessing and evaluation, you make the system easier to extend or modify.
- Data-driven configuration: Field positions (CSV) and fonts are externalized, which suggests the system is designed to be adaptable to multiple document formats.

##### Technologies and Frameworks
- While the specific libraries aren’t listed, the requirements.txt file will list the necessary Python packages (likely image processing libraries like OpenCV or PIL, OCR libraries like Tesseract, or machine learning frameworks).
- The code structure suggests that standard Python libraries are used alongside specialized OCR tools.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Orchestration Layer
    subgraph "Orchestration"
        M["Main Controller (main.py)"]:::orchestrator
    end

    %% Workflow Layer
    subgraph "Workflow"
        Input["Input: Image/Document"]:::input
        IP["Image Preprocessing (image_processing.py)"]:::process
        OCR["OCR Engine (ocr_engine.py)"]:::process
        DP["Document Post-Processing (document_processing.py)"]:::process
        EV["Evaluation (eval.py)"]:::process
    end

    %% Supporting Modules
    subgraph "Supporting Modules"
        U1["Utility Module (anylabel_utils.py)"]:::utility
        U2["Utility Module (utils.py)"]:::utility
        FD["Field Positions (CSV)"]:::data
        F["Fonts Resource"]:::data
    end

    %% Configuration/Dependency Layer
    subgraph "Configuration"
        DEP["Dependencies (requirements.txt)"]:::config
        GIT["Version Control (.gitignore)"]:::config
    end

    %% Main Workflow Data Flow
    M -->|"triggers"| Input
    Input -->|"preprocesses"| IP
    IP -->|"passesData"| OCR
    OCR -->|"extractsText"| DP
    DP -->|"evaluates"| EV

    %% Orchestrator coordination (dashed lines)
    M --- IP
    M --- OCR
    M --- DP
    M --- EV

    %% Utility Modules support
    U1 --- DP
    U1 --- EV
    U2 --- DP
    U2 --- EV

    %% Supporting Data Flow
    FD -->|"configures"| DP
    F -->|"supports"| OCR

    %% Click Events
    click M "https://github.com/sahacha/chamomind-ocr/blob/main/main.py"
    click IP "https://github.com/sahacha/chamomind-ocr/blob/main/image_processing.py"
    click OCR "https://github.com/sahacha/chamomind-ocr/blob/main/ocr_engine.py"
    click DP "https://github.com/sahacha/chamomind-ocr/blob/main/document_processing.py"
    click EV "https://github.com/sahacha/chamomind-ocr/blob/main/eval.py"
    click U1 "https://github.com/sahacha/chamomind-ocr/blob/main/anylabel_utils.py"
    click U2 "https://github.com/sahacha/chamomind-ocr/blob/main/utils.py"
    click FD "https://github.com/sahacha/chamomind-ocr/blob/main/field_positions/juris_record_fields_manual_backup.csv"
    click F "https://github.com/sahacha/chamomind-ocr/tree/main/font"
    click DEP "https://github.com/sahacha/chamomind-ocr/blob/main/requirements.txt"
    click GIT "https://github.com/sahacha/chamomind-ocr/blob/main/.gitignore"

    %% Styles
    classDef orchestrator fill:#f9d5e5,stroke:#e85a71,stroke-width:2px;
    classDef process fill:#cce5ff,stroke:#1a75ff,stroke-width:2px;
    classDef input fill:#d5f5e3,stroke:#28a745,stroke-width:2px;
    classDef utility fill:#fff3cd,stroke:#ffcc00,stroke-width:2px;
    classDef data fill:#fef9e7,stroke:#f39c12,stroke-width:2px,stroke-dasharray:5,5;
    classDef config fill:#e8daef,stroke:#8e44ad,stroke-width:2px,stroke-dasharray:3,3;
```
