# ksacheth/sih-2026 architecture

> Architecture diagram of the GitHub repository ksacheth/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/ksacheth/sih-2026
- Repository: https://github.com/ksacheth/sih-2026

## Overview

#### Purpose and Runtime Shape
This is a privacy-preserving personal data exposure monitor. A Next.js App Router application accepts user identifiers, discovers public/breach evidence, extracts and correlates PII, assigns deterministic risk, and presents remediation actions. A separate Python/FastAPI sidecar provides GLiNER-based extraction. The repository includes both scaffolded product layers and a production evaluation dataset.

Primary application entry points: `src/app/page.tsx`, `src/app/dashboard/page.tsx`, `src/app/api/scan/route.ts`, and `sidecar/main.py`.

#### API and User Boundary
Next.js Route Handlers form the application boundary for authenticated account, identifier, scan, exposure, and health operations. The UI is a dashboard/onboarding client layered over those APIs, rather than a separate backend service.

Key paths:
- `src/app/api/auth/[...nextauth]/route.ts`
- `src/app/api/identifiers/route.ts`
- `src/app/api/scan/route.ts`
- `src/components/dashboard/dashboard-client.tsx`
- `src/lib/auth/require-user.ts`

#### Scan Orchestration
The scan pipeline is the central control flow: validate and normalize identifiers; create/manage scan state; invoke permitted discovery connectors; then pass collected evidence to extraction, correlation, rules, and persistence/presentation stages. Fetch protections constrain external retrieval.

Key paths:
- `src/lib/pipeline/orchestrator.ts`
- `src/lib/pipeline/scanState.ts`
- `src/lib/pipeline/fetchGuard.ts`
- `src/lib/validation.ts`
- `src/lib/identifiers.ts`

#### Discovery Connectors and External Services
Connectors isolate third-party discovery semantics behind a shared contract. Expected sources include Serper.dev web search, ExposedOrNot, optional HIBP, Pwned Passwords range API, and the local broker catalog. Cache support limits repeated external calls.

Key paths:
- `src/lib/connectors/index.ts`
- `src/lib/connectors/types.ts`
- `src/lib/connectors/serper.ts`
- `src/lib/connectors/exposedOrNot.ts`
- `src/lib/connectors/cache.ts`
- `data/brokers.json`

#### Evidence Extraction and Correlation
Raw source responses are converted to extracted identifiers using rules/checksums and the GLiNER sidecar, then fused and matched against the user’s identity. This is the key boundary between untrusted external content and internally assessed evidence.

Key paths:
- `src/lib/extraction/client.ts`
- `src/lib/extraction/fusion.ts`
- `src/lib/correlation/pipelineAdapter.ts`
- `src/lib/correlation/nameMatcher.ts`
- `sidecar/app.py`
- `sidecar/schemas.py`

#### Deterministic Risk and Action Layer
Rules turn correlated evidence into severity, confidence, threats, broker context, and recommendations. LLM output is limited to explaining an already-redacted finding; it is not an evidence, identity, or severity authority. Monitoring tracks future exposure state via fingerprints and a state machine.

Key paths:
- `src/lib/rules/rulesEngine.ts` is not present; rule modules are under `src/lib/rules/`
- `src/lib/rules/confidence.ts`
- `src/lib/rules/severity.ts`
- `src/lib/rules/recommendations.ts`
- `src/lib/llm/explain.ts`
- `src/lib/monitoring/stateMachine.ts`

#### Data, Security, and Operations
MongoDB Atlas is the durable store, with TTL-oriented cache/quota support implied by models and connector caching. Sensitive values are normalized, masked, encrypted/audited, rate-limited, and redacted before Gemini. Docker Compose coordinates the application, Mongo initialization, and sidecar runtime.

Key paths:
- `src/lib/models/db.ts`
- `src/lib/models/Cache.ts`
- `src/lib/security/crypto.ts`
- `src/lib/security/audit.ts`
- `src/lib/security/rate-limit.ts`
- `Docker-compose.yml`
- `scripts/init-mongo.js`

#### Evaluation Asset Boundary
The golden corpus, decoys, ground truth, generator, and Python evaluators are offline quality assets for correlation/detection validation, not runtime discovery infrastructure.

Key paths:
- `data/eval/ground_truth.json`
- `data/eval/corpus/`
- `advanced_evaluator.py`
- `validate_dataset.py`

