# charlesw/tesseract-samples architecture

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

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

## Overview

1. **Repository purpose**
   - This is a sample solution for the **Tesseract .NET Wrapper** showing two ways to invoke OCR: a **console app** and an **ASP.NET Web Forms app**.

2. **Top-level architecture**
   - The solution is split into two independent demos under `src/`:
     - `Tesseract.ConsoleDemo`
     - `Tesseract.WebDemo`
   - There is no shared application project in the tree; both samples appear to exercise the same external Tesseract OCR library directly from their own host process.

3. **Core OCR boundary**
   - The important architectural boundary is between the **host application** and the **OCR engine/runtime**.
   - Each demo depends on a local `tessdata/eng.traineddata` language model directory, which is required at runtime for recognition.
   - The README notes that each image processing operation creates a new `TesseractEngine` instance, emphasizing that OCR initialization is expensive and separate from UI logic.

4. **Console demo flow**
   - `Program.cs` in `Tesseract.ConsoleDemo` is a minimal command-line entry point.
   - It reads the bundled sample image `phototest.tif`, runs OCR, and prints the results to stdout.
   - The README says it demonstrates both `Page.GetText()` and iteration over recognition results, so this sample is focused on API usage and output formatting rather than user interaction.

5. **Web demo flow**
   - `Tesseract.WebDemo` is a classic **ASP.NET Web Forms** application.
   - The main request path is centered on `Default.aspx` and its code-behind `Default.aspx.cs`, with app startup handled by `Global.asax`.
   - The demo processes an image from within the web UI and returns OCR results to the browser.

6. **Web UI and static assets**
   - The web sample includes local copies of **Bootstrap** and **jQuery** under `Content/` and `Scripts/`.
   - These assets are presentation-only; they support the page layout and client-side behavior but do not affect the OCR pipeline.

7. **Configuration and hosting**
   - `Web.config` and `packages.config` indicate the web sample is built on the older .NET Framework / NuGet stack typical of Web Forms applications.
   - `AssemblyInfo.cs` and the `.csproj` files define the application boundaries and build metadata for each sample.

8. **Runtime inputs and packaged assets**
   - Both demos carry their own local OCR assets in `tessdata/eng.traineddata`.
   - The console sample also includes a fixed test image (`phototest.tif`), making it a self-contained reproducible OCR run.
   - This means the samples are designed to run without depending on remote services or external asset downloads at runtime.

9. **Data flow summary**
   - For both apps, the flow is:
     - host process starts
     - OCR engine is constructed
     - image is loaded
     - OCR result is produced from the local language data
     - text is rendered to console or browser
   - The key runtime dependency is the Tesseract engine plus language data; the host merely orchestrates input and output.

10. **Architectural takeaway**
   - The solution is primarily a **sample-host architecture**: thin UI/entry-point layers around an OCR library.
   - If you were drawing it, the main boxes would be:
     - Console host
     - Web Forms host
     - Tesseract OCR engine/library
     - local `tessdata` language files
     - sample image/UI assets
   - The demos differ only in their presentation layer; the OCR subsystem is the shared conceptual core.

Main entry points: [`src/Tesseract.WebDemo/Default.aspx`](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Default.aspx) (Default page), [`src/Tesseract.WebDemo/Tesseract.WebDemo.csproj`](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Tesseract.WebDemo.csproj) (Web demo), [`src/Tesseract.ConsoleDemo/Program.cs`](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/Program.cs) (Program), [`src/Tesseract.WebDemo/Default.aspx.cs`](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Default.aspx.cs) (Page code)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_solution["Solution"]
  node_node_solution["Samples.sln<br/>solution"]
end

subgraph group_grp_console["Console demo"]
  node_node_console_proj["Console demo<br/>app project"]
  node_node_console_main["Program<br/>entrypoint<br/>[Program.cs]"]
  node_node_console_image["Test image<br/>sample asset<br/>[phototest.tif]"]
  node_node_console_lang["Lang data<br/>ocr data<br/>[eng.traineddata]"]
  node_node_console_engine{{"Tesseract engine<br/>ocr runtime"}}
end

subgraph group_grp_web["Web demo"]
  node_node_web_proj["Web demo<br/>web app project"]
  node_node_web_page["Default page<br/>web form<br/>[Default.aspx]"]
  node_node_web_code["Page code<br/>code-behind<br/>[Default.aspx.cs]"]
  node_node_web_startup["Global<br/>app startup<br/>[Global.asax]"]
  node_node_web_config["Web config<br/>[Web.config]"]
  node_node_web_lang["Lang data<br/>ocr data<br/>[eng.traineddata]"]
  node_node_web_engine{{"Tesseract engine<br/>ocr runtime"}}
  node_node_bootstrap["Bootstrap<br/>ui assets<br/>[bootstrap.css]"]
  node_node_jquery["jQuery<br/>ui assets<br/>[jquery-3.6.1.js]"]
end

