paddleocr-js/docs/architecture.md
English | 简体中文
The paddleocr-js folder has two main parts:
packages/core: the browser PaddleOCR SDK (published on npm as @paddleocr/paddleocr-js)apps/demo: a demo application for PP-OCR that consumes the SDKpackages/core)src/
├── runtime/ — inference runtime setup
├── resources/ — model & asset management
├── models/ — model wiring
├── platform/ — browser/worker input adaptation
├── worker/ — worker transport layer
├── pipelines/ — pipeline implementations
├── viz/ — visualization (optional)
├── types/ — external type declarations
└── utils/ — shared utilities
The current high-level pipeline entry point is PaddleOCR.create(). It coordinates:
PaddleOCR.create() supports 2 execution modes:
PaddleOCR, which runs OCR directly on the calling threadWorkerBackedPaddleOCR, which forwards OCR lifecycle calls to a dedicated workerThe runtime flow for worker mode is:
PaddleOCR.create({ worker: true }) resolves OCR options and creates a WorkerBackedPaddleOCRWorkerBackedPaddleOCR sends init/predict/dispose requests through WorkerTransportClientsrc/pipelines/ocr/worker-entry.tssrc/pipelines/ocr/worker-entry.ts binds the generic worker bootstrap in src/worker/entry.ts to the OCR-specific worker handlerOcrPipelineRunner runs OpenCV.js, ONNX Runtime Web, model loading, detection, and recognition inside the workerInput handling is split by environment:
cv.MatWorker mode uses the package worker path and explicitly disables ONNX Runtime Web wasm proxy internally. This avoids stacking two worker layers and keeps the package responsible for the concurrency model.
ONNX Runtime Web requires WASM binaries at runtime. ortOptions.wasmPaths is a unified configuration that applies to both execution modes — setting it once controls where WASM is loaded in both main-thread and worker contexts:
PaddleOCR.create({
ortOptions: { wasmPaths: "/assets/" }
});
When wasmPaths is set, both modes fetch WASM from the specified path. When it is not set, each mode falls back differently:
.wasm files from node_modules/onnxruntime-web/dist/ into the build output and rewrites the URLs automatically)ortOptions.wasmPathsSetting ortOptions.wasmPaths explicitly is recommended for worker mode to ensure version consistency between the two modes.
The SDK owns OCR runtime setup and inference orchestration. The host application still owns:
worker: true is usedHere, the apps/ directory contains such host applications.