# neural-maze/production-ocr-course architecture

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

- Interactive diagram: https://gitdiagram.com/neural-maze/production-ocr-course
- Repository: https://github.com/neural-maze/production-ocr-course

## Overview

This repository is an engineering course and set of deployment snapshots for a Kubernetes-hosted visual document understanding pipeline. Its principal async workflow accepts uploads through a Rust API, queues tasks in Redis, batches them in a Python worker for GLM-OCR processing, and exposes task status/results; the README also documents a separate synchronous/streaming Rust gateway-to-vLLM path. The graph preserves both paths and the documented deployment, security, scaling, and MCP capabilities. Source excerpts are limited, so some documented integrations are shown from the README rather than inferred from unsampled code.

Main entry points: [`client_rt_producer/src/main.rs`](https://github.com/neural-maze/production-ocr-course/blob/main/client_rt_producer/src/main.rs) (Upload and status API), [`client_rt_consumer/worker.py`](https://github.com/neural-maze/production-ocr-course/blob/main/client_rt_consumer/worker.py) (Batching worker), [`week4_rust_gateway_deployment/gateway/src/main.rs`](https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/main.rs) (Document API), [`week4_rust_gateway_deployment/gateway/src/processor.rs`](https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/processor.rs) (Document processor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_async["Async OCR pipeline"]
  node_producer["Upload and status API<br/>[main.rs]"]
  node_redis[("Redis tasks and state")]
  node_worker["Batching worker<br/>[worker.py]"]
end

subgraph group_gateway["Rust OCR gateway"]
  node_gatewayapi["Document API<br/>[main.rs]"]
  node_gatewayconfig["Gateway configuration<br/>[config.rs]"]
  node_gatewaymodels["Request and response models<br/>[models.rs]"]
  node_processor["Document processor<br/>[processor.rs]"]
  node_pdf["PDF rasterization<br/>[pdf.rs]"]
end

subgraph group_inference["OCR inference"]
  node_glmocr["GLM-OCR SDK"]
  node_shm[("Shared-memory handoff")]
  node_vllm["vLLM model serving<br/>[deployment-vlm.yml]"]
end

subgraph group_platform["Deployment and access"]
  node_cluster["AKS or GKE cluster"]
  node_autoscaler["KEDA scaling<br/>[keda-scaler.yml]"]
  node_apigateway["Enterprise API gateway<br/>[apim-policy.xml]"]
end

subgraph group_agents["Agent integration"]
  node_mcp["MCP server<br/>[server.py]"]
end

node_user(("Document client"))
node_agent(("AI coding assistant"))

node_user -->|"uploads document"| node_producer
node_producer -->|"stores task"| node_redis
node_worker -->|"claims and updates"| node_redis
node_redis -->|"queues task IDs"| node_worker
node_worker -->|"writes files"| node_shm
node_worker -->|"parses batch"| node_glmocr
node_producer -->|"reads task result"| node_redis
node_gatewayapi -->|"loads settings"| node_gatewayconfig
node_gatewayapi -->|"processes request"| node_processor
node_gatewayapi -->|"uses DTOs"| node_gatewaymodels
node_processor -->|"rasterizes documents"| node_pdf
node_processor -->|"sends inference requests"| node_vllm
node_user -->|"submits document"| node_gatewayapi
node_cluster -->|"scales workloads"| node_autoscaler
node_apigateway -.->|"secures API access"| node_producer
node_agent -->|"invokes OCR tool"| node_mcp
node_mcp -->|"submits and polls"| node_producer
node_vllm -.->|"runs on"| node_cluster
node_glmocr -.->|"layout-first pipeline"| node_vllm

click node_producer "https://github.com/neural-maze/production-ocr-course/blob/main/client_rt_producer/src/main.rs"
click node_worker "https://github.com/neural-maze/production-ocr-course/blob/main/client_rt_consumer/worker.py"
click node_gatewayapi "https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/main.rs"
click node_gatewayconfig "https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/config.rs"
click node_gatewaymodels "https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/models.rs"
click node_processor "https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/processor.rs"
click node_pdf "https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/pdf.rs"
click node_vllm "https://github.com/neural-maze/production-ocr-course/blob/main/week3_vllm_deployment/k8s/apps/deployment-vlm.yml"
click node_autoscaler "https://github.com/neural-maze/production-ocr-course/blob/main/k8s/aks/apps/keda-scaler.yml"
click node_apigateway "https://github.com/neural-maze/production-ocr-course/blob/main/k8s/aks/networking/apim-policy.xml"
click node_mcp "https://github.com/neural-maze/production-ocr-course/blob/main/week6_apim_mcp_deployment/mcp_server/server.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_producer,node_redis,node_worker,node_user toneBlue
class node_gatewayapi,node_gatewayconfig,node_gatewaymodels,node_processor,node_pdf toneAmber
class node_glmocr,node_shm,node_vllm toneMint
class node_cluster,node_autoscaler,node_apigateway toneRose
class node_mcp,node_agent toneIndigo
```

## Components

### Async OCR pipeline

- [Upload and status API](https://github.com/neural-maze/production-ocr-course/blob/main/client_rt_producer/src/main.rs): `client_rt_producer/src/main.rs`
- **Redis tasks and state**
- [Batching worker](https://github.com/neural-maze/production-ocr-course/blob/main/client_rt_consumer/worker.py): `client_rt_consumer/worker.py`

### Rust OCR gateway

- [Document API](https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/main.rs): `week4_rust_gateway_deployment/gateway/src/main.rs`
- [Gateway configuration](https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/config.rs): `week4_rust_gateway_deployment/gateway/src/config.rs`
- [Request and response models](https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/models.rs): `week4_rust_gateway_deployment/gateway/src/models.rs`
- [Document processor](https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/processor.rs): `week4_rust_gateway_deployment/gateway/src/processor.rs`
- [PDF rasterization](https://github.com/neural-maze/production-ocr-course/blob/main/week4_rust_gateway_deployment/gateway/src/pdf.rs): `week4_rust_gateway_deployment/gateway/src/pdf.rs`

### OCR inference

- **GLM-OCR SDK**
- **Shared-memory handoff**
- [vLLM model serving](https://github.com/neural-maze/production-ocr-course/blob/main/week3_vllm_deployment/k8s/apps/deployment-vlm.yml): `week3_vllm_deployment/k8s/apps/deployment-vlm.yml`

### Deployment and access

- **AKS or GKE cluster**
- [KEDA scaling](https://github.com/neural-maze/production-ocr-course/blob/main/k8s/aks/apps/keda-scaler.yml): `k8s/aks/apps/keda-scaler.yml`
- [Enterprise API gateway](https://github.com/neural-maze/production-ocr-course/blob/main/k8s/aks/networking/apim-policy.xml): `k8s/aks/networking/apim-policy.xml`

### Agent integration

- [MCP server](https://github.com/neural-maze/production-ocr-course/blob/main/week6_apim_mcp_deployment/mcp_server/server.py): `week6_apim_mcp_deployment/mcp_server/server.py`

### Other components

- **Document client**
- **AI coding assistant**

## Connections

- Document client → Upload and status API: uploads document (evidence: `README.md`)
- Upload and status API → Redis tasks and state: stores task (evidence: `client_rt_producer/src/main.rs`)
- Batching worker → Redis tasks and state: claims and updates (evidence: `client_rt_consumer/worker.py`)
- Redis tasks and state → Batching worker: queues task IDs (evidence: `client_rt_consumer/worker.py`)
- Batching worker → Shared-memory handoff: writes files (evidence: `client_rt_consumer/worker.py`)
- Batching worker → GLM-OCR SDK: parses batch (evidence: `client_rt_consumer/worker.py`)
- Upload and status API → Redis tasks and state: reads task result (evidence: `client_rt_producer/src/main.rs`)
- Document API → Gateway configuration: loads settings (evidence: `week4_rust_gateway_deployment/gateway/src/main.rs`)
- Document API → Document processor: processes request (evidence: `week4_rust_gateway_deployment/gateway/src/main.rs`)
- Document API → Request and response models: uses DTOs (evidence: `week4_rust_gateway_deployment/gateway/src/main.rs`)
- Document processor → PDF rasterization: rasterizes documents (evidence: `week4_rust_gateway_deployment/gateway/src/processor.rs`)
- Document processor → vLLM model serving: sends inference requests (evidence: `week4_rust_gateway_deployment/gateway/src/processor.rs`)
- Document client → Document API: submits document (evidence: `README.md`)
- AKS or GKE cluster → KEDA scaling: scales workloads (evidence: `README.md`)
- Enterprise API gateway → Upload and status API: secures API access (evidence: `README.md`)
- AI coding assistant → MCP server: invokes OCR tool (evidence: `week6_apim_mcp_deployment/mcp_server/server.py`)
- MCP server → Upload and status API: submits and polls (evidence: `week6_apim_mcp_deployment/mcp_server/server.py`)
- vLLM model serving → AKS or GKE cluster: runs on (evidence: `README.md`)
- GLM-OCR SDK → vLLM model serving: layout-first pipeline (evidence: `README.md`)
