# roderen/ocr-service-api architecture

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

- Interactive diagram: https://gitdiagram.com/roderen/ocr-service-api
- Repository: https://github.com/roderen/ocr-service-api

## Overview

This repository implements a document-verification API: clients submit document images for OCR/MRZ processing and duplicate lookup, or submit a selfie and document image for face comparison. The .NET API orchestrates these workflows, with Python/PaddleOCR and AWS Rekognition as separate integrations. The OCR service also validates MRZ data and encrypts document identifiers before persistence. Some links are documented in the README rather than shown in sampled source; OCR controller internals and Python implementation details were not excerpted.

Main entry points: [`OCR-Service-API/Services/OCR/OCRService.cs`](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/OCRService.cs) (OCR service), [`OCR-Service-API/Program.cs`](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Program.cs) (.NET API), [`OCR-Service-API/Data/ApplicationDbContext.cs`](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Data/ApplicationDbContext.cs) (Database context), [`OCR-Service-API/Controllers/OCR/OCRController.cs`](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Controllers/OCR/OCRController.cs) (OCR endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API orchestration"]
  node_api_host[".NET API<br/>[Program.cs]"]
  node_ocr_endpoint["OCR endpoint<br/>[OCRController.cs]"]
  node_face_endpoint["Face endpoint<br/>[FaceController.cs]"]
end

subgraph group_ocr["Document OCR"]
  node_ocr_service["OCR service<br/>[OCRService.cs]"]
  node_image_resize["Image resizing"]
  node_python_ocr["Python OCR service<br/>[main.py]"]
  node_mrz_parse["MRZ parsing<br/>[OCRService.cs]"]
  node_mrz_format["Format detection"]
  node_mrz_checksum["Checksum validation"]
end

subgraph group_identity["Identity checks"]
  node_face_service["Face comparison"]
  node_rekognition["AWS Rekognition"]
end

subgraph group_storage["Data protection"]
  node_encryptor["Encrypt and hash<br/>[Encryptor.cs]"]
  node_document_model["Document record<br/>[DocumentModel.cs]"]
  node_db_context["Database context"]
  node_postgres[("PostgreSQL")]
end

node_client(("Client"))

node_client -->|"submits request"| node_api_host
node_api_host -->|"routes controllers"| node_ocr_endpoint
node_api_host -->|"routes controllers"| node_face_endpoint
node_ocr_endpoint -.->|"invokes OCR"| node_ocr_service
node_face_endpoint -->|"compares faces"| node_face_service
node_ocr_service -->|"resizes image"| node_image_resize
node_ocr_service -->|"posts image"| node_python_ocr
node_python_ocr -->|"returns OCR text"| node_ocr_service
node_ocr_service -->|"parses MRZ"| node_mrz_parse
node_ocr_service -->|"detects format"| node_mrz_format
node_ocr_service -->|"validates checksum"| node_mrz_checksum
node_ocr_service -->|"encrypts and hashes"| node_encryptor
node_ocr_service -->|"queries and saves"| node_db_context
node_db_context -->|"maps records"| node_document_model
node_db_context -->|"persists data"| node_postgres
node_face_service -->|"requests comparison"| node_rekognition

click node_api_host "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Program.cs"
click node_ocr_endpoint "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Controllers/OCR/OCRController.cs"
click node_face_endpoint "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Controllers/Face/FaceController.cs"
click node_ocr_service "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/OCRService.cs"
click node_image_resize "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/ResizeToMaxDimension.cs"
click node_python_ocr "https://github.com/roderen/ocr-service-api/blob/main/ocr-service/main.py"
click node_mrz_parse "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/OCRService.cs"
click node_mrz_format "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/MrzFormatDetector.cs"
click node_mrz_checksum "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/MrzChecksumValidator.cs"
click node_face_service "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/Face/FaceCompareService.cs"
click node_encryptor "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Encryption/Encryptor.cs"
click node_document_model "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Models/Document/DocumentModel.cs"
click node_db_context "https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Data/ApplicationDbContext.cs"

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_api_host,node_ocr_endpoint,node_face_endpoint,node_client toneBlue
class node_ocr_service,node_image_resize,node_python_ocr,node_mrz_parse,node_mrz_format,node_mrz_checksum toneAmber
class node_face_service,node_rekognition toneMint
class node_encryptor,node_document_model,node_db_context,node_postgres toneRose
```

## Components

### API orchestration

- [.NET API](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Program.cs): `OCR-Service-API/Program.cs`
- [OCR endpoint](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Controllers/OCR/OCRController.cs): `OCR-Service-API/Controllers/OCR/OCRController.cs`
- [Face endpoint](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Controllers/Face/FaceController.cs): `OCR-Service-API/Controllers/Face/FaceController.cs`

### Document OCR

- [OCR service](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/OCRService.cs): `OCR-Service-API/Services/OCR/OCRService.cs`
- [Image resizing](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/ResizeToMaxDimension.cs): `OCR-Service-API/Services/OCR/ResizeToMaxDimension.cs`
- [Python OCR service](https://github.com/roderen/ocr-service-api/blob/main/ocr-service/main.py): `ocr-service/main.py`
- [MRZ parsing](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/OCRService.cs): `OCR-Service-API/Services/OCR/OCRService.cs`
- [Format detection](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/MrzFormatDetector.cs): `OCR-Service-API/Services/OCR/MrzFormatDetector.cs`
- [Checksum validation](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/OCR/MrzChecksumValidator.cs): `OCR-Service-API/Services/OCR/MrzChecksumValidator.cs`

### Identity checks

- [Face comparison](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Services/Face/FaceCompareService.cs): `OCR-Service-API/Services/Face/FaceCompareService.cs`
- **AWS Rekognition**

### Data protection

- [Encrypt and hash](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Encryption/Encryptor.cs): `OCR-Service-API/Encryption/Encryptor.cs`
- [Document record](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Models/Document/DocumentModel.cs): `OCR-Service-API/Models/Document/DocumentModel.cs`
- [Database context](https://github.com/roderen/ocr-service-api/blob/main/OCR-Service-API/Data/ApplicationDbContext.cs): `OCR-Service-API/Data/ApplicationDbContext.cs`
- **PostgreSQL**

### Other components

- **Client**

## Connections

- Client → .NET API: submits request (evidence: `README.md`)
- .NET API → OCR endpoint: routes controllers (evidence: `OCR-Service-API/Program.cs`)
- .NET API → Face endpoint: routes controllers (evidence: `OCR-Service-API/Program.cs`)
- OCR endpoint → OCR service: invokes OCR
- Face endpoint → Face comparison: compares faces (evidence: `OCR-Service-API/Controllers/Face/FaceController.cs`)
- OCR service → Image resizing: resizes image (evidence: `OCR-Service-API/Services/OCR/OCRService.cs`)
- OCR service → Python OCR service: posts image (evidence: `OCR-Service-API/Services/OCR/OCRService.cs`)
- Python OCR service → OCR service: returns OCR text (evidence: `README.md`)
- OCR service → MRZ parsing: parses MRZ (evidence: `OCR-Service-API/Services/OCR/OCRService.cs`)
- OCR service → Format detection: detects format (evidence: `OCR-Service-API/Services/OCR/OCRService.cs`)
- OCR service → Checksum validation: validates checksum (evidence: `OCR-Service-API/Services/OCR/OCRService.cs`)
- OCR service → Encrypt and hash: encrypts and hashes (evidence: `OCR-Service-API/Services/OCR/OCRService.cs`)
- OCR service → Database context: queries and saves (evidence: `OCR-Service-API/Services/OCR/OCRService.cs`)
- Database context → Document record: maps records (evidence: `OCR-Service-API/Data/ApplicationDbContext.cs`)
- Database context → PostgreSQL: persists data (evidence: `README.md`)
- Face comparison → AWS Rekognition: requests comparison (evidence: `OCR-Service-API/Services/Face/FaceCompareService.cs`)
