# soni-shivam/c-s-cool-stuff architecture

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

- Interactive diagram: https://gitdiagram.com/soni-shivam/c-s-cool-stuff
- Repository: https://github.com/soni-shivam/c-s-cool-stuff

## Overview

#### Purpose and entry points
DRISHTI is a defensive Android APK triage system: it produces calibrated threat scoring, evidence-grounded analysis, signed provenance, and reports. The primary backend orchestration entry point is `drishti/pipeline.py`; API startup and job control are in `drishti/api/main.py` and `drishti/api/jobs.py`. `Makefile` drives local install, test, and API startup. `v1-reference/` is a frozen, non-imported predecessor.

#### Contract-first analysis boundary
Typed contracts define handoffs among all stages: APK/corpus inputs, static findings, dynamic traces, AI verdicts, scores, containment evidence, and final verdicts. These contracts are the principal compatibility boundary for the pipeline, API, UI, and Android consumer.
- `drishti/contracts/base.py`
- `drishti/contracts/static_report.py`
- `drishti/contracts/verdict.py`

#### M1–M2: ingestion and static reverse engineering
M1 validates and identifies incoming APKs, applies reputation/intelligence checks, and creates the analysis record. M2 decompiles and inspects manifests/code, call graphs, sensitive sinks, permission combinations, and brand impersonation; it produces structured evidence and hypotheses rather than an executable result.
- `drishti/m1_ingest/ingest.py`
- `drishti/m2_static/engine.py`
- `drishti/m2_static/lookalike.py`

#### M3: sealed active detonation
Dynamic execution is explicitly isolated from developer machines. Admission and containment gate samples before the detonator/harness runs them; trace ingestion and normalization turn observed device/network behavior into contracts. The system can identify evasion checks and morph the emulator environment to trigger dormant behavior. Network capture is observational via the proxy addon.
- `drishti/m3_dynamic/detonator.py`
- `drishti/m3_dynamic/harness.py`
- `drishti/m3_dynamic/normaliser.py`

#### M4–M6: grounded interpretation, ML, and fusion
The GenAI controller uses retrieval, constrained agents, safety checks, and evidence-aware tools to interpret static and dynamic artefacts; its output must remain grounded. ML derives features and runs bundled classifier/anomaly/calibration models. The scoring engine fuses these signals into the 0–100 risk score and confidence, separating interpretation from final decision policy.
- `drishti/m4_genai/controller.py`
- `drishti/m5_ml/infer.py`
- `drishti/m6_score/engine.py`

#### Provenance and deliverables
A hash-chained, Ed25519-signed ledger records evidence/provenance independently of report presentation. Reporting projects the verified analysis into case files, HTML dossiers, STIX, and YARA outputs. API routes expose analysis state, artifacts, ledger verification, and logs to consumers.
- `drishti/ledger/store.py`
- `drishti/ledger/verifier.py`
- `drishti/m7_report/dossier.py`

#### Consumers, infrastructure, and external boundaries
The React/Vite analyst console polls API jobs, artefacts, logs, and graph/report views. The separate Android Shield client watches installed packages, obtains/uses verdicts, and applies device-side policy/notifications. Android canary/decoy applications provide controlled samples. GCP Terraform/Packer and operational scripts provision sealed GCE detonation VMs with no egress, external IP, or Google identity; LLM providers are accessed through the GenAI client, outside the trusted evidence boundary.
- `ui/src/App.tsx`
- `shield/app/src/main/java/in/drishti/shield/ScanEngine.kt`
- `infra/gcp/terraform/runtime/main.tf`

