# bg12345/ocr architecture

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

- Interactive diagram: https://gitdiagram.com/bg12345/ocr
- Repository: https://github.com/bg12345/ocr

## Overview

OCR API accepts Indian identity-document uploads through its browser demo or REST endpoints, processes PAN, driving licence, and Aadhaar documents, and returns extracted records or existing-record matches as JSON with temporary download links. The documented processing includes image preprocessing, PDF image conversion, OCR, and Aadhaar/QR decoding; routes also check MongoDB and use S3 for private file storage. The principal source excerpt is partial, so the graph omits uncertain internal wiring and represents documented but unsampled PDF handling at the routes module.

Main entry points: [`app/routes/routes.py`](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py) (Flask API routes), [`app/static/js/app.js`](https://github.com/bg12345/ocr/blob/main/app/static/js/app.js) (Upload demo), [`preprocessing.py`](https://github.com/bg12345/ocr/blob/main/preprocessing.py) (Image preprocessing), [`PDFTextExtract.py`](https://github.com/bg12345/ocr/blob/main/PDFTextExtract.py) (PDF image extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client experience"]
  node_demo["Upload demo<br/>[app.js]"]
end

subgraph group_api["API workflows"]
  node_routes["Flask API routes<br/>[routes.py]"]
  node_pan["PAN extraction<br/>[routes.py]"]
  node_dl["Licence extraction<br/>[routes.py]"]
  node_aadhaar["Aadhaar extraction<br/>[routes.py]"]
  node_results["JSON responses<br/>[routes.py]"]
end

subgraph group_processing["Document processing"]
  node_image_prep["Image preprocessing<br/>[preprocessing.py]"]
  node_pdf_handling["PDF image conversion<br/>[routes.py]"]
  node_pdf_images["PDF image extraction<br/>[PDFTextExtract.py]"]
  node_tesseract["Tesseract OCR"]
  node_qr_decode["QR decoding<br/>[preprocessing.py]"]
  node_aadhaar_qr["Aadhaar QR parsing<br/>[routes.py]"]
end

subgraph group_persistence["Storage and records"]
  node_mongo[("MongoDB records")]
  node_file_store["S3 upload and links<br/>[routes.py]"]
end

node_browser(("Browser user"))
node_api_caller(("API caller"))
node_s3[("Amazon S3")]

node_browser -->|"uploads files"| node_demo
node_demo -->|"submits forms"| node_routes
node_api_caller -->|"posts documents"| node_routes
node_routes -->|"dispatches PAN"| node_pan
node_routes -->|"dispatches licence"| node_dl
node_routes -->|"dispatches Aadhaar"| node_aadhaar
node_pan -->|"preprocesses image"| node_image_prep
node_dl -->|"preprocesses image"| node_image_prep
node_aadhaar -->|"preprocesses image"| node_image_prep
node_routes -->|"converts PDFs"| node_pdf_handling
node_routes -.->|"extracts PDF images"| node_pdf_images
node_pan -->|"recognizes text"| node_tesseract
node_dl -->|"recognizes text"| node_tesseract
node_aadhaar -->|"recognizes text"| node_tesseract
node_aadhaar -->|"detects QR"| node_qr_decode
node_aadhaar -->|"decodes Aadhaar QR"| node_aadhaar_qr
node_pan -->|"checks and stores"| node_mongo
node_dl -->|"checks and stores"| node_mongo
node_aadhaar -->|"checks and stores"| node_mongo
node_routes -->|"uploads files"| node_file_store
node_file_store -->|"stores privately"| node_s3
node_file_store -->|"returns signed links"| node_routes
node_routes -->|"formats response"| node_results
node_results -->|"displays JSON"| node_demo

click node_demo "https://github.com/bg12345/ocr/blob/main/app/static/js/app.js"
click node_routes "https://github.com/bg12345/ocr/blob/main/app/routes/routes.py"
click node_pan "https://github.com/bg12345/ocr/blob/main/app/routes/routes.py"
click node_dl "https://github.com/bg12345/ocr/blob/main/app/routes/routes.py"
click node_aadhaar "https://github.com/bg12345/ocr/blob/main/app/routes/routes.py"
click node_results "https://github.com/bg12345/ocr/blob/main/app/routes/routes.py"
click node_image_prep "https://github.com/bg12345/ocr/blob/main/preprocessing.py"
click node_pdf_handling "https://github.com/bg12345/ocr/blob/main/app/routes/routes.py"
click node_pdf_images "https://github.com/bg12345/ocr/blob/main/PDFTextExtract.py"
click node_qr_decode "https://github.com/bg12345/ocr/blob/main/preprocessing.py"
click node_aadhaar_qr "https://github.com/bg12345/ocr/blob/main/app/routes/routes.py"
click node_file_store "https://github.com/bg12345/ocr/blob/main/app/routes/routes.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_demo,node_browser toneBlue
class node_routes,node_pan,node_dl,node_aadhaar,node_results,node_s3 toneAmber
class node_image_prep,node_pdf_handling,node_pdf_images,node_tesseract,node_qr_decode,node_aadhaar_qr,node_api_caller toneMint
class node_mongo,node_file_store toneRose
```

## Components

### Client experience

- [Upload demo](https://github.com/bg12345/ocr/blob/main/app/static/js/app.js): `app/static/js/app.js`

### API workflows

- [Flask API routes](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`
- [PAN extraction](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`
- [Licence extraction](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`
- [Aadhaar extraction](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`
- [JSON responses](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`

### Document processing

- [Image preprocessing](https://github.com/bg12345/ocr/blob/main/preprocessing.py): `preprocessing.py`
- [PDF image conversion](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`
- [PDF image extraction](https://github.com/bg12345/ocr/blob/main/PDFTextExtract.py): `PDFTextExtract.py`
- **Tesseract OCR**
- [QR decoding](https://github.com/bg12345/ocr/blob/main/preprocessing.py): `preprocessing.py`
- [Aadhaar QR parsing](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`

### Storage and records

- **MongoDB records**
- [S3 upload and links](https://github.com/bg12345/ocr/blob/main/app/routes/routes.py): `app/routes/routes.py`

### Other components

- **Browser user**
- **API caller**
- **Amazon S3**

## Connections

- Browser user → Upload demo: uploads files
- Upload demo → Flask API routes: submits forms
- API caller → Flask API routes: posts documents
- Flask API routes → PAN extraction: dispatches PAN
- Flask API routes → Licence extraction: dispatches licence
- Flask API routes → Aadhaar extraction: dispatches Aadhaar
- PAN extraction → Image preprocessing: preprocesses image
- Licence extraction → Image preprocessing: preprocesses image
- Aadhaar extraction → Image preprocessing: preprocesses image
- Flask API routes → PDF image conversion: converts PDFs
- Flask API routes → PDF image extraction: extracts PDF images
- PAN extraction → Tesseract OCR: recognizes text
- Licence extraction → Tesseract OCR: recognizes text
- Aadhaar extraction → Tesseract OCR: recognizes text
- Aadhaar extraction → QR decoding: detects QR
- Aadhaar extraction → Aadhaar QR parsing: decodes Aadhaar QR
- PAN extraction → MongoDB records: checks and stores
- Licence extraction → MongoDB records: checks and stores
- Aadhaar extraction → MongoDB records: checks and stores
- Flask API routes → S3 upload and links: uploads files
- S3 upload and links → Amazon S3: stores privately
- S3 upload and links → Flask API routes: returns signed links
- Flask API routes → JSON responses: formats response
- JSON responses → Upload demo: displays JSON
