# charlesw/tesseract architecture

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

- Interactive diagram: https://gitdiagram.com/charlesw/tesseract
- Repository: https://github.com/charlesw/tesseract

## Overview

##### Project type and purpose
- This is an open‑source .NET library (wrapper) around the native Tesseract‑OCR and Leptonica libraries.
- Its purpose is to expose OCR functionality to .NET applications via managed classes and dynamic interop.

##### File structure
- Top‑level folders:
– src/Tesseract: the core managed API, engine config, data types, result rendering, P/Invoke definitions.
– src/Tesseract/Internal/InteropDotNet + src/Tesseract/Interop: dynamic loader and low‑level bindings to native libraries.
– src/Tesseract/x64 and x86: ship native tesseract.exe and required DLLs for each architecture.
– src/Tesseract.Drawing: an optional extension assembly for System.Drawing interop.
– src/Tesseract.*Tests: multiple test projects targeting .NET Framework 4.8 and .NET Core 3.1, holding test data and integration suites.
– docs: build & usage guides.
– CI and packaging files (.github/workflows, nuspec, .csproj, etc.).

##### README for additional insights
- Confirms the binary dependencies (VS 2019 runtime, tessdata language files).
- Notes that it is delivered via NuGet (“Tesseract” and optional “Tesseract.Drawing”).
- References InteropDotNet dynamic interop system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer Layer
    ConsumerApp["Consumer Application\n(.NET App)"]:::consumer

    %% Managed API Layer
    subgraph "Managed API Assembly" 
        direction TB
        TesseractEngine["TesseractEngine\nsrc/Tesseract/TesseractEngine.cs"]:::managed
        PageIterator["PageIterator\nsrc/Tesseract/PageIterator.cs"]:::managed
        ResultRenderer["ResultRenderer\nsrc/Tesseract/ResultRenderer.cs"]:::managed
    end

    %% Optional Drawing Extension
    DrawingExt["Tesseract.Drawing.dll\nsrc/Tesseract.Drawing/Tesseract.Drawing.csproj"]:::managed

    %% Interop Layer
    subgraph "Interop Layer"
        direction TB
        subgraph "Dynamic Loader (InteropDotNet)"
            direction TB
            ILibraryLoaderLogic["ILibraryLoaderLogic.cs"]:::managed
            InteropRuntimeImplementer["InteropRuntimeImplementer.cs"]:::managed
            LibraryLoader["LibraryLoader.cs"]:::managed
            RuntimeDllImportAttribute["RuntimeDllImportAttribute.cs"]:::managed
            SystemManager["SystemManager.cs"]:::managed
            UnixLibraryLoaderLogic["UnixLibraryLoaderLogic.cs"]:::managed
            WindowsLibraryLoaderLogic["WindowsLibraryLoaderLogic.cs"]:::managed
        end
        subgraph "P/Invoke Definitions"
            direction TB
            BaseApi["BaseApi.cs"]:::managed
            LeptonicaApi["LeptonicaApi.cs"]:::managed
            Constants["Constants.cs"]:::managed
            HostProcessInfo["HostProcessInfo.cs"]:::managed
            MarshalHelper["MarshalHelper.cs"]:::managed
        end
    end

    %% Native Binaries
    subgraph "Native Binaries"
        direction TB
        X64Exe["x64/tesseract.exe"]:::native
        X86Exe["x86/tesseract.exe"]:::native
    end

    %% Data Layer
    TessData["tessdata\nsrc/Tesseract.Tests/tessdata"]:::data

    %% Test Harness
    subgraph "Test Harness"
        direction TB
        Net48Tests[".NET Framework 4.8 Tests\nsrc/Tesseract.Net48Tests"]:::tests
        NetCore31Tests[".NET Core 3.1 Tests\nsrc/Tesseract.NetCore31Tests"]:::tests
        subgraph "Core Test Suite"
            direction TB
            EngineTests["EngineTests.cs"]:::tests
            BaseApiTests["BaseApiTests.cs"]:::tests
            AnalyseResultTests["AnalyseResultTests.cs"]:::tests
            LeptonicaTests["Leptonica Tests\nsrc/Tesseract.Tests/Leptonica"]:::tests
            ResultRendererTests["ResultRendererTests.cs"]:::tests
            ResultIteratorTests["ResultIteratorTests.cs"]:::tests
        end
    end

    %% CI & Packaging
    subgraph "CI & Packaging"
        direction TB
        CIWorkflow["ci.yml\n.github/workflows/ci.yml"]:::ci
        NuGetProj["Tesseract.csproj\nsrc/Tesseract/Tesseract.csproj"]:::ci
        NuGetTargets["Tesseract.targets\nsrc/Tesseract/Tesseract.targets"]:::ci
        SolutionFile["Tesseract.sln\nsrc/Tesseract.sln"]:::ci
    end

    %% Relationships
    ConsumerApp -->|"references"| TesseractEngine
    ConsumerApp -->|"references (optional)"| DrawingExt
    TesseractEngine -->|"calls"| ILibraryLoaderLogic
    TesseractEngine -->|"calls"| BaseApi
    PageIterator --> BaseApi
    ResultRenderer --> BaseApi
    ILibraryLoaderLogic -->|"loads"| X64Exe
    ILibraryLoaderLogic -->|"loads"| X86Exe
    BaseApi -->|"invokes"| X64Exe
    BaseApi -->|"invokes"| X86Exe
    X64Exe -->|"loads data"| TessData
    X86Exe -->|"loads data"| TessData
    ILibraryLoaderLogic <-->|"bitmap↔pix conversion"| DrawingExt
    Net48Tests --> TesseractEngine
    NetCore31Tests --> TesseractEngine
    EngineTests --> TesseractEngine
    BaseApiTests --> BaseApi
    AnalyseResultTests --> ResultRenderer
    LeptonicaTests --> LeptonicaApi
    ResultRendererTests --> ResultRenderer
    ResultIteratorTests --> PageIterator

    %% Click Events
    click TesseractEngine "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/TesseractEngine.cs"
    click PageIterator "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/PageIterator.cs"
    click ResultRenderer "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/ResultRenderer.cs"
    click DrawingExt "https://github.com/charlesw/tesseract/blob/master/src/Tesseract.Drawing/Tesseract.Drawing.csproj"
    click ILibraryLoaderLogic "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Internal/InteropDotNet/ILibraryLoaderLogic.cs"
    click InteropRuntimeImplementer "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Internal/InteropDotNet/InteropRuntimeImplementer.cs"
    click LibraryLoader "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Internal/InteropDotNet/LibraryLoader.cs"
    click RuntimeDllImportAttribute "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Internal/InteropDotNet/RuntimeDllImportAttribute.cs"
    click SystemManager "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Internal/InteropDotNet/SystemManager.cs"
    click UnixLibraryLoaderLogic "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Internal/InteropDotNet/UnixLibraryLoaderLogic.cs"
    click WindowsLibraryLoaderLogic "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Internal/InteropDotNet/WindowsLibraryLoaderLogic.cs"
    click BaseApi "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Interop/BaseApi.cs"
    click LeptonicaApi "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Interop/LeptonicaApi.cs"
    click Constants "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Interop/Constants.cs"
    click HostProcessInfo "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Interop/HostProcessInfo.cs"
    click MarshalHelper "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Interop/MarshalHelper.cs"
    click X64Exe "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/x64/tesseract.exe"
    click X86Exe "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/x86/tesseract.exe"
    click TessData "https://github.com/charlesw/tesseract/tree/master/src/Tesseract.Tests/tessdata"
    click Net48Tests "https://github.com/charlesw/tesseract/blob/master/src/Tesseract.Net48Tests"
    click NetCore31Tests "https://github.com/charlesw/tesseract/blob/master/src/Tesseract.NetCore31Tests"
    click LeptonicaTests "https://github.com/charlesw/tesseract/tree/master/src/Tesseract.Tests/Leptonica"
    click CIWorkflow "https://github.com/charlesw/tesseract/blob/master/.github/workflows/ci.yml"
    click NuGetProj "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Tesseract.csproj"
    click NuGetTargets "https://github.com/charlesw/tesseract/blob/master/src/Tesseract/Tesseract.targets"
    click SolutionFile "https://github.com/charlesw/tesseract/blob/master/src/Tesseract.sln"

    %% Styles
    classDef managed fill:#cce5ff,stroke:#2b6cb0
    classDef native fill:#c6f6d5,stroke:#2f855a
    classDef data fill:#faf089,stroke:#d69e2e
    classDef tests fill:#e2e8f0,stroke:#4a5568
    classDef ci fill:#fefcbf,stroke:#d69e2e
    classDef consumer fill:#f0fff4,stroke:#38a169
```
