A visual guide to the architecture

Follow a document
through the stack.

See where validation, recognition, agent access and optional storage live. Then choose the request path that fits the work.

Three entry pathsFig. 01
Applications and agents reach Smart Document Manager inside your loopback boundary Console and REST clients talk to the smart-document-manager container on port 8020. AI agents connect through optional smart-document-mcp on port 8021. The API coordinates GPU recognition on vllm-paddleocr and optional archiving on document-storage-s3. YOUR COMPUTER · LOOPBACK PUBLICATIONS (127.0.0.1) Console / REST client AI agent + ocr-skill smart-document-mcp :8021 · OPTIONAL BRIDGE smart-document-manager :8020 · FastAPI + /chunk vllm-paddleocr :8080 / :8081 · GPU VLM document-storage-s3 :8333 VIA GATEWAY · OPTIONAL
The guides are static teaching resources. The console and MCP are operating surfaces.
Smart Document Manager / Containers, request routes, trust boundaries & state
01 / The big picture

One document in.
Structured facts out.

Think of a scanning desk: one service coordinates the work, a GPU specialist reads the pages, and an optional archive keeps the results.

THE FRONT DESK

The OCR API coordinates.

The smart-document-manager container validates every submission, converts and rasterizes pages, orchestrates recognition and returns structured JSON and Markdown.

One API on :8020 for the console, REST clients and the MCP bridge.
THE READING SPECIALIST

vLLM recognizes.

vllm-paddleocr serves PaddleOCR-VL on an NVIDIA GPU through an OpenAI-compatible API. Only the OCR API calls it; the pinned model revision never moves silently.

GPU inference on :8080 internally, :8081 docs on the host.
THE OPTIONAL ARCHIVE

Storage archives.

An opt-in SeaweedFS S3 profile keeps parsed outputs under least-privilege roles. Without it, every result simply returns in the HTTP response.

Three extra containers when COMPOSE_PROFILES=storage.
For AI agents

An optional MCP server exposes the API as fourteen tools on :8021. Two optional skills teach an agent how to drive them. The core pipeline works without either.

Understand the difference
02 / Follow one document

From an upload
to structured evidence.

Follow one document through the pipeline. Each stage shows who acts and what crosses the next boundary.

Inside the stackReady when you are
01 / Hand a document over

You submit.
The API answers.

A document enters through the static console, a REST call or an agent's MCP tool. All three reach the same POST /parse endpoint on the smart-document-manager container.

Callers · console, REST client or MCP tool
Three doors, one contract. The API is the only front door.
You, in natural language or code

“Parse this scanned invoice into JSON and Markdown.”

BrowserConsole :8020
ScriptREST /parse
AgentMCP tool :8021

