# leeeshart/sih- architecture

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

- Interactive diagram: https://gitdiagram.com/leeeshart/sih-
- Repository: https://github.com/leeeshart/sih-

## Overview

This repository contains the AI/ML prototype for a broader proposed legal-document management system; the README says the frontend and general backend are not yet in the repository. The implemented user workflow is document upload to the FastAPI analysis endpoint, text extraction, classification, and—when applicable—Charge Sheet structural verification. The graph also shows the separate OCR-to-training-data and model-training workflow. RBAC, encrypted document storage, audit history, and blockchain integrity are documented capabilities, but their implementations are absent from the supplied tree. Relationships below are limited to the README and excerpted source.

Main entry points: [`ai_ml/api/app.py`](https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py) (Analysis API), [`ai_ml/data/processed`](https://github.com/leeeshart/sih-/tree/main/ai_ml/data/processed) (FIR OCR output), [`ai_ml/preprocessing/build_classification_dataset.py`](https://github.com/leeeshart/sih-/blob/main/ai_ml/preprocessing/build_classification_dataset.py) (Dataset assembly), [`ai_ml/classification/train_baseline.py`](https://github.com/leeeshart/sih-/blob/main/ai_ml/classification/train_baseline.py) (Baseline training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["AI service"]
  node_api["Analysis API<br/>[app.py]"]
  node_text_extraction["Upload text extraction<br/>[app.py]"]
  node_classifier["Document classification<br/>[app.py]"]
  node_response["Analysis result<br/>[app.py]"]
end

subgraph group_pipeline["ML pipeline"]
  node_model[("Trained model")]
  node_ocr["FIR image OCR<br/>[ocr_fir.py]"]
  node_ocr_data[("FIR OCR output")]
  node_dataset["Dataset assembly"]
  node_training_data[("Classification data")]
  node_training["Baseline training<br/>[train_baseline.py]"]
end

subgraph group_verification["Structural verification"]
  node_verification["Charge Sheet checks"]
end

node_user(("Police / legal user"))

node_user -->|"uploads document"| node_api
node_api -->|"extracts text"| node_text_extraction
node_text_extraction -->|"supplies text"| node_classifier
node_classifier -->|"predicts with"| node_model
node_api -->|"verifies Charge Sheet"| node_verification
node_api -->|"returns analysis"| node_response
node_response -.->|"delivers result"| node_user
node_ocr -->|"writes OCR text"| node_ocr_data
node_ocr_data -->|"provides FIR text"| node_dataset
node_dataset -->|"writes dataset"| node_training_data
node_training_data -->|"loads examples"| node_training
node_training -->|"saves model"| node_model

click node_api "https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py"
click node_text_extraction "https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py"
click node_classifier "https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py"
click node_model "https://github.com/leeeshart/sih-/tree/main/ai_ml/models"
click node_verification "https://github.com/leeeshart/sih-/blob/main/ai_ml/verification/verify_charge_sheet.py"
click node_ocr "https://github.com/leeeshart/sih-/blob/main/ai_ml/preprocessing/ocr_fir.py"
click node_ocr_data "https://github.com/leeeshart/sih-/tree/main/ai_ml/data/processed"
click node_dataset "https://github.com/leeeshart/sih-/blob/main/ai_ml/preprocessing/build_classification_dataset.py"
click node_training_data "https://github.com/leeeshart/sih-/tree/main/ai_ml/data/processed"
click node_training "https://github.com/leeeshart/sih-/blob/main/ai_ml/classification/train_baseline.py"
click node_response "https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.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_api,node_text_extraction,node_classifier,node_response,node_user toneBlue
class node_model,node_ocr,node_ocr_data,node_dataset,node_training_data,node_training toneAmber
class node_verification toneMint
```

## Components

### AI service

- [Analysis API](https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py): `ai_ml/api/app.py`
- [Upload text extraction](https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py): `ai_ml/api/app.py`
- [Document classification](https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py): `ai_ml/api/app.py`
- [Analysis result](https://github.com/leeeshart/sih-/blob/main/ai_ml/api/app.py): `ai_ml/api/app.py`

### ML pipeline

- [Trained model](https://github.com/leeeshart/sih-/tree/main/ai_ml/models): `ai_ml/models`
- [FIR image OCR](https://github.com/leeeshart/sih-/blob/main/ai_ml/preprocessing/ocr_fir.py): `ai_ml/preprocessing/ocr_fir.py`
- [FIR OCR output](https://github.com/leeeshart/sih-/tree/main/ai_ml/data/processed): `ai_ml/data/processed`
- [Dataset assembly](https://github.com/leeeshart/sih-/blob/main/ai_ml/preprocessing/build_classification_dataset.py): `ai_ml/preprocessing/build_classification_dataset.py`
- [Classification data](https://github.com/leeeshart/sih-/tree/main/ai_ml/data/processed): `ai_ml/data/processed`
- [Baseline training](https://github.com/leeeshart/sih-/blob/main/ai_ml/classification/train_baseline.py): `ai_ml/classification/train_baseline.py`

### Structural verification

- [Charge Sheet checks](https://github.com/leeeshart/sih-/blob/main/ai_ml/verification/verify_charge_sheet.py): `ai_ml/verification/verify_charge_sheet.py`

### Other components

- **Police / legal user**

## Connections

- Police / legal user → Analysis API: uploads document (evidence: `ai_ml/api/app.py`)
- Analysis API → Upload text extraction: extracts text (evidence: `ai_ml/api/app.py`)
- Upload text extraction → Document classification: supplies text (evidence: `ai_ml/api/app.py`)
- Document classification → Trained model: predicts with (evidence: `ai_ml/api/app.py`)
- Analysis API → Charge Sheet checks: verifies Charge Sheet (evidence: `ai_ml/api/app.py`)
- Analysis API → Analysis result: returns analysis (evidence: `ai_ml/api/app.py`)
- Analysis result → Police / legal user: delivers result (evidence: `ai_ml/api/app.py`)
- FIR image OCR → FIR OCR output: writes OCR text (evidence: `ai_ml/preprocessing/ocr_fir.py`)
- FIR OCR output → Dataset assembly: provides FIR text (evidence: `ai_ml/preprocessing/build_classification_dataset.py`)
- Dataset assembly → Classification data: writes dataset (evidence: `ai_ml/preprocessing/build_classification_dataset.py`)
- Classification data → Baseline training: loads examples (evidence: `ai_ml/classification/train_baseline.py`)
- Baseline training → Trained model: saves model (evidence: `ai_ml/classification/train_baseline.py`)