node_node_solution -->|"includes"| node_node_console_proj
node_node_solution -->|"includes"| node_node_web_proj
node_node_console_proj -->|"starts at"| node_node_console_main
node_node_console_main -->|"reads"| node_node_console_image
node_node_console_main -->|"creates"| node_node_console_engine
node_node_console_engine -->|"uses"| node_node_console_lang
node_node_console_engine -->|"processes"| node_node_console_image
node_node_web_proj -->|"boots via"| node_node_web_startup
node_node_web_proj -->|"serves"| node_node_web_page
node_node_web_page -->|"backed by"| node_node_web_code
node_node_web_code -->|"creates"| node_node_web_engine
node_node_web_engine -->|"uses"| node_node_web_lang
node_node_web_code -->|"renders to"| node_node_web_page
node_node_web_proj -->|"configured by"| node_node_web_config
node_node_web_page -->|"styles with"| node_node_bootstrap
node_node_web_page -->|"scripts with"| node_node_jquery

click node_node_solution "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.Samples.sln"
click node_node_console_proj "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/Tesseract.ConsoleDemo.csproj"
click node_node_console_main "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/Program.cs"
click node_node_console_image "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/phototest.tif"
click node_node_console_lang "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/tessdata/eng.traineddata"
click node_node_web_proj "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Tesseract.WebDemo.csproj"
click node_node_web_page "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Default.aspx"
click node_node_web_code "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Default.aspx.cs"
click node_node_web_startup "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Global.asax"
click node_node_web_config "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Web.config"
click node_node_web_lang "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/tessdata/eng.traineddata"
click node_node_bootstrap "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Content/bootstrap.css"
click node_node_jquery "https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Scripts/jquery-3.6.1.js"

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_node_solution toneBlue
class node_node_console_proj,node_node_console_main,node_node_console_image,node_node_console_lang,node_node_console_engine toneAmber
class node_node_web_proj,node_node_web_page,node_node_web_code,node_node_web_startup,node_node_web_config,node_node_web_lang,node_node_web_engine,node_node_bootstrap,node_node_jquery toneMint
```

## Components

### Solution

Repository-level entry points and sample apps

- [Samples.sln](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.Samples.sln): solution · Visual Studio solution for both demos · `src/Tesseract.Samples.sln`

### Console demo

Command-line OCR sample and its bundled inputs

- [Console demo](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/Tesseract.ConsoleDemo.csproj): app project · Console host for OCR sample · `src/Tesseract.ConsoleDemo/Tesseract.ConsoleDemo.csproj`
- [Program](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/Program.cs): entrypoint · Minimal command-line OCR flow · `src/Tesseract.ConsoleDemo/Program.cs`
- [Test image](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/phototest.tif): sample asset · Bundled input image for OCR · `src/Tesseract.ConsoleDemo/phototest.tif`
- [Lang data](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.ConsoleDemo/tessdata/eng.traineddata): ocr data · Local English language model · `src/Tesseract.ConsoleDemo/tessdata/eng.traineddata`
- **Tesseract engine**: ocr runtime · OCR engine created per run

### Web demo

ASP.NET Web Forms OCR sample and presentation assets

- [Web demo](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Tesseract.WebDemo.csproj): web app project · ASP.NET Web Forms OCR host · `src/Tesseract.WebDemo/Tesseract.WebDemo.csproj`
- [Default page](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Default.aspx): web form · Main browser-facing OCR UI · `src/Tesseract.WebDemo/Default.aspx`
- [Page code](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Default.aspx.cs): code-behind · Request handling and OCR orchestration · `src/Tesseract.WebDemo/Default.aspx.cs`
- [Global](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Global.asax): app startup · Web application startup hooks · `src/Tesseract.WebDemo/Global.asax`
- [Web config](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Web.config): config · ASP.NET hosting and app settings · `src/Tesseract.WebDemo/Web.config`
- [Lang data](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/tessdata/eng.traineddata): ocr data · Local English language model · `src/Tesseract.WebDemo/tessdata/eng.traineddata`
- **Tesseract engine**: ocr runtime · OCR engine created per request or image action
- [Bootstrap](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Content/bootstrap.css): ui assets · Local CSS and JS for page styling · `src/Tesseract.WebDemo/Content/bootstrap.css`
- [jQuery](https://github.com/charlesw/tesseract-samples/blob/master/src/Tesseract.WebDemo/Scripts/jquery-3.6.1.js): ui assets · Local client-side library for the web sample · `src/Tesseract.WebDemo/Scripts/jquery-3.6.1.js`

## Connections

- Samples.sln → Console demo: includes · Solution contains console sample
- Samples.sln → Web demo: includes · Solution contains web sample
- Console demo → Program: starts at · Project compiles to command-line entry point
- Program → Test image: reads · Loads bundled image for OCR
- Program → Tesseract engine: creates · Constructs OCR engine for work
- Tesseract engine → Lang data: uses · Requires local language data
- Tesseract engine → Test image: processes · Recognizes text from input image
- Web demo → Global: boots via · Web app initialization
- Web demo → Default page: serves · Main browser entry page
- Default page → Page code: backed by · Code-behind handles page behavior
- Page code → Tesseract engine: creates · Constructs OCR engine for requests
- Tesseract engine → Lang data: uses · Requires local language data
- Page code → Default page: renders to · Returns OCR output to browser
- Web demo → Web config: configured by · Hosting and framework settings
- Default page → Bootstrap: styles with · Presentation assets for layout
- Default page → jQuery: scripts with · Client-side helper library
