# sml2h3/ddddocr architecture

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

- Interactive diagram: https://gitdiagram.com/sml2h3/ddddocr
- Repository: https://github.com/sml2h3/ddddocr

## Overview

DdddOcr is an offline CAPTCHA-recognition SDK with OCR, object detection, and slider matching, also exposed through an optional HTTP/MCP API. The main workflow is image input through the SDK or API, mode dispatch, image/model processing, and a recognition result. The graph includes the documented custom-model and preprocessing capabilities. Relationships are limited to README statements and source-index references; unsampled API and helper implementations are represented conservatively.

Main entry points: [`ddddocr/core/ocr_engine.py`](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/ocr_engine.py) (OCR engine), [`ddddocr/utils/image_io.py`](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/image_io.py) (Image I/O), [`ddddocr/utils/validators.py`](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/validators.py) (Input validators), [`ddddocr/compat/v1.py`](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/compat/v1.py) (SDK facade)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Interfaces"]
  node_compat["SDK facade<br/>[v1.py]"]
  node_api_app["HTTP endpoints<br/>[app.py]"]
  node_api_models["API schemas<br/>[models.py]"]
  node_api_routes["API routes<br/>[routes.py]"]
  node_mcp["MCP interface<br/>[mcp.py]"]
  node_api_server["API server<br/>[server.py]"]
end

subgraph group_engines["Recognition engines"]
  node_ocr["OCR engine<br/>[ocr_engine.py]"]
  node_detection["Detection engine"]
  node_slider["Slider engine<br/>[slide_engine.py]"]
  node_base["Engine base<br/>[base.py]"]
end

subgraph group_models["Models and character data"]
  node_model_loader["Model loader<br/>[model_loader.py]"]
  node_charset["Charset manager<br/>[charset_manager.py]"]
end

subgraph group_images["Image processing"]
  node_image_processor["Image processor<br/>[image_processor.py]"]
  node_color_filter["Color filter<br/>[color_filter.py]"]
end

subgraph group_support["Shared support"]
  node_image_io["Image I/O<br/>[image_io.py]"]
  node_validators["Input validators<br/>[validators.py]"]
  node_exceptions["Errors and imports<br/>[exceptions.py]"]
end

node_user(("SDK/API caller"))

node_user -->|"calls SDK"| node_compat
node_user -->|"sends requests"| node_api_app
node_compat -->|"dispatches OCR"| node_ocr
node_compat -->|"dispatches detection"| node_detection
node_compat -->|"dispatches slider"| node_slider
node_api_server -->|"serves app"| node_api_app
node_api_server -->|"uses routes"| node_api_routes
node_api_server -->|"uses MCP"| node_mcp
node_api_routes -->|"uses schemas"| node_api_models
node_api_app -->|"invokes SDK"| node_compat
node_ocr -->|"inherits from"| node_base
node_detection -->|"inherits from"| node_base
node_ocr -->|"loads models"| node_model_loader
node_base -->|"creates loader"| node_model_loader
node_ocr -->|"uses charset"| node_charset
node_ocr -->|"preprocesses image"| node_image_processor
node_ocr -->|"filters colors"| node_color_filter
node_ocr -->|"loads image"| node_image_io
node_detection -->|"loads image"| node_image_io
node_slider -->|"loads images"| node_image_io
node_detection -->|"validates input"| node_validators
node_ocr -->|"validates input"| node_validators
node_slider -->|"validates input"| node_validators
node_model_loader -->|"validates config"| node_validators
node_charset -->|"validates ranges"| node_validators
node_color_filter -->|"converts images"| node_image_io
node_image_processor -->|"converts images"| node_image_io
node_image_io -->|"raises errors"| node_exceptions
node_validators -->|"raises errors"| node_exceptions
node_model_loader -->|"raises errors"| node_exceptions