Illustrative entry points. When OCR_SERVER_API_TOKENS is set, only /, /health, /assets/* and the Swagger pages are public; /stats, /metrics and /parse/progress/{id} need the bearer too.

02 / Check before touching the GPU

Validate. Convert.
Rasterize.

The API checks the bytes, page count and per-page pixel budget first. Office files become PDF through headless LibreOffice; PDF pages rasterize at the configured DPI inside a hard per-page pixel cap, in blocks of up to 24 pages and 100 M pixels, so layout of one 8-page batch overlaps recognition of the previous one.

smart-document-manager container · admission and preparation
Oversized files and pixel budgets fail closed with 413 — never silently downscaled. Pages past OCR_MAX_PAGES are cut with a pages_truncated warning.
Validation before inferencePOST /parse
Size
MAX_FILE_BYTES · 30 MiB
Pages
OCR_MAX_PAGES · 50 · truncates
Pixels
25M per page · blocks ≤ 24 pages
Office
9 formats → PDF via LibreOffice
Rasterized pagespypdfium2 · OCR_PARSE_DPI 250
PAGE IMAGES

Defaults from .env.example. Numbers are configuration, not measurements.

03 / Find the regions

Layout detection
labels every block.

PP-DocLayoutV3 scans each page image and returns labelled regions — text, titles, tables, figures, formulas, seals — each with a bounding box in raster pixels.

ocr-api · layout detection on the GPU, beside vLLM
Blocks are a map of regions, not yet text. Recognition comes next.
b0headerbbox · no order
b1doc_titlebbox · order 1
b2textbbox · order 2
b3table + figure_titlebbox · no order
b4textbbox · order 3

Illustrative labels. 25 block types exist; captions, headers and footers carry no order.

04 / Read each region

PaddleOCR-VL reads
block by block.

The API crops each labelled region and sends it to vllm-paddleocr. Slot and memory budgets bound how many elements recognize at once; lanes bound parse concurrency.

vllm-paddleocr · GPU vision-language inference
/ocr focused tasks share the same GPU under dedicated slot and memory budgets.
On your NVIDIA GPUPaddleOCR-VL-1.6served as PaddleOCR-VL-0.9B · vLLM 0.32.0 · :8080

▤ Crops in

Labelled regions dispatched within lane and inflight budgets

✎ Text out

Markdown text, HTML tables with rowspan/colspan, LaTeX formulas, chart and seal descriptions — per block, with 413 (size or pixel budget), 429 (rate limit) and 503 (shutting_down, or backend_unavailable while the vLLM circuit breaker is open) pressure signals instead of unbounded queues.

Admission defaults: 32 element slots, 512 MiB shared element memory.

05 / Rebuild the document

Order. Relations.
Markdown.

Recognized content lands back on its blocks. block_id gives the reading order for every block; captions sit next to their tables and figures in that order; per-page Markdown renders the result with warnings attached.

ocr-api · assembly and normalization
A null order is a label choice, not a missing position — block_id is the order.
b1doc_title — “Invoice 2026-041”order 1
b2text — billing address blockorder 2
b3table + adjacent captionno order
b4text — totals and termsorder 3

Illustrative blocks. Page errors and warnings survive in the JSON.

06 / Return and optionally keep

JSON out.
Archive optional.

The response carries pages, blocks, Markdown and warnings. With the storage profile enabled, outputs also land in SeaweedFS S3 under least-privilege roles. /chunk can later build RAG chunks on CPU — no second inference.

ocr-api → caller · optional document-storage-s3
Delivery is the HTTP response. The S3 archive is an opt-in side effect.
Assembled resultJSON + Markdown
Returned structure · illustrative
{"pages":[{"blocks":[{"block_id":1,
 "type":"doc_title","order":1,
 "bbox":[52,60,398,96]}]}],
 "warnings":[]}
Source: your uploadp{page}:b{block_id} provenance
document-storage-* · gateway :8333Optional archive · writer / reader / browser / admin roles

You control the pace. Nothing plays automatically.Illustrative workflow · no requests are sent
Prefer to read? The pipeline in six sentences
  1. Submit. A document reaches POST /parse through the console, REST or an MCP tool — one endpoint, one contract.
  2. Validate. The API enforces byte, page and per-page pixel limits, converts Office files with LibreOffice and rasterizes PDF pages.
  3. Layout. PP-DocLayoutV3 labels every region with a type and a bounding box.
  4. Recognize. PaddleOCR-VL on the GPU reads each region under slot and memory budgets.
  5. Assemble. Content lands on blocks in block_id reading order, with Markdown and warnings.
  6. Deliver. JSON and Markdown return in the response; an optional S3 profile archives outputs, and /chunk builds RAG chunks later on CPU.
03 / Container topology

Separate responsibilities,
connected services.

Host ports below are shipped defaults. Each card names the container and, where it differs, the Compose service name that launcher commands such as logs -Service expect.

Container · smart-document-manager · service ocr-api

OCR API · 8020

FastAPI owns document validation, Office conversion, layout/recognition orchestration, request budgets, RAG creation and the static console.

One coordinator for browser, REST and MCP callers.
Container · vllm-paddleocr

vLLM · 8081 on the host

The GPU model server serves PaddleOCR-VL through an OpenAI-compatible API. Compose uses port 8080 internally; the host port exposes its API and docs.

NVIDIA GPU required · vLLM 0.32.0 · model revision pinned to c5630aba.
Container · smart-document-mcp · service ocr-mcp

MCP · 8021

Fourteen task tools translate agent requests into API calls. Three prompts teach workflows. Eleven resources: ten docs:// documents including these six guides, plus the live ocr://metrics.

Streamable HTTP at /mcp with distinct bearer tokens.
Containers · document-storage-*

Optional S3 storage

SeaweedFS (document-storage-s3, service seaweedfs), its gateway (document-storage-gateway, service storage-gateway, published on :8333 and :23646 for the admin console) and a one-shot initializer (document-storage-init, service storage-init) archive outputs. The initializer provisions identities before API startup. Writer, reader, browser and administrator credentials have separate roles.

Opt-in profile · COMPOSE_PROFILES=storage.
04 / Interactive route explorer

A document takes
one deliberate route.

This diagram changes only its explanation; it never contacts the application.

  1. Client / agent

    Send a document through the console, REST or an MCP tool.

  2. OCR API

    Validate the source, enforce budgets and prepare pages.

  3. GPU recognition

    Use layout and PaddleOCR-VL to recognize page content.

  4. Structured result

    Return page/block JSON and optional Markdown with warnings.

Illustration only. No request is sent and no model capacity is measured.

Route A / Full document

/parse & /parse/chunks

/parse converts Office files if needed, rasterizes pages, runs layout detection and recognizes blocks on the GPU. /parse/chunks combines one parse with immediate RAG chunking.

Route B / Cropped element

/ocr focused tasks

Recognizes a single cropped image element (text, table, formula, chart, seal or spotting) against vllm-paddleocr under dedicated slot and memory budgets.

Route C / Zero GPU inference

/chunk saved OCR JSON

Accepts an existing structured /parse JSON payload and builds token-bounded RAG chunks on the CPU using the local tokenizer—without calling vLLM again.

Route D / Office preview

/office/pdf

Converts one Office or OpenDocument file with headless LibreOffice and returns the PDF that /parse would read — no GPU. The MCP tool ocr_convert_office_to_pdf wraps it.

Route E / Archive

/storage/* and /parse/progress/{id}

With the storage profile, /storage/* lists, downloads, deletes and refines archived jobs through the S3 gateway — no GPU, exact confirmation for deletes. GET /parse/progress/{id} reports a running parse; the MCP parse tool polls it. In archive-only mode (--archive-only / -ArchiveOnly) these routes, /chunk and /office/pdf are the data routes that keep working, while /health, /stats and /metrics answer as usual: vllm-paddleocr is not started, no GPU is reserved and /parse, /ocr and /parse/chunks answer 503 ocr_disabled_archive_only.

05 / Choose your boundaries

Same stack.
Your deployment.

Explore which services run, which clients reach them, and whether an archive joins the picture. These choices are independent.

Your deployment, illustratedOn this computer

API + GPU recognition, no agent bridge.

Your computerYOUR OCR STACK
Console + REST clientsBrowser console and scripts call :8020 directly.
Console / REST clientsmart-document-manager :8020
GPU recognitionvllm-paddleocr:8080 internal · :8081 host docs

No archive: every result returns in the HTTP response and nothing is persisted by the pipeline.

Agent access
None — REST and console only
Model server
PaddleOCR-VL on NVIDIA GPU
Archive
Disabled
The whole pipeline stays on your machine.

All published ports bind to 127.0.0.1. Keep MCP inbound tokens and any agent connections inside the same boundary.

A GPU is required. vllm-paddleocr and the layout step in the smart-document-manager container both need a compatible NVIDIA GPU with at least 8 GB and a GPU-capable container runtime; there is no CPU fallback. Both share one GPU: GPU 0 unless OCR_GPU_DEVICE or --gpu-device selects another. /chunk runs on CPU but reuses existing parse JSON.

First-run preparation needs downloads. Container images, dependencies and the pinned PaddleOCR-VL model weights must be available once; afterwards the stack runs without hosted inference.

What makes a private-network setup private?

Keep the services on trusted infrastructure, control who can connect, and use an agent whose model and integrations fit that boundary. Every published host port binds to loopback by default; the published vLLM port (8081) serves its OpenAI-compatible API and metrics without bearer auth, so keep it on loopback.

MCP inbound tokens (MCP_API_TOKENS) are distinct from the API tokens (OCR_SERVER_API_TOKENS, also token:label), and the MCP server calls the API with its own service credential (UPSTREAM_CLIENT_TOKEN), which the API accepts automatically. Publishing a port beyond loopback is a deliberate deployment decision — follow the MCP configuration reference and the launcher configuration reference before exposing anything.

06 / Speak naturally. Act through tools.

MCP gives access.
Skills give guidance.

You describe the extraction in ordinary language. The agent chooses an available tool, supplies structured arguments and interprets the response.

The connection / MCP

A standard way to call tools.

The optional MCP server exposes the OCR API as 14 tools over Streamable HTTP at http://127.0.0.1:8021/mcp, plus 3 workflow prompts and 11 resources — ten documents including these guides, and the live ocr://metrics. It authenticates with its own MCP_API_TOKENS, distinct from the API token.

MCP tools reference ↗
The instructions / Skills

Playbooks beside the agent.

The smart-document-manager skill teaches tool selection and careful workflows; smart-document-reader teaches how to read parse JSON or a stored archive — block_id order, null order, relations and provenance. They are Markdown loaded by the agent host, not running services.

Client-side skills reference ↗
A request, translatedIllustrative example · nothing is sent
You say
“Extract this invoice into structured JSON.”

The agent knows a mounted input path such as /inputs/invoice.pdf, or receives the bytes as base64.

The agent can use

ocr_parse_document

One tool call maps to one POST /parse on the OCR API. Illustrative request:

{"name":"ocr_parse_document",
 "arguments":{"params":{
  "file_path":"/inputs/invoice.pdf",
  "output":"both","json_rag":true}}}

Illustrative response, abbreviated:

{"structuredContent":{"pages":[{
  "blocks":[{"block_id":1,"type":"doc_title",
  "order":1}]}],"warnings":[]}}

Agent → MCP :8021 → smart-document-manager :8020 → vllm-paddleocr :8080 → structured JSON

Skills guide; services enforce. A skill shapes agent behaviour, while authentication, input checks and confirmation gates live in the services. Destructive storage tools require an exact confirm value checked locally and again by the API.

You connect the agent host. Point a Streamable HTTP client at /mcp with a bearer token, then load the skills if the host supports them. Server file paths live inside the MCP container — mounts plus MCP_INPUT_ROOTS decide what file_path may reach.

07 / Security & network isolation

Keep access boundaries
visible.

Authentication belongs to the service receiving a request, not to a nearby UI or network label.

01 / Loopback & UI

Static console, loopback ports

The console is static code served by the API—not a separate ocr-ui container. All published host ports bind to 127.0.0.1; Docker-private networks do not authenticate callers. Two Compose networks: smart-document-manager-private joins the API, vLLM, MCP and the storage gateway; smart-document-manager-storage is internal-only and holds SeaweedFS and the initializer, so the API reaches S3 only through the gateway.

02 / Token separation

Distinct service secrets

MCP has its own inbound tokens (MCP_API_TOKENS), calls the API with its own service token (UPSTREAM_CLIENT_TOKEN, listed in neither token list), and never gives clients a direct model-server token. The published vLLM port (8081) has no bearer auth.

03 / Files & mutations

Server roots & confirmation

MCP local file paths refer to the MCP container, requiring both MCP_INPUT_ROOTS and read-only Docker mounts. Inference POSTs are not retried; destructive storage tools require exact confirmation.

04 / Request admission

Guard, limit, authenticate

Every non-public request passes the shutdown guard (503 shutting_down on POST), a per-IP rate limit (429 rate_limited; GET /stats, /metrics and /parse/progress/{id} are exempt) and bearer auth (401 unauthorized). CORS is opt-in through OCR_CORS_ORIGINS and answers preflights before authentication.

05 / Container hardening

Least privilege by default

ocr-api, ocr-mcp and the storage services run as a non-root user on read-only filesystems with every capability dropped, no-new-privileges and memory/PID limits. vllm-paddleocr drops capabilities and is memory-limited but runs as root on a writable filesystem.

08 / Volumes, calibration & evidence

Know what survives
a restart.

Runtime state and release evidence answer different questions.

Persistent Docker volumes

Caches, profiles & archives

Named volumes retain model weights (ocr-vllm-model-cache), Paddle caches, runtime hardware state, tuning profiles and optional OCR archives (ocr-output-storage). Normal down retains them; volume deletion is destructive.

Hardware calibration

Autotuning fingerprints

Autotuning fingerprints include the runtime and model context. A vLLM version or hardware change invalidates the cached profile and triggers recalibration. Empty concurrency overrides preserve automatic selection. OCR_AUTOTUNE is quick by default; full runs the complete corpus, off skips calibration and keeps built-in defaults, and OCR_AUTOTUNE_FORCE=true discards the cached profile.

Deployment model

Container vs native startup

The Docker services have separate images and dependency inventories. Native startup changes dotenv and bind semantics; use its owning reference instead of copying container settings blindly.

Verification boundary

CI vs release evidence

CI tests contracts with fake inference and offline guides. Its green aggregate does not prove GPU OCR quality, live credentials or production readiness. See the release checklist ↗.

09 / Glossary & further reading

A little less jargon.
One level deeper.

Terms this page uses, and the owning documents that define the exact behavior.

What is MCP?

The Model Context Protocol is a standard for connecting AI applications to tools and context. This repository's optional MCP server exposes the OCR API over Streamable HTTP at http://127.0.0.1:8021/mcp. Using HTTP does not by itself mean using the public internet.

What is the VLM?

The vision-language model — PaddleOCR-VL, served by vllm-paddleocr through vLLM's OpenAI-compatible API at a pinned revision. It reads cropped page regions and returns text, tables, formulas and descriptions.

What is a layout block?

A labelled region of a page: a type (one of 25 tags like text, doc_title, table, seal), a bounding box in raster pixels, recognized content, and identifiers block_id / group_id.

What is reading order?

block_id is the reading order for every block, tables and captions included. order is null by label for captions, headers, footers and page numbers — never "unplaced". Do not rebuild order from coordinates.

What is a chunk?

A token-bounded, section-aware unit built from parse JSON by the deterministic CPU chunker (/chunk, /parse/chunks). Same input plus same options gives byte-identical chunks with canonical hashes.

What is autotune?

Pre-start calibration: vllm-paddleocr writes a hardware manifest, then ocr-api measures concurrency settings against quality and stability gates and persists a fingerprint-bound profile.

What is a GPU tier?

The capacity band the Stage-1 entrypoint detects from VRAM and compute capability. It selects vLLM startup flags such as max sequences — 16 below 16 GiB, 32 from 16 GiB, 64 from 24 GiB — unless you override them.

What is the archive?

The optional storage Compose profile: SeaweedFS S3 behind an nginx gateway, provisioned by a one-shot init with four least-privilege roles — writer, browser, reader, and an admin key the API never sees.

What is archive-only mode?

A launcher mode (-ArchiveOnly / --archive-only, or OCR_ARCHIVE_ONLY=true) that starts ocr-api, MCP and, with COMPOSE_PROFILES=storage, the storage profile without vllm-paddleocr or any GPU reservation, through the compose.archive-only.yml overlay. Stored archives stay readable through the console, /storage/* and the MCP storage tools; inference routes refuse with 503 ocr_disabled_archive_only, autotune does not run and /health reports vllm=disabled, healthy once the archive bucket answers.

Go one level deeper.

Checked against the repository's owning references. This page is an offline explanation; it does not inspect your machine, connect to your services, or change their configuration.

10 / Questions

Choose the next
check.

Match each observation to the layer it can actually prove.

Which health result should I trust?

API health can return HTTP 200 while degraded. Check its response and model reachability. mode=archive_only with vllm=disabled is a healthy archive-only stack, not an outage: OCR is off by design and ocr_enabled=false says so. MCP listener health only proves a listening process; authenticated discovery is a separate check.

Do I need to run OCR again to create chunks?

No, when complete structured parse JSON already exists. Use the existing-JSON mode of ocr_create_rag_chunks or REST /chunk. The tokenizer and CPU budgets remain relevant.

How do I stop without deleting model caches?

Run from the repository root

Windows · PowerShell 7
pwsh .\stack.ps1 down

Linux / macOS · Bash
bash stack.sh down

Retained data does not guarantee an unchanged calibration is valid after an upgrade. Let the runtime fingerprint decide.

What happens if optional S3 storage is disabled?

The API returns parsed JSON, Markdown and chunks directly in the HTTP/MCP response without writing to S3, and the three document-storage-* containers are not started.

11 / Keep going

Keep the contract
close.

These guides teach the workflow. The owning documents define its exact behavior.