# ravindra4158/sih_2026 architecture

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

- Interactive diagram: https://gitdiagram.com/ravindra4158/sih_2026
- Repository: https://github.com/ravindra4158/sih_2026

## Overview

#### Purpose and entry points
This is an AI-assisted identity-document screening MVP. A React/Vite officer interface submits document uploads to a FastAPI backend, which produces explainable screening evidence rather than authenticity proof. Backend startup is `backend/app/main.py`; frontend bootstrap is `frontend/src/main.jsx` with UI composition in `frontend/src/App.jsx`.

#### HTTP/API boundary
Versioned FastAPI routes separate document processing, biometrics, forensics, checksum, and screening concerns. The document routes own upload/process/verification-facing interactions; request and report contracts are centralized in model modules.
- `backend/app/api/v1/document.py`
- `backend/app/api/v1/screening.py`
- `backend/app/models/request_models.py`
- `backend/app/models/response_models.py`

#### Document-processing orchestration
The primary flow is: multipart upload validation and temporary handling → image/PDF preparation → OCR and extraction → structural/forensic checks → deterministic screening/risk result. The orchestration service should coordinate stages rather than route handlers embedding processing logic. Shared case/report shapes support metadata-only history and results.
- `backend/app/services/orchestration_service.py`
- `backend/app/services/ocr_service.py`
- `backend/app/services/layout_validation_service.py`
- `backend/app/models/case_models.py`

#### Evidence and verification stages
Independent service boundaries allow screening signals to be reported separately and replaced later with trained models or integrations. OCR supports document data recovery; Aadhaar QR and barcode services add machine-readable evidence; checksum, cross-reference, ELA, and biometric services contribute validation or forensic signals.
- `backend/app/services/aadhaar_qr_service.py`
- `backend/app/services/barcode_service.py`
- `backend/app/services/checksum_service.py`
- `backend/app/services/cross_reference_service.py`
- `backend/app/services/ela_service.py`
- `backend/app/services/biometrics_service.py`

#### Client workflow
The frontend is a dashboard-style review application: upload and preview documents, inspect OCR/validation/forensics/biometric results, and review case-level risk and alerts. API access is isolated from view components; `useCaseData` is the likely client-side case state boundary. Some UI data may remain mock-backed during MVP development.
- `frontend/src/services/api.js`
- `frontend/src/hooks/useCaseData.js`
- `frontend/src/pages/CaseDetails/index.jsx`
- `frontend/src/components/DocumentUpload/index.jsx`
- `frontend/src/components/RiskScore/index.jsx`

#### Runtime, storage, and integration boundaries
Backend runtime is Python/FastAPI; frontend runtime is Node-based React/Vite. Docker Compose provides local container orchestration. Configuration controls CORS, upload limits, and temporary storage. MongoDB has a dedicated adapter boundary, while document database, external API, and watchlist integrations are intentionally empty extension points. Raw uploads are intended to be short-lived rather than durable records.
- `backend/app/config/settings.py`
- `backend/app/database/mongodb.py`
- `backend/app/integrations/document_database/.gitkeep`
- `backend/app/integrations/external_apis/.gitkeep`
- `docker-compose.yml`

#### ML lifecycle and external dependencies
The live backend uses service adapters; model development is separately organized for face, morphing, and tampering detection. Preprocessing includes image cleaning, ELA generation, and MRZ cropping. Operational capabilities depend on local OCR/PDF tooling (Tesseract and PyMuPDF) and optional MRZ-reader/DeepFace runtimes or weights; model source/weights are isolated under third-party and model directories.
- `ml/preprocessing/image_cleaning.py`
- `ml/preprocessing/ela_generation.py`
- `ml/training/tampering/train.py`
- `third_party/mrz_model/source`
- `third_party/face_model/source`