Main entry points: [`drishti/contracts/base.py`](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/contracts/base.py) (Typed analysis contracts), [`drishti/api/main.py`](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/api/main.py) (API and job control), [`drishti/pipeline.py`](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/pipeline.py) (Pipeline orchestrator), [`drishti/m1_ingest/ingest.py`](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m1_ingest/ingest.py) (M1 APK ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control plane"]
  node_api["API and job control<br/>backend API<br/>[main.py]"]
  node_pipeline["Pipeline orchestrator<br/>workflow<br/>[pipeline.py]"]
  node_contracts["Typed analysis contracts<br/>compatibility boundary<br/>[base.py]"]
end

subgraph group_analysis["Analysis pipeline"]
  node_ingest["M1 APK ingestion<br/>validation and intelligence<br/>[ingest.py]"]
  node_static["M2 static analysis<br/>reverse engineering<br/>[engine.py]"]
  node_lookalike["Brand impersonation<br/>static detector<br/>[lookalike.py]"]
  node_genai["M4 grounded interpretation<br/>retrieval and agents<br/>[controller.py]"]
  node_ml["M5 ML inference<br/>models and calibration<br/>[infer.py]"]
  node_score["M6 scoring<br/>decision policy<br/>[engine.py]"]
end

subgraph group_dynamic["Sealed detonation"]
  node_admission{{"Admission and containment<br/>execution gate"}}
  node_detonation["Detonator and harness<br/>active execution<br/>[detonator.py]"]
  node_normalise["Trace normalization<br/>dynamic evidence<br/>[normaliser.py]"]
  node_sealed_infra["Sealed GCE detonation VMs<br/>GCP infrastructure<br/>[main.tf]"]
end

subgraph group_deliver["Provenance and consumers"]
  node_ledger[("Signed evidence ledger<br/>hash-chained provenance<br/>[store.py]")]
  node_verify["Ledger verification<br/>provenance verifier<br/>[verifier.py]"]
  node_report["M7 reports and exports<br/>case deliverables<br/>[dossier.py]"]
  node_console["Analyst console<br/>React/Vite UI<br/>[App.tsx]"]
  node_shield["Android Shield client<br/>device policy client<br/>[ScanEngine.kt]"]
end

node_llm(("LLM providers<br/>external service"))

node_api -->|"starts jobs"| node_pipeline
node_console -->|"polls jobs and artifacts"| node_api
node_shield -->|"obtains verdicts"| node_api
node_pipeline -->|"APK input"| node_ingest
node_ingest -->|"analysis record"| node_contracts
node_ingest -->|"validated APK"| node_static
node_static -->|"app identity evidence"| node_lookalike
node_static -->|"static findings"| node_contracts
node_pipeline -->|"candidate sample"| node_admission
node_admission -->|"approved sample"| node_detonation
node_sealed_infra -.->|"isolated runtime"| node_detonation
node_detonation -->|"device and network traces"| node_normalise
node_normalise -->|"dynamic traces"| node_contracts
node_contracts -->|"evidence"| node_genai
node_llm -.->|"model responses"| node_genai
node_contracts -->|"features"| node_ml
node_genai -->|"grounded verdict"| node_score
node_ml -->|"calibrated signals"| node_score
node_score -->|"final verdict"| node_contracts
node_contracts -->|"evidence and provenance"| node_ledger
node_ledger -->|"hash chain"| node_verify
node_verify -->|"verified analysis"| node_report
node_report -->|"artifacts and state"| node_api

click node_api "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/api/main.py"
click node_pipeline "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/pipeline.py"
click node_contracts "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/contracts/base.py"
click node_ingest "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m1_ingest/ingest.py"
click node_static "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m2_static/engine.py"
click node_lookalike "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m2_static/lookalike.py"
click node_detonation "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m3_dynamic/detonator.py"
click node_normalise "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m3_dynamic/normaliser.py"
click node_genai "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m4_genai/controller.py"
click node_ml "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m5_ml/infer.py"
click node_score "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m6_score/engine.py"
click node_ledger "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/ledger/store.py"
click node_verify "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/ledger/verifier.py"
click node_report "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m7_report/dossier.py"
click node_console "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/ui/src/App.tsx"
click node_shield "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/shield/app/src/main/java/in/drishti/shield/ScanEngine.kt"
click node_sealed_infra "https://github.com/soni-shivam/c-s-cool-stuff/blob/main/infra/gcp/terraform/runtime/main.tf"

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_pipeline,node_contracts toneBlue
class node_ingest,node_static,node_lookalike,node_genai,node_ml,node_score toneAmber
class node_admission,node_detonation,node_normalise,node_sealed_infra toneMint
class node_ledger,node_verify,node_report,node_console,node_shield toneRose
class node_llm toneNeutral
```

## Components

### Control plane

- [API and job control](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/api/main.py): backend API · `drishti/api/main.py`
- [Pipeline orchestrator](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/pipeline.py): workflow · `drishti/pipeline.py`
- [Typed analysis contracts](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/contracts/base.py): compatibility boundary · Shared handoffs for evidence, traces, scores, and verdicts. · `drishti/contracts/base.py`

### Analysis pipeline

- [M1 APK ingestion](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m1_ingest/ingest.py): validation and intelligence · `drishti/m1_ingest/ingest.py`
- [M2 static analysis](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m2_static/engine.py): reverse engineering · Produces structured evidence and hypotheses. · `drishti/m2_static/engine.py`
- [Brand impersonation](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m2_static/lookalike.py): static detector · `drishti/m2_static/lookalike.py`
- [M4 grounded interpretation](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m4_genai/controller.py): retrieval and agents · Uses constrained, evidence-aware tools and safety checks. · `drishti/m4_genai/controller.py`
- [M5 ML inference](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m5_ml/infer.py): models and calibration · `drishti/m5_ml/infer.py`
- [M6 scoring](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m6_score/engine.py): decision policy · Fuses signals into risk score and confidence. · `drishti/m6_score/engine.py`

### Sealed detonation

Execution is isolated from developer machines.

- **Admission and containment**: execution gate · Gates samples before active execution.
- [Detonator and harness](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m3_dynamic/detonator.py): active execution · `drishti/m3_dynamic/detonator.py`
- [Trace normalization](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m3_dynamic/normaliser.py): dynamic evidence · Normalizes observed device and network behavior. · `drishti/m3_dynamic/normaliser.py`
- [Sealed GCE detonation VMs](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/infra/gcp/terraform/runtime/main.tf): GCP infrastructure · Provisioned with no egress, external IP, or Google identity. · `infra/gcp/terraform/runtime/main.tf`

### Provenance and consumers

- [Signed evidence ledger](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/ledger/store.py): hash-chained provenance · Ed25519-signed evidence is independent of presentation. · `drishti/ledger/store.py`
- [Ledger verification](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/ledger/verifier.py): provenance verifier · `drishti/ledger/verifier.py`
- [M7 reports and exports](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/drishti/m7_report/dossier.py): case deliverables · Projects verified analysis into dossiers, STIX, and YARA. · `drishti/m7_report/dossier.py`
- [Analyst console](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/ui/src/App.tsx): React/Vite UI · `ui/src/App.tsx`
- [Android Shield client](https://github.com/soni-shivam/c-s-cool-stuff/blob/main/shield/app/src/main/java/in/drishti/shield/ScanEngine.kt): device policy client · Watches packages and applies verdict-driven policy. · `shield/app/src/main/java/in/drishti/shield/ScanEngine.kt`

### Other components

- **LLM providers**: external service · Outside the trusted evidence boundary.

## Connections

- API and job control → Pipeline orchestrator: starts jobs
- Analyst console → API and job control: polls jobs and artifacts
- Android Shield client → API and job control: obtains verdicts
- Pipeline orchestrator → M1 APK ingestion: APK input
- M1 APK ingestion → Typed analysis contracts: analysis record
- M1 APK ingestion → M2 static analysis: validated APK
- M2 static analysis → Brand impersonation: app identity evidence
- M2 static analysis → Typed analysis contracts: static findings
- Pipeline orchestrator → Admission and containment: candidate sample
- Admission and containment → Detonator and harness: approved sample
- Sealed GCE detonation VMs → Detonator and harness: isolated runtime
- Detonator and harness → Trace normalization: device and network traces
- Trace normalization → Typed analysis contracts: dynamic traces
- Typed analysis contracts → M4 grounded interpretation: evidence
- LLM providers → M4 grounded interpretation: model responses
- Typed analysis contracts → M5 ML inference: features
- M4 grounded interpretation → M6 scoring: grounded verdict
- M5 ML inference → M6 scoring: calibrated signals
- M6 scoring → Typed analysis contracts: final verdict
- Typed analysis contracts → Signed evidence ledger: evidence and provenance
- Signed evidence ledger → Ledger verification: hash chain
- Ledger verification → M7 reports and exports: verified analysis
- M7 reports and exports → API and job control: artifacts and state
