# dipesh10110n1/sensitive-document-flagging-system architecture

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

- Interactive diagram: https://gitdiagram.com/dipesh10110n1/sensitive-document-flagging-system
- Repository: https://github.com/dipesh10110n1/sensitive-document-flagging-system

## Overview

DocShield AI is a privacy-focused Aadhaar/PAN document screening platform. Users upload or capture an image in the dashboard; the API routes it through visual and spatial analysis, fuses classification evidence into a three-tier risk decision, and records scans for audit and analytics. The README also documents synthetic sample generation, human audit overrides, privacy redaction, and model retraining. The API, ML engine, database, and generator are identified in the source index; detailed internal calls were not excerpted, so the edges below rely on documented product behavior rather than claims about unseen code.

Main entry points: [`frontend/app.js`](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/frontend/app.js) (Scanner dashboard), [`backend/app.py`](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py) (REST API), [`backend/ml_engine.py`](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py) (Visual embeddings), [`backend/database.py`](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/database.py) (Scan and audit store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_dashboard["Scanner dashboard<br/>[app.js]"]
  node_api["REST API<br/>[app.py]"]
  node_samples["Sample catalog<br/>[app.py]"]
  node_analytics["Scan analytics<br/>[app.py]"]
end

subgraph group_screening["Screening pipeline"]
  node_validation["Image validation<br/>[ml_engine.py]"]
  node_features["Visual embeddings<br/>[ml_engine.py]"]
  node_patches["Patch sequence<br/>[ml_engine.py]"]
  node_cluster["K-means analysis<br/>[ml_engine.py]"]
  node_hmm["HMM likelihoods<br/>[ml_engine.py]"]
  node_fusion["Evidence fusion<br/>[ml_engine.py]"]
  node_risk{{"Risk decision gate<br/>[ml_engine.py]"}}
  node_redaction["PII redaction<br/>[ml_engine.py]"]
end

subgraph group_operations["Records and review"]
  node_database[("Scan and audit store<br/>[database.py]")]
  node_audit["Audit override<br/>[app.py]"]
  node_generator["Synthetic documents<br/>[data_generator.py]"]
end

subgraph group_modeling["Model development"]
  node_training["Model training<br/>[train.py]"]
  node_model["Inference models<br/>[ml_engine.py]"]
end

node_user(("Uploader / auditor"))

node_user -->|"uploads or reviews"| node_dashboard
node_dashboard -->|"submits scans"| node_api
node_api -->|"validates image"| node_validation
node_validation -->|"preprocesses image"| node_features
node_features -->|"provides embeddings"| node_cluster
node_features -->|"extracts patch grid"| node_patches
node_patches -->|"scores sequences"| node_hmm
node_cluster -->|"supplies cluster metrics"| node_fusion
node_hmm -->|"supplies likelihoods"| node_fusion
node_fusion -->|"fuses probabilities"| node_risk
node_risk -->|"redacts flagged PII"| node_redaction
node_api -->|"records scan"| node_database
node_risk -->|"stores decision evidence"| node_database
node_dashboard -->|"requests samples"| node_samples
node_samples -.->|"uses synthetic catalog"| node_generator
node_dashboard -->|"requests analytics"| node_analytics
node_api -->|"routes audit action"| node_audit
node_audit -->|"logs override"| node_database
node_training -->|"trains models"| node_model
node_model -.->|"extracts embeddings"| node_features

click node_dashboard "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/frontend/app.js"
click node_api "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py"
click node_samples "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py"
click node_analytics "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py"
click node_validation "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_features "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_patches "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_cluster "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_hmm "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_fusion "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_risk "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_redaction "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py"
click node_database "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/database.py"
click node_audit "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py"
click node_generator "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/data_generator.py"
click node_training "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/train.py"
click node_model "https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.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_dashboard,node_api,node_samples,node_analytics toneBlue
class node_validation,node_features,node_patches,node_cluster,node_hmm,node_fusion,node_risk,node_redaction toneAmber
class node_database,node_audit,node_generator toneMint
class node_training,node_model toneRose
class node_user toneIndigo
```

## Components

### User experience

- [Scanner dashboard](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/frontend/app.js): `frontend/app.js`
- [REST API](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py): `backend/app.py`
- [Sample catalog](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py): `backend/app.py`
- [Scan analytics](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py): `backend/app.py`

### Screening pipeline

- [Image validation](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [Visual embeddings](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [Patch sequence](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [K-means analysis](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [HMM likelihoods](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [Evidence fusion](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [Risk decision gate](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [PII redaction](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`

### Records and review

- [Scan and audit store](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/database.py): `backend/database.py`
- [Audit override](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/app.py): `backend/app.py`
- [Synthetic documents](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/data_generator.py): `backend/data_generator.py`

### Model development

- [Model training](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/train.py): `train.py`
- [Inference models](https://github.com/dipesh10110n1/sensitive-document-flagging-system/blob/main/backend/ml_engine.py): `backend/ml_engine.py`

### Other components

- **Uploader / auditor**

## Connections

- Uploader / auditor → Scanner dashboard: uploads or reviews
- Scanner dashboard → REST API: submits scans
- REST API → Image validation: validates image (evidence: `backend/app.py`)
- Image validation → Visual embeddings: preprocesses image (evidence: `backend/ml_engine.py`)
- Visual embeddings → K-means analysis: provides embeddings (evidence: `backend/ml_engine.py`)
- Visual embeddings → Patch sequence: extracts patch grid (evidence: `backend/ml_engine.py`)
- Patch sequence → HMM likelihoods: scores sequences (evidence: `backend/ml_engine.py`)
- K-means analysis → Evidence fusion: supplies cluster metrics (evidence: `backend/ml_engine.py`)
- HMM likelihoods → Evidence fusion: supplies likelihoods (evidence: `backend/ml_engine.py`)
- Evidence fusion → Risk decision gate: fuses probabilities (evidence: `backend/ml_engine.py`)
- Risk decision gate → PII redaction: redacts flagged PII (evidence: `backend/ml_engine.py`)
- REST API → Scan and audit store: records scan (evidence: `backend/app.py`)
- Risk decision gate → Scan and audit store: stores decision evidence
- Scanner dashboard → Sample catalog: requests samples
- Sample catalog → Synthetic documents: uses synthetic catalog (evidence: `backend/app.py`)
- Scanner dashboard → Scan analytics: requests analytics
- REST API → Audit override: routes audit action (evidence: `backend/app.py`)
- Audit override → Scan and audit store: logs override (evidence: `backend/app.py`)
- Model training → Inference models: trains models (evidence: `train.py`)
- Inference models → Visual embeddings: extracts embeddings (evidence: `backend/ml_engine.py`)