Main entry points: [`src/app/api/scan/route.ts`](https://github.com/ksacheth/sih-2026/blob/main/src/app/api/scan/route.ts) (Authenticated API routes), [`src/lib/pipeline/orchestrator.ts`](https://github.com/ksacheth/sih-2026/blob/main/src/lib/pipeline/orchestrator.ts) (Scan orchestrator), [`src/lib/connectors/index.ts`](https://github.com/ksacheth/sih-2026/blob/main/src/lib/connectors/index.ts) (Discovery connectors), [`src/lib/extraction/fusion.ts`](https://github.com/ksacheth/sih-2026/blob/main/src/lib/extraction/fusion.ts) (Extraction fusion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js application"]
  node_ui["Dashboard &amp; onboarding<br/>Next.js client UI"]
  node_routes["Authenticated API routes<br/>Next.js Route Handlers<br/>[route.ts]"]
  node_auth["User authorization<br/>auth guard<br/>[require-user.ts]"]
end

subgraph group_pipeline["Scan assessment pipeline"]
  node_validation["Identifier normalization<br/>validation<br/>[validation.ts]"]
  node_orchestrator{{"Scan orchestrator<br/>pipeline control<br/>[orchestrator.ts]"}}
  node_scanstate["Scan state<br/>scan lifecycle<br/>[scanState.ts]"]
  node_fetchguard["Fetch protections<br/>external retrieval guard<br/>[fetchGuard.ts]"]
  node_connectors["Discovery connectors<br/>source adapter contract<br/>[index.ts]"]
  node_connectorcache["Connector cache<br/>TTL cache<br/>[cache.ts]"]
  node_brokers["Broker catalog<br/>source catalog<br/>[brokers.json]"]
  node_extraction["Extraction fusion<br/>evidence extraction<br/>[fusion.ts]"]
  node_correlation["Identity correlation<br/>evidence matching<br/>[pipelineAdapter.ts]"]
  node_risk["Deterministic risk rules<br/>risk assessment<br/>[severity.ts]"]
  node_monitoring["Exposure monitoring<br/>state machine<br/>[stateMachine.ts]"]
  node_explain["Redacted finding explanation<br/>LLM explanation<br/>[explain.ts]"]
end

subgraph group_sidecar["Extraction sidecar"]
  node_sidecarapi{{"GLiNER extraction API<br/>FastAPI service<br/>[main.py]"}}
  node_sidecarschema["Extraction schemas<br/>API schemas<br/>[schemas.py]"]
end

subgraph group_data["Data and operations"]
  node_mongo[("MongoDB Atlas<br/>durable datastore<br/>[db.ts]")]
  node_security["Security controls<br/>privacy controls<br/>[crypto.ts]"]
  node_compose["Container runtime<br/>Docker Compose<br/>[Docker-compose.yml]"]
end

subgraph group_eval["Offline evaluation"]
  node_evaluation["Golden evaluation dataset<br/>offline quality corpus<br/>[ground_truth.json]"]
  node_evaluators["Python evaluators<br/>offline validation"]
end

node_ui -->|"uses"| node_routes
node_routes -->|"authorizes"| node_auth
node_routes -->|"validates input"| node_validation
node_routes -->|"starts scan"| node_orchestrator
node_orchestrator -->|"manages"| node_scanstate
node_orchestrator -->|"constrains retrieval"| node_fetchguard
node_fetchguard -->|"permits calls"| node_connectors
node_connectors -->|"reads/writes"| node_connectorcache
node_connectors -->|"uses catalog"| node_brokers
node_connectors -->|"raw evidence"| node_extraction
node_extraction -->|"GLiNER extraction"| node_sidecarapi
node_sidecarapi -->|"uses"| node_sidecarschema
node_extraction -->|"fused identifiers"| node_correlation
node_correlation -->|"matched evidence"| node_risk
node_risk -->|"findings and fingerprints"| node_monitoring
node_risk -->|"redacted finding"| node_explain
node_orchestrator -->|"persists scans"| node_mongo
node_routes -->|"protects access"| node_security
node_security -->|"encrypts/audits"| node_mongo
node_compose -->|"runs"| node_sidecarapi
node_compose -->|"initializes"| node_mongo
node_evaluators -->|"validates"| node_evaluation

click node_ui "https://github.com/ksacheth/sih-2026/blob/main/src/components/dashboard/dashboard-client.tsx"
click node_routes "https://github.com/ksacheth/sih-2026/blob/main/src/app/api/scan/route.ts"
click node_auth "https://github.com/ksacheth/sih-2026/blob/main/src/lib/auth/require-user.ts"
click node_validation "https://github.com/ksacheth/sih-2026/blob/main/src/lib/validation.ts"
click node_orchestrator "https://github.com/ksacheth/sih-2026/blob/main/src/lib/pipeline/orchestrator.ts"
click node_scanstate "https://github.com/ksacheth/sih-2026/blob/main/src/lib/pipeline/scanState.ts"
click node_fetchguard "https://github.com/ksacheth/sih-2026/blob/main/src/lib/pipeline/fetchGuard.ts"
click node_connectors "https://github.com/ksacheth/sih-2026/blob/main/src/lib/connectors/index.ts"
click node_connectorcache "https://github.com/ksacheth/sih-2026/blob/main/src/lib/connectors/cache.ts"
click node_brokers "https://github.com/ksacheth/sih-2026/blob/main/data/brokers.json"
click node_extraction "https://github.com/ksacheth/sih-2026/blob/main/src/lib/extraction/fusion.ts"
click node_correlation "https://github.com/ksacheth/sih-2026/blob/main/src/lib/correlation/pipelineAdapter.ts"
click node_risk "https://github.com/ksacheth/sih-2026/blob/main/src/lib/rules/severity.ts"
click node_monitoring "https://github.com/ksacheth/sih-2026/blob/main/src/lib/monitoring/stateMachine.ts"
click node_explain "https://github.com/ksacheth/sih-2026/blob/main/src/lib/llm/explain.ts"
click node_sidecarapi "https://github.com/ksacheth/sih-2026/blob/main/sidecar/main.py"
click node_sidecarschema "https://github.com/ksacheth/sih-2026/blob/main/sidecar/schemas.py"
click node_mongo "https://github.com/ksacheth/sih-2026/blob/main/src/lib/models/db.ts"
click node_security "https://github.com/ksacheth/sih-2026/blob/main/src/lib/security/crypto.ts"
click node_compose "https://github.com/ksacheth/sih-2026/blob/main/Docker-compose.yml"
click node_evaluation "https://github.com/ksacheth/sih-2026/blob/main/data/eval/ground_truth.json"
click node_evaluators "https://github.com/ksacheth/sih-2026/blob/main/advanced_evaluator.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_ui,node_routes,node_auth toneBlue
class node_validation,node_orchestrator,node_scanstate,node_fetchguard,node_connectors,node_connectorcache,node_brokers,node_extraction,node_correlation,node_risk,node_monitoring,node_explain toneAmber
class node_sidecarapi,node_sidecarschema toneMint
class node_mongo,node_security,node_compose toneRose
class node_evaluation,node_evaluators toneIndigo
```

## Components

### Next.js application

User-facing UI and authenticated route handlers.

- [Dashboard & onboarding](https://github.com/ksacheth/sih-2026/blob/main/src/components/dashboard/dashboard-client.tsx): Next.js client UI · `src/components/dashboard/dashboard-client.tsx`
- [Authenticated API routes](https://github.com/ksacheth/sih-2026/blob/main/src/app/api/scan/route.ts): Next.js Route Handlers · Account, identifier, scan, exposure, and health boundary. · `src/app/api/scan/route.ts`
- [User authorization](https://github.com/ksacheth/sih-2026/blob/main/src/lib/auth/require-user.ts): auth guard · `src/lib/auth/require-user.ts`

### Scan assessment pipeline

Transforms identifiers and external evidence into findings.

- [Identifier normalization](https://github.com/ksacheth/sih-2026/blob/main/src/lib/validation.ts): validation · `src/lib/validation.ts`
- [Scan orchestrator](https://github.com/ksacheth/sih-2026/blob/main/src/lib/pipeline/orchestrator.ts): pipeline control · Coordinates discovery, assessment, persistence, and scan state. · `src/lib/pipeline/orchestrator.ts`
- [Scan state](https://github.com/ksacheth/sih-2026/blob/main/src/lib/pipeline/scanState.ts): scan lifecycle · `src/lib/pipeline/scanState.ts`
- [Fetch protections](https://github.com/ksacheth/sih-2026/blob/main/src/lib/pipeline/fetchGuard.ts): external retrieval guard · `src/lib/pipeline/fetchGuard.ts`
- [Discovery connectors](https://github.com/ksacheth/sih-2026/blob/main/src/lib/connectors/index.ts): source adapter contract · Adapters cover search, breach, password, and broker sources. · `src/lib/connectors/index.ts`
- [Connector cache](https://github.com/ksacheth/sih-2026/blob/main/src/lib/connectors/cache.ts): TTL cache · Limits repeated third-party calls. · `src/lib/connectors/cache.ts`
- [Broker catalog](https://github.com/ksacheth/sih-2026/blob/main/data/brokers.json): source catalog · `data/brokers.json`
- [Extraction fusion](https://github.com/ksacheth/sih-2026/blob/main/src/lib/extraction/fusion.ts): evidence extraction · Combines rule/checksum extraction with sidecar entities. · `src/lib/extraction/fusion.ts`
- [Identity correlation](https://github.com/ksacheth/sih-2026/blob/main/src/lib/correlation/pipelineAdapter.ts): evidence matching · Matches fused identifiers to the user's identity. · `src/lib/correlation/pipelineAdapter.ts`
- [Deterministic risk rules](https://github.com/ksacheth/sih-2026/blob/main/src/lib/rules/severity.ts): risk assessment · Derives confidence, severity, threats, and recommendations. · `src/lib/rules/severity.ts`
- [Exposure monitoring](https://github.com/ksacheth/sih-2026/blob/main/src/lib/monitoring/stateMachine.ts): state machine · Tracks future exposure state using fingerprints. · `src/lib/monitoring/stateMachine.ts`
- [Redacted finding explanation](https://github.com/ksacheth/sih-2026/blob/main/src/lib/llm/explain.ts): LLM explanation · Gemini can explain findings but cannot determine evidence or severity. · `src/lib/llm/explain.ts`

### Extraction sidecar

FastAPI service for GLiNER-based entity extraction.

- [GLiNER extraction API](https://github.com/ksacheth/sih-2026/blob/main/sidecar/main.py): FastAPI service · `sidecar/main.py`
- [Extraction schemas](https://github.com/ksacheth/sih-2026/blob/main/sidecar/schemas.py): API schemas · `sidecar/schemas.py`

### Data and operations

Durable storage, security controls, and runtime coordination.

- [MongoDB Atlas](https://github.com/ksacheth/sih-2026/blob/main/src/lib/models/db.ts): durable datastore · Stores accounts, scans, findings, cache, and quota data. · `src/lib/models/db.ts`
- [Security controls](https://github.com/ksacheth/sih-2026/blob/main/src/lib/security/crypto.ts): privacy controls · Encryption, audit, masking, redaction, and rate limiting. · `src/lib/security/crypto.ts`
- [Container runtime](https://github.com/ksacheth/sih-2026/blob/main/Docker-compose.yml): Docker Compose · Coordinates app, Mongo initialization, and extraction sidecar. · `Docker-compose.yml`

### Offline evaluation

Quality assets excluded from runtime discovery.

- [Golden evaluation dataset](https://github.com/ksacheth/sih-2026/blob/main/data/eval/ground_truth.json): offline quality corpus · Corpus, decoys, and ground truth validate detection and correlation. · `data/eval/ground_truth.json`
- [Python evaluators](https://github.com/ksacheth/sih-2026/blob/main/advanced_evaluator.py): offline validation · `advanced_evaluator.py`

## Connections

- Dashboard & onboarding → Authenticated API routes: uses
- Authenticated API routes → User authorization: authorizes
- Authenticated API routes → Identifier normalization: validates input
- Authenticated API routes → Scan orchestrator: starts scan
- Scan orchestrator → Scan state: manages
- Scan orchestrator → Fetch protections: constrains retrieval
- Fetch protections → Discovery connectors: permits calls
- Discovery connectors → Connector cache: reads/writes
- Discovery connectors → Broker catalog: uses catalog
- Discovery connectors → Extraction fusion: raw evidence
- Extraction fusion → GLiNER extraction API: GLiNER extraction
- GLiNER extraction API → Extraction schemas: uses
- Extraction fusion → Identity correlation: fused identifiers
- Identity correlation → Deterministic risk rules: matched evidence
- Deterministic risk rules → Exposure monitoring: findings and fingerprints
- Deterministic risk rules → Redacted finding explanation: redacted finding
- Scan orchestrator → MongoDB Atlas: persists scans
- Authenticated API routes → Security controls: protects access
- Security controls → MongoDB Atlas: encrypts/audits
- Container runtime → GLiNER extraction API: runs
- Container runtime → MongoDB Atlas: initializes
- Python evaluators → Golden evaluation dataset: validates