click node_compat "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/compat/v1.py"
click node_api_app "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/app.py"
click node_api_models "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/models.py"
click node_api_routes "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/routes.py"
click node_mcp "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/mcp.py"
click node_api_server "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/server.py"
click node_ocr "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/ocr_engine.py"
click node_detection "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/detection_engine.py"
click node_slider "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/slide_engine.py"
click node_base "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/base.py"
click node_model_loader "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/models/model_loader.py"
click node_charset "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/models/charset_manager.py"
click node_image_processor "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/preprocessing/image_processor.py"
click node_color_filter "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/preprocessing/color_filter.py"
click node_image_io "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/image_io.py"
click node_validators "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/validators.py"
click node_exceptions "https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/exceptions.py"

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_compat,node_api_app,node_api_models,node_api_routes,node_mcp,node_api_server toneBlue
class node_ocr,node_detection,node_slider,node_base toneAmber
class node_model_loader,node_charset,node_user toneMint
class node_image_processor,node_color_filter toneRose
class node_image_io,node_validators,node_exceptions toneIndigo
```

## Components

### Interfaces

- [SDK facade](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/compat/v1.py): `ddddocr/compat/v1.py`
- [HTTP endpoints](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/app.py): `ddddocr/api/app.py`
- [API schemas](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/models.py): `ddddocr/api/models.py`
- [API routes](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/routes.py): `ddddocr/api/routes.py`
- [MCP interface](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/mcp.py): `ddddocr/api/mcp.py`
- [API server](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/api/server.py): `ddddocr/api/server.py`

### Recognition engines

- [OCR engine](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/ocr_engine.py): `ddddocr/core/ocr_engine.py`
- [Detection engine](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/detection_engine.py): `ddddocr/core/detection_engine.py`
- [Slider engine](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/slide_engine.py): `ddddocr/core/slide_engine.py`
- [Engine base](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/core/base.py): `ddddocr/core/base.py`

### Models and character data

- [Model loader](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/models/model_loader.py): `ddddocr/models/model_loader.py`
- [Charset manager](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/models/charset_manager.py): `ddddocr/models/charset_manager.py`

### Image processing

- [Image processor](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/preprocessing/image_processor.py): `ddddocr/preprocessing/image_processor.py`
- [Color filter](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/preprocessing/color_filter.py): `ddddocr/preprocessing/color_filter.py`

### Shared support

- [Image I/O](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/image_io.py): `ddddocr/utils/image_io.py`
- [Input validators](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/validators.py): `ddddocr/utils/validators.py`
- [Errors and imports](https://github.com/sml2h3/ddddocr/blob/master/ddddocr/utils/exceptions.py): `ddddocr/utils/exceptions.py`

### Other components

- **SDK/API caller**

## Connections

- SDK/API caller → SDK facade: calls SDK (evidence: `README.md`)
- SDK/API caller → HTTP endpoints: sends requests (evidence: `README.md`)
- SDK facade → OCR engine: dispatches OCR (evidence: `ddddocr/compat/v1.py`)
- SDK facade → Detection engine: dispatches detection (evidence: `ddddocr/compat/v1.py`)
- SDK facade → Slider engine: dispatches slider (evidence: `ddddocr/compat/v1.py`)
- API server → HTTP endpoints: serves app (evidence: `ddddocr/api/server.py`)
- API server → API routes: uses routes (evidence: `ddddocr/api/server.py`)
- API server → MCP interface: uses MCP (evidence: `ddddocr/api/server.py`)
- API routes → API schemas: uses schemas (evidence: `ddddocr/api/routes.py`)
- HTTP endpoints → SDK facade: invokes SDK (evidence: `ddddocr/api/app.py`)
- OCR engine → Engine base: inherits from (evidence: `ddddocr/core/ocr_engine.py`)
- Detection engine → Engine base: inherits from (evidence: `ddddocr/core/detection_engine.py`)
- OCR engine → Model loader: loads models (evidence: `ddddocr/core/ocr_engine.py`)
- Engine base → Model loader: creates loader (evidence: `ddddocr/core/base.py`)
- OCR engine → Charset manager: uses charset (evidence: `ddddocr/core/ocr_engine.py`)
- OCR engine → Image processor: preprocesses image (evidence: `ddddocr/core/ocr_engine.py`)
- OCR engine → Color filter: filters colors (evidence: `ddddocr/core/ocr_engine.py`)
- OCR engine → Image I/O: loads image (evidence: `ddddocr/core/ocr_engine.py`)
- Detection engine → Image I/O: loads image (evidence: `ddddocr/core/detection_engine.py`)
- Slider engine → Image I/O: loads images (evidence: `ddddocr/core/slide_engine.py`)
- Detection engine → Input validators: validates input (evidence: `ddddocr/core/detection_engine.py`)
- OCR engine → Input validators: validates input (evidence: `ddddocr/core/ocr_engine.py`)
- Slider engine → Input validators: validates input (evidence: `ddddocr/core/slide_engine.py`)
- Model loader → Input validators: validates config (evidence: `ddddocr/models/model_loader.py`)
- Charset manager → Input validators: validates ranges (evidence: `ddddocr/models/charset_manager.py`)
- Color filter → Image I/O: converts images (evidence: `ddddocr/preprocessing/color_filter.py`)
- Image processor → Image I/O: converts images (evidence: `ddddocr/preprocessing/image_processor.py`)
- Image I/O → Errors and imports: raises errors (evidence: `ddddocr/utils/image_io.py`)
- Input validators → Errors and imports: raises errors (evidence: `ddddocr/utils/validators.py`)
- Model loader → Errors and imports: raises errors (evidence: `ddddocr/models/model_loader.py`)
