# rapidai/rapidocr architecture

> Architecture diagram of the GitHub repository rapidai/rapidocr, 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/rapidai/rapidocr
- Repository: https://github.com/rapidai/rapidocr

## Overview

##### Project type and purpose
- RapidOCR is an open-source, multi-platform OCR toolkit and inference engine wrapper.
- It provides a core OCR pipeline in Python with plugin-style support for ONNXRuntime, OpenVINO, PaddlePaddle, and PyTorch backends.
- It exposes:
– A Python package and CLI for local/in-process use
– A Dockerized HTTP API service
– A web UI (ocrweb)
– Language bindings for C++, .NET, Java, Android, and iOS

##### File structure
- Top-level “python” directory:
– rapidocr/… implements the core abstraction, configuration, CLI, and default pipeline
– rapidocr_inference_engine subpackages (onnxruntime, openvino, paddle, torch) implement the strategy/plugin pattern for different inference engines
– models/, networks/, utils/ break down OCR pipeline into detection, classification, recognition, postprocessing
– Tests validate each engine and the overall pipeline
- “api” directory:
– A small web service wrapping the Python package in a Dockerfile
- “ocrweb” and “ocrweb_multi”:
– Web UIs that call either the local Python package directly (ocrweb_multi) or the HTTP API (ocrweb)
- Language-specific directories (cpp, dotnet, jvm, android, ios):
– Bindings or wrappers around the core library for each target platform
- CI/CD workflows and docs govern packaging, publishing to PyPI, GitHub Actions, and user guides

##### README insights
- Emphasizes multi-engine, multi-platform deployment
- Points to external dependencies: ONNXRuntime, Paddle, Torch, OpenVINO
- Describes demo apps (Python notebook, web demos) and installation via pip

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core OCR Engine"
        CORE["Core OCR Engine"]:::core
        CFG["Configuration Loader"]:::core
        PARSE["Parameter Parser"]:::core
        DET["Detection Module"]:::core
        CLS["Classification Module"]:::core
        REC["Recognition Module"]:::core
        POST["Postprocessing Module"]:::core
    end

    subgraph "Inference Engine Plugins"
        ONNX["ONNXRuntime Plugin"]:::plugin
        OPENVINO["OpenVINO Plugin"]:::plugin
        PADDLE["PaddlePaddle Plugin"]:::plugin
        TORCH["PyTorch Plugin"]:::plugin
    end

    subgraph "Transport & API"
        CLI["CLI & Python Package"]:::transport
        API["HTTP API Service"]:::transport
    end

    subgraph "Web UI"
        OCRWEB["OCRWeb (HTTP)"]:::ui
        OCRWEB_MULTI["OCRWeb_Multi (Local)"]:::ui
    end

    subgraph "Language Bindings"
        CPP["C++ SDK"]:::transport
        DOTNET[".NET SDK"]:::transport
        JVM["Java/JVM SDK"]:::transport
        ANDROID["Android SDK"]:::transport
        IOS["iOS SDK"]:::transport
    end

    subgraph "External & CI/CD"
        DOCKER["Docker Host"]:::external
        MODEL["Model Repository"]:::external
        CICD["CI/CD Pipelines"]:::external
    end

    %% Core connections
    CLI -->|"calls"| CORE
    API -->|"wraps"| CORE
    OCRWEB -->|"HTTP request"| API
    API -->|"returns JSON"| OCRWEB
    OCRWEB_MULTI -->|"direct call"| CORE

    %% Plugin connections
    CORE -->|"loads plugin"| ONNX
    CORE -->|"loads plugin"| OPENVINO
    CORE -->|"loads plugin"| PADDLE
    CORE -->|"loads plugin"| TORCH

    %% Bindings connections
    CPP -->|"wraps core"| CORE
    DOTNET -->|"wraps core"| CORE
    JVM -->|"wraps core"| CORE
    ANDROID -->|"wraps core"| CORE
    IOS -->|"wraps core"| CORE

    %% External connections
    API -->|"deployed on"| DOCKER
    CORE -->|"loads models from"| MODEL
    CICD -->|"publishes builds"| CLI
    CICD -->|"builds bindings"| CPP

    %% Detailed modules
    CORE --> CFG
    CORE --> PARSE
    CORE --> DET
    CORE --> CLS
    CORE --> REC
    CORE --> POST

    %% Click Events
    click CORE "https://github.com/rapidai/rapidocr/tree/main/python/rapidocr/"
    click CFG "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/config.yaml"
    click CFG "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/default_models.yaml"
    click PARSE "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/utils/parse_parameters.py"
    click DET "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/networks/heads/det_db_head.py"
    click DET "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/networks/necks/db_fpn.py"
    click CLS "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/networks/heads/cls_head.py"
    click REC "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/networks/heads/rec_ctc_head.py"
    click REC "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/networks/heads/rec_multi_head.py"
    click POST "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/utils/vis_res.py"

    click ONNX "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/inference_engine/onnxruntime.py"
    click ONNX "https://github.com/rapidai/rapidocr/tree/main/python/rapidocr_onnxruntime/"
    click OPENVINO "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/inference_engine/openvino.py"
    click OPENVINO "https://github.com/rapidai/rapidocr/tree/main/python/rapidocr_openvino/"
    click PADDLE "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/inference_engine/paddle.py"
    click PADDLE "https://github.com/rapidai/rapidocr/tree/main/python/rapidocr_paddle/"
    click TORCH "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/inference_engine/torch.py"
    click TORCH "https://github.com/rapidai/rapidocr/tree/main/python/rapidocr_torch/"

    click CLI "https://github.com/rapidai/rapidocr/blob/main/python/setup.py"
    click CLI "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/cli.py"
    click CLI "https://github.com/rapidai/rapidocr/blob/main/python/rapidocr/main.py"
    click API "https://github.com/rapidai/rapidocr/blob/main/api/rapidocr_api/main.py"
    click API "https://github.com/rapidai/rapidocr/tree/main/api/Dockerfile"
    click API "https://github.com/rapidai/rapidocr/blob/main/api/setup.py"
    click API "https://github.com/rapidai/rapidocr/blob/main/api/demo.py"

    click OCRWEB "https://github.com/rapidai/rapidocr/tree/main/ocrweb/rapidocr_web/"
    click OCRWEB_MULTI "https://github.com/rapidai/rapidocr/blob/main/ocrweb_multi/main.py"
    click OCRWEB_MULTI "https://github.com/rapidai/rapidocr/tree/main/ocrweb_multi/rapidocr/"
    click OCRWEB_MULTI "https://github.com/rapidai/rapidocr/blob/main/ocrweb_multi/config.yaml"

    click CPP "https://github.com/rapidai/rapidocr/tree/main/cpp/"
    click DOTNET "https://github.com/rapidai/rapidocr/tree/main/dotnet/"
    click JVM "https://github.com/rapidai/rapidocr/tree/main/jvm/"
    click ANDROID "https://github.com/rapidai/rapidocr/tree/main/android/"
    click IOS "https://github.com/rapidai/rapidocr/tree/main/ios/"

    %% Styles
    classDef core fill:#c6f5c6,stroke:#333,stroke-width:1px
    classDef plugin fill:#c6f5c6,stroke:#333,stroke-width:1px
    classDef transport fill:#c6e0f7,stroke:#333,stroke-width:1px
    classDef ui fill:#ffd2a2,stroke:#333,stroke-width:1px
    classDef external fill:#f9f5a2,stroke:#333,stroke-width:1px
```