Main entry points: [`backend/app/services/orchestration_service.py`](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/orchestration_service.py) (Screening orchestrator), [`backend/app/api/v1/document.py`](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/api/v1/document.py) (Versioned API routes), [`frontend/src/hooks/useCaseData.js`](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/hooks/useCaseData.js) (Case data state), [`frontend/src/pages/CaseDetails/index.jsx`](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/pages/CaseDetails/index.jsx) (Case review UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["FastAPI backend"]
  node_backend_main{{"Backend startup<br/>FastAPI entrypoint<br/>[main.py]"}}
  node_api["Versioned API routes<br/>HTTP boundary<br/>[document.py]"]
  node_contracts["Request/report contracts<br/>Pydantic models<br/>[request_models.py]"]
  node_orchestration["Screening orchestrator<br/>pipeline service"]
  node_ocr["OCR and extraction<br/>evidence service<br/>[ocr_service.py]"]
  node_layout["Layout validation<br/>evidence service"]
  node_machine_evidence["QR and barcode evidence<br/>evidence services"]
  node_verification["Verification signals<br/>evidence services"]
  node_case_models["Case and report shapes<br/>domain models<br/>[case_models.py]"]
  node_settings["Runtime settings<br/>configuration boundary<br/>[settings.py]"]
  node_mongodb[("MongoDB adapter<br/>persistence boundary<br/>[mongodb.py]")]
  node_integration_slots["Future integrations<br/>extension points<br/>[.gitkeep]"]
end

subgraph group_frontend["Officer client"]
  node_frontend_main{{"Client bootstrap<br/>React/Vite entrypoint<br/>[main.jsx]"}}
  node_case_state["Case data state<br/>client state boundary<br/>[useCaseData.js]"]
  node_client_api["API client<br/>HTTP client<br/>[api.js]"]
  node_review_ui["Case review UI<br/>dashboard view<br/>[index.jsx]"]
  node_upload_ui["Document upload<br/>UI component<br/>[index.jsx]"]
  node_risk_ui["Risk score view<br/>UI component<br/>[index.jsx]"]
end

subgraph group_ml["ML lifecycle"]
  node_ml_preprocessing["ML preprocessing<br/>training pipeline<br/>[image_cleaning.py]"]
  node_tampering_training["Tampering training<br/>model training<br/>[train.py]"]
  node_model_assets["Third-party model assets<br/>model sources"]
end

node_compose["Local containers<br/>Docker Compose<br/>[docker-compose.yml]"]

node_compose -->|"runs"| node_backend_main
node_compose -->|"runs"| node_frontend_main
node_backend_main -->|"mounts"| node_api
node_api -->|"uses"| node_contracts
node_api -->|"submits processing"| node_orchestration
node_orchestration -->|"extracts text"| node_ocr
node_orchestration -->|"checks structure"| node_layout
node_orchestration -->|"reads codes"| node_machine_evidence
node_orchestration -->|"collects signals"| node_verification
node_orchestration -->|"produces case report"| node_case_models
node_orchestration -->|"persists metadata/results"| node_mongodb
node_settings -.->|"configures limits/temp files"| node_orchestration
node_integration_slots -.->|"future evidence sources"| node_orchestration
node_frontend_main -->|"initializes"| node_case_state
node_case_state -->|"loads/submits cases"| node_client_api
node_client_api -->|"HTTP requests"| node_api
node_case_state -->|"supplies case data"| node_review_ui
node_review_ui -->|"composes"| node_upload_ui
node_review_ui -->|"composes"| node_risk_ui
node_ml_preprocessing -->|"prepares training inputs"| node_tampering_training
node_tampering_training -.->|"uses model assets"| node_model_assets
node_model_assets -.->|"optional runtime models"| node_verification

click node_backend_main "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/main.py"
click node_api "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/api/v1/document.py"
click node_contracts "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/models/request_models.py"
click node_orchestration "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/orchestration_service.py"
click node_ocr "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/ocr_service.py"
click node_layout "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/layout_validation_service.py"
click node_machine_evidence "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/aadhaar_qr_service.py"
click node_verification "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/checksum_service.py"
click node_case_models "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/models/case_models.py"
click node_settings "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/config/settings.py"
click node_mongodb "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/database/mongodb.py"
click node_integration_slots "https://github.com/ravindra4158/sih_2026/blob/main/backend/app/integrations/document_database/.gitkeep"
click node_frontend_main "https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/main.jsx"
click node_case_state "https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/hooks/useCaseData.js"
click node_client_api "https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/services/api.js"
click node_review_ui "https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/pages/CaseDetails/index.jsx"
click node_upload_ui "https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/components/DocumentUpload/index.jsx"
click node_risk_ui "https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/components/RiskScore/index.jsx"
click node_ml_preprocessing "https://github.com/ravindra4158/sih_2026/blob/main/ml/preprocessing/image_cleaning.py"
click node_tampering_training "https://github.com/ravindra4158/sih_2026/blob/main/ml/training/tampering/train.py"
click node_model_assets "https://github.com/ravindra4158/sih_2026/tree/main/third_party/mrz_model/source"
click node_compose "https://github.com/ravindra4158/sih_2026/blob/main/docker-compose.yml"

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_backend_main,node_api,node_contracts,node_orchestration,node_ocr,node_layout,node_machine_evidence,node_verification,node_case_models,node_settings,node_mongodb,node_integration_slots toneBlue
class node_frontend_main,node_case_state,node_client_api,node_review_ui,node_upload_ui,node_risk_ui toneAmber
class node_ml_preprocessing,node_tampering_training,node_model_assets toneMint
class node_compose toneNeutral
```

## Components

### FastAPI backend

Document screening and evidence pipeline.

- [Backend startup](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/main.py): FastAPI entrypoint · `backend/app/main.py`
- [Versioned API routes](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/api/v1/document.py): HTTP boundary · Document and screening endpoints expose processing and report workflows. · `backend/app/api/v1/document.py`
- [Request/report contracts](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/models/request_models.py): Pydantic models · `backend/app/models/request_models.py`
- [Screening orchestrator](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/orchestration_service.py): pipeline service · Coordinates upload preparation, evidence stages, and deterministic risk output. · `backend/app/services/orchestration_service.py`
- [OCR and extraction](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/ocr_service.py): evidence service · `backend/app/services/ocr_service.py`
- [Layout validation](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/layout_validation_service.py): evidence service · `backend/app/services/layout_validation_service.py`
- [QR and barcode evidence](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/aadhaar_qr_service.py): evidence services · `backend/app/services/aadhaar_qr_service.py`
- [Verification signals](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/services/checksum_service.py): evidence services · Checksum, cross-reference, ELA, and biometric signals remain independently replaceable. · `backend/app/services/checksum_service.py`
- [Case and report shapes](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/models/case_models.py): domain models · Supports metadata-only history and screening results. · `backend/app/models/case_models.py`
- [Runtime settings](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/config/settings.py): configuration boundary · Controls CORS, upload limits, and temporary storage. · `backend/app/config/settings.py`
- [MongoDB adapter](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/database/mongodb.py): persistence boundary · `backend/app/database/mongodb.py`
- [Future integrations](https://github.com/ravindra4158/sih_2026/blob/main/backend/app/integrations/document_database/.gitkeep): extension points · Document database and external API adapters are intentionally empty. · `backend/app/integrations/document_database/.gitkeep`

### Officer client

React/Vite case review workflow.

- [Client bootstrap](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/main.jsx): React/Vite entrypoint · `frontend/src/main.jsx`
- [Case data state](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/hooks/useCaseData.js): client state boundary · `frontend/src/hooks/useCaseData.js`
- [API client](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/services/api.js): HTTP client · Keeps API access outside view components. · `frontend/src/services/api.js`
- [Case review UI](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/pages/CaseDetails/index.jsx): dashboard view · Shows upload, document preview, evidence, alerts, and risk. · `frontend/src/pages/CaseDetails/index.jsx`
- [Document upload](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/components/DocumentUpload/index.jsx): UI component · `frontend/src/components/DocumentUpload/index.jsx`
- [Risk score view](https://github.com/ravindra4158/sih_2026/blob/main/frontend/src/components/RiskScore/index.jsx): UI component · `frontend/src/components/RiskScore/index.jsx`

### ML lifecycle

Separately organized model development and assets.

- [ML preprocessing](https://github.com/ravindra4158/sih_2026/blob/main/ml/preprocessing/image_cleaning.py): training pipeline · Image cleaning, ELA generation, and MRZ cropping prepare model inputs. · `ml/preprocessing/image_cleaning.py`
- [Tampering training](https://github.com/ravindra4158/sih_2026/blob/main/ml/training/tampering/train.py): model training · `ml/training/tampering/train.py`
- [Third-party model assets](https://github.com/ravindra4158/sih_2026/tree/main/third_party/mrz_model/source): model sources · MRZ and face model source and weights are isolated from live service code. · `third_party/mrz_model/source`

### Other components

- [Local containers](https://github.com/ravindra4158/sih_2026/blob/main/docker-compose.yml): Docker Compose · Runs the local frontend and backend environment. · `docker-compose.yml`

## Connections

- Local containers → Backend startup: runs
- Local containers → Client bootstrap: runs
- Backend startup → Versioned API routes: mounts
- Versioned API routes → Request/report contracts: uses
- Versioned API routes → Screening orchestrator: submits processing
- Screening orchestrator → OCR and extraction: extracts text
- Screening orchestrator → Layout validation: checks structure
- Screening orchestrator → QR and barcode evidence: reads codes
- Screening orchestrator → Verification signals: collects signals
- Screening orchestrator → Case and report shapes: produces case report
- Screening orchestrator → MongoDB adapter: persists metadata/results
- Runtime settings → Screening orchestrator: configures limits/temp files
- Future integrations → Screening orchestrator: future evidence sources
- Client bootstrap → Case data state: initializes
- Case data state → API client: loads/submits cases
- API client → Versioned API routes: HTTP requests
- Case data state → Case review UI: supplies case data
- Case review UI → Document upload: composes
- Case review UI → Risk score view: composes
- ML preprocessing → Tampering training: prepares training inputs
- Tampering training → Third-party model assets: uses model assets
- Third-party model assets → Verification signals: optional runtime models
