# bcss-nandeep/charge_sheet_ocr architecture

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

- Interactive diagram: https://gitdiagram.com/bcss-nandeep/charge_sheet_ocr
- Repository: https://github.com/bcss-nandeep/charge_sheet_ocr

## Overview

This is a local-only FastAPI service for extracting printed labels and values from charge-sheet PDFs, with an HTML review UI and REST API. Operators upload or reprocess documents; the processing service extracts pages and fields, stores results and raw text, and reviewers can correct or verify them. The graph also preserves document history, templates, retention, and local OCR/layout capabilities. Pipeline links follow the extraction module’s references and README; some implementation details were not sampled, so uncertain links are omitted.

Main entry points: [`app/services/extraction_service.py`](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/extraction_service.py) (Extraction pipeline), [`app/repositories/document_repository.py`](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/repositories/document_repository.py) (Document repository), [`app/api/routes_upload.py`](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/api/routes_upload.py) (Upload API), [`app/services/processing_service.py`](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/processing_service.py) (Processing coordinator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_upload["Upload API<br/>[routes_upload.py]"]
  node_document_routes["Document API"]
  node_result_routes["Results API<br/>[routes_results.py]"]
  node_auth["Role authorization<br/>[auth.py]"]
  node_ui["Review UI<br/>[app.js]"]
end

subgraph group_extract["PDF extraction"]
  node_processing["Processing coordinator"]
  node_extraction["Extraction pipeline"]
  node_pdf_router["PDF page routing<br/>[pdf_service.py]"]
  node_ocr["Local OCR<br/>[ocr_service.py]"]
  node_structure["Table structure"]
  node_docling["Docling assist<br/>[docling_service.py]"]
  node_vl["OCR-VL assist<br/>[vl_service.py]"]
  node_layout["Layout parsing<br/>[layout_service.py]"]
  node_form_parser["Form parsing<br/>[form_parser.py]"]
  node_field_builder["Field building<br/>[field_builder.py]"]
end

subgraph group_review["Review and records"]
  node_documents["Document repository"]
  node_results["Results repository"]
  node_templates["Template service"]
  node_retention["Retention purge"]
end

subgraph group_platform["Local platform"]
  node_database[("Application database<br/>[models.py]")]
  node_files["Protected PDF files<br/>[files.py]"]
  node_schemas["Extraction schemas<br/>[charge_sheet.py]"]
end

node_operator(("Operator / reviewer"))

node_operator -->|"uploads PDF"| node_upload
node_operator -->|"reviews results"| node_result_routes
node_upload -->|"checks role"| node_auth
node_result_routes -->|"checks role"| node_auth
node_upload -->|"creates record"| node_documents
node_upload -->|"stores upload"| node_files
node_upload -->|"queues processing"| node_processing
node_document_routes -->|"queues reprocess"| node_processing
node_processing -->|"runs extraction"| node_extraction
node_processing -->|"updates status"| node_documents
node_processing -->|"persists results"| node_results
node_extraction -->|"routes pages"| node_pdf_router
node_extraction -->|"reads scans"| node_ocr
node_extraction -->|"parses structure"| node_structure
node_extraction -.->|"assists digital forms"| node_docling
node_extraction -.->|"assists hard pages"| node_vl
node_extraction -->|"builds layout items"| node_layout
node_extraction -->|"parses forms"| node_form_parser
node_extraction -->|"builds fields"| node_field_builder
node_extraction -->|"returns field data"| node_schemas
node_result_routes -->|"reads metadata"| node_documents
node_result_routes -->|"reads saved results"| node_results
node_document_routes -->|"reads document records"| node_documents
node_document_routes -->|"purges expired data"| node_retention
node_document_routes -->|"lists templates"| node_templates
node_documents -->|"persists records"| node_database
node_results -->|"persists extraction"| node_database
node_retention -->|"deletes stored PDFs"| node_files
node_retention -->|"purges records"| node_documents

click node_upload "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/api/routes_upload.py"
click node_document_routes "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/api/routes_documents.py"
click node_result_routes "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/api/routes_results.py"
click node_auth "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/security/auth.py"
click node_ui "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/static/js/app.js"
click node_processing "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/processing_service.py"
click node_extraction "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/extraction_service.py"
click node_pdf_router "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/pdf_service.py"
click node_ocr "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/ocr_service.py"
click node_structure "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/structure_service.py"
click node_docling "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/docling_service.py"
click node_vl "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/vl_service.py"
click node_layout "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/layout_service.py"
click node_form_parser "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/form_parser.py"
click node_field_builder "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/field_builder.py"
click node_documents "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/repositories/document_repository.py"
click node_results "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/repositories/results_repository.py"
click node_templates "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/template_service.py"
click node_retention "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/retention_service.py"
click node_database "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/models.py"
click node_files "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/security/files.py"
click node_schemas "https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/schemas/charge_sheet.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_upload,node_document_routes,node_result_routes,node_auth,node_ui,node_operator toneBlue
class node_processing,node_extraction,node_pdf_router,node_ocr,node_structure,node_docling,node_vl,node_layout,node_form_parser,node_field_builder toneAmber
class node_documents,node_results,node_templates,node_retention toneMint
class node_database,node_files,node_schemas toneRose
```

## Components

### API and access

- [Upload API](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/api/routes_upload.py): `app/api/routes_upload.py`
- [Document API](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/api/routes_documents.py): `app/api/routes_documents.py`
- [Results API](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/api/routes_results.py): `app/api/routes_results.py`
- [Role authorization](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/security/auth.py): `app/security/auth.py`
- [Review UI](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/static/js/app.js): `app/static/js/app.js`

### PDF extraction

- [Processing coordinator](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/processing_service.py): `app/services/processing_service.py`
- [Extraction pipeline](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/extraction_service.py): `app/services/extraction_service.py`
- [PDF page routing](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/pdf_service.py): `app/services/pdf_service.py`
- [Local OCR](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/ocr_service.py): `app/services/ocr_service.py`
- [Table structure](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/structure_service.py): `app/services/structure_service.py`
- [Docling assist](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/docling_service.py): `app/services/docling_service.py`
- [OCR-VL assist](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/vl_service.py): `app/services/vl_service.py`
- [Layout parsing](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/layout_service.py): `app/services/layout_service.py`
- [Form parsing](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/form_parser.py): `app/services/form_parser.py`
- [Field building](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/field_builder.py): `app/services/field_builder.py`

### Review and records

- [Document repository](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/repositories/document_repository.py): `app/repositories/document_repository.py`
- [Results repository](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/repositories/results_repository.py): `app/repositories/results_repository.py`
- [Template service](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/template_service.py): `app/services/template_service.py`
- [Retention purge](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/services/retention_service.py): `app/services/retention_service.py`

### Local platform

- [Application database](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/models.py): `app/models.py`
- [Protected PDF files](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/security/files.py): `app/security/files.py`
- [Extraction schemas](https://github.com/bcss-nandeep/charge_sheet_ocr/blob/main/app/schemas/charge_sheet.py): `app/schemas/charge_sheet.py`

### Other components

- **Operator / reviewer**

## Connections

- Operator / reviewer → Upload API: uploads PDF (evidence: `README.md`)
- Operator / reviewer → Results API: reviews results (evidence: `README.md`)
- Upload API → Role authorization: checks role (evidence: `app/api/routes_upload.py`)
- Results API → Role authorization: checks role (evidence: `app/api/routes_results.py`)
- Upload API → Document repository: creates record (evidence: `app/api/routes_upload.py`)
- Upload API → Protected PDF files: stores upload (evidence: `app/api/routes_upload.py`)
- Upload API → Processing coordinator: queues processing (evidence: `app/api/routes_upload.py`)
- Document API → Processing coordinator: queues reprocess (evidence: `app/api/routes_documents.py`)
- Processing coordinator → Extraction pipeline: runs extraction (evidence: `app/services/processing_service.py`)
- Processing coordinator → Document repository: updates status (evidence: `app/services/processing_service.py`)
- Processing coordinator → Results repository: persists results (evidence: `app/services/processing_service.py`)
- Extraction pipeline → PDF page routing: routes pages (evidence: `app/services/extraction_service.py`)
- Extraction pipeline → Local OCR: reads scans (evidence: `app/services/extraction_service.py`)
- Extraction pipeline → Table structure: parses structure (evidence: `app/services/extraction_service.py`)
- Extraction pipeline → Docling assist: assists digital forms (evidence: `README.md`)
- Extraction pipeline → OCR-VL assist: assists hard pages (evidence: `README.md`)
- Extraction pipeline → Layout parsing: builds layout items (evidence: `app/services/extraction_service.py`)
- Extraction pipeline → Form parsing: parses forms (evidence: `app/services/extraction_service.py`)
- Extraction pipeline → Field building: builds fields (evidence: `app/services/extraction_service.py`)
- Extraction pipeline → Extraction schemas: returns field data (evidence: `app/services/extraction_service.py`)
- Results API → Document repository: reads metadata (evidence: `app/api/routes_results.py`)
- Results API → Results repository: reads saved results (evidence: `app/api/routes_results.py`)
- Document API → Document repository: reads document records (evidence: `app/api/routes_documents.py`)
- Document API → Retention purge: purges expired data (evidence: `app/api/routes_documents.py`)
- Document API → Template service: lists templates (evidence: `app/api/routes_documents.py`)
- Document repository → Application database: persists records (evidence: `app/repositories/document_repository.py`)
- Results repository → Application database: persists extraction (evidence: `app/repositories/results_repository.py`)
- Retention purge → Protected PDF files: deletes stored PDFs (evidence: `app/services/retention_service.py`)
- Retention purge → Document repository: purges records (evidence: `app/services/retention_service.py`)
