# pratheep-bit/frapast architecture

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

- Interactive diagram: https://gitdiagram.com/pratheep-bit/frapast
- Repository: https://github.com/pratheep-bit/frapast

## Overview

#### Purpose and entry points
frapAST is a Python 3.10+ static security scanner specialized for Frappe/ERPNext applications. It combines framework-aware indexing, AST rules, reachability context, severity scoring, optional runtime proof, and report exports.

Primary entry points are the package launcher and CLI: `scanner/__main__.py`, `scanner/cli.py`. The local dashboard is served by `scanner/web/server.py`; containerized execution is supported by `Dockerfile` and `docker-compose.yml`.

#### Scan orchestration and shared records
The CLI resolves target repositories/configuration, runs the analysis pipeline, optionally persists a findings ledger, and selects terminal, structured, or web-facing output. Shared finding/index record shapes are centralized in `scanner/shared/records.py`, while configuration is handled in `scanner/config.py`.

The main boundary is from an arbitrary Frappe application filesystem into normalized indexes and findings. Persistent tracking uses the ledger layer: `scanner/ledger_io.py`, `scanner/ledger_schema.py`.

#### Framework-aware indexing
Three analysis domains model Frappe-specific inputs:
- DocType JSON schemas and field metadata: `scanner/schema/engine.py`, `scanner/schema/models.py`.
- `hooks.py` declarations such as document events, scheduler events, and overridden methods: `scanner/hooks/engine.py`, `scanner/hooks/models.py`.
- Python modules parsed through the Python AST to discover symbols, endpoints, calls, imports, and relevant source constructs: `scanner/python/engine.py`, `scanner/python/models.py`.

These stages avoid dependence on a running Frappe instance for static scanning, while accepting source and schema conventions established by the target app.

#### Reachability and rule detection
The call-graph builder connects indexed symbols through direct calls plus Frappe dispatch mechanisms—string RPC dispatch, hook dispatch, and dynamic document methods: `scanner/callgraph/builder.py`, `scanner/callgraph/models.py`.

The rule engine evaluates graph-connected indexed code against YAML-defined detectors and their schema: `scanner/rules/engine.py`, `scanner/rules/schema.yaml`, `scanner/rules/FR-PERM-001.yaml`. Rules cover authorization, SQL injection, hooks, workflow integrity, correctness, and related Frappe risks. This is the core static-analysis boundary: indexes/call graph in, deduplicated candidate findings out.

#### Classification, suppression, and tracking
Severity is assigned through a composite model incorporating privilege, impact, blast radius, and proof tier: `scanner/severity/engine.py`, `scanner/severity/models.py`, `scanner/severity/taxonomy.py`. The taxonomy data maps findings into the broader security classification system: `scanner/taxonomy/taxonomy_registry.yaml`, `scanner/taxonomy/FR-SQLI-001.yaml`.

False-positive handling is a separate categorization flow in `scanner/fp/engine.py`, and regression artifact generation lives in `scanner/regression/generator.py`. Ledger validation/integrity tools protect persisted findings from malformed or inconsistent state: `scanner/validate_ledger.py`, `scanner/verify_ledger_integrity.py`.

#### Optional runtime proof
Proof operates after static detection and can upgrade, fail, skip, or error a candidate without deleting the underlying static evidence. The orchestrator coordinates Tier 1 local reproducer execution and Tier 2 bench verification: `scanner/proof/orchestrator.py`, `scanner/proof/bench_runner.py`.

Tier 2 crosses the only significant external-service boundary: HTTP/RPC communication with a configured local or remote Frappe bench via `scanner/proof/http_client.py` and synthesized requests in `scanner/proof/http_synthesis.py`. Tier 1 uses isolated local subprocess-style reproducer execution rather than a hosted service.

#### Delivery surfaces and CI
Reporting converts findings into terminal-friendly and machine-readable JSON, YAML, SARIF, and Markdown outputs: `scanner/reporting/engine.py`, `scanner/reporting/sarif.py`, `scanner/reporting/formatters.py`. GitHub Actions integration is represented by `action.yml` and `.github/workflows/scanner-ci.yml`.

The optional local-only dashboard provides scan/proof workflows, exports, and progress UI: `scanner/web/server.py`, `scanner/web/static/app.js`, `scanner/ui/flow.py`. It is a local Python HTTP service, not a cloud application; its intended browser boundary is loopback access.

Main entry points: [`scanner/cli.py`](https://github.com/pratheep-bit/frapast/blob/main/scanner/cli.py) (CLI launcher), [`scanner/web/server.py`](https://github.com/pratheep-bit/frapast/blob/main/scanner/web/server.py) (Local dashboard), [`scanner/proof/orchestrator.py`](https://github.com/pratheep-bit/frapast/blob/main/scanner/proof/orchestrator.py) (Proof orchestrator), [`scanner/fp/engine.py`](https://github.com/pratheep-bit/frapast/blob/main/scanner/fp/engine.py) (False-positive handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Control"]
  node_cli["CLI launcher<br/>Python CLI<br/>[cli.py]"]
  node_config["Scan configuration<br/>[config.py]"]
  node_records["Shared records<br/>data models<br/>[records.py]"]
end

subgraph group_indexing["Static Indexing"]
  node_schema_index["DocType indexer<br/>schema analysis<br/>[engine.py]"]
  node_hooks_index["Hooks indexer<br/>hooks analysis<br/>[engine.py]"]
  node_python_index["Python AST indexer<br/>AST analysis<br/>[engine.py]"]
  node_indexes[("Normalized indexes<br/>analysis data")]
end

subgraph group_analysis["Detection &amp; Enrichment"]
  node_callgraph["Frappe call graph<br/>reachability analysis<br/>[builder.py]"]
  node_rules["Rule engine<br/>detector evaluation<br/>[engine.py]"]
  node_severity["Severity scoring<br/>risk classification<br/>[engine.py]"]
  node_taxonomy["Security taxonomy<br/>classification data"]
  node_fp["False-positive handling<br/>finding categorization<br/>[engine.py]"]
  node_ledger[("Findings ledger<br/>persistent tracking<br/>[ledger_io.py]")]
end

subgraph group_delivery["Proof, Reporting &amp; UI"]
  node_proof["Proof orchestrator<br/>runtime verification<br/>[orchestrator.py]"]
  node_reporting["Report exports<br/>output rendering<br/>[engine.py]"]
  node_dashboard["Local dashboard<br/>loopback HTTP UI<br/>[server.py]"]
  node_ci["GitHub Actions<br/>CI integration<br/>[action.yml]"]
end

node_target["Frappe app source<br/>target filesystem"]
node_bench{{"Frappe bench<br/>external HTTP/RPC service"}}
node_browser(("Local browser<br/>loopback client"))

node_cli -->|"loads"| node_config
node_cli -->|"scans"| node_target
node_cli -->|"orchestrates"| node_schema_index
node_cli -->|"orchestrates"| node_hooks_index
node_cli -->|"orchestrates"| node_python_index
node_target -->|"DocType JSON"| node_schema_index
node_target -->|"hooks.py"| node_hooks_index
node_target -->|"Python modules"| node_python_index
node_schema_index -->|"schema metadata"| node_indexes
node_hooks_index -->|"event declarations"| node_indexes
node_python_index -->|"AST symbols"| node_indexes
node_indexes -->|"indexed constructs"| node_callgraph
node_callgraph -->|"reachability context"| node_rules
node_indexes -->|"source metadata"| node_rules
node_rules -->|"candidate findings"| node_severity
node_taxonomy -->|"classification mapping"| node_severity
node_severity -->|"scored findings"| node_fp
node_fp -->|"tracked findings"| node_ledger
node_fp -->|"static candidates"| node_proof
node_proof -->|"Tier 2 HTTP/RPC"| node_bench
node_proof -->|"proof outcomes"| node_ledger
node_ledger -->|"findings"| node_reporting
node_cli -->|"selects output"| node_reporting
node_dashboard -->|"starts scans"| node_cli
node_dashboard -->|"runs proof"| node_proof
node_dashboard -->|"exports"| node_reporting
node_browser -->|"loopback access"| node_dashboard
node_ci -->|"runs scanner"| node_cli

click node_cli "https://github.com/pratheep-bit/frapast/blob/main/scanner/cli.py"
click node_config "https://github.com/pratheep-bit/frapast/blob/main/scanner/config.py"
click node_records "https://github.com/pratheep-bit/frapast/blob/main/scanner/shared/records.py"
click node_schema_index "https://github.com/pratheep-bit/frapast/blob/main/scanner/schema/engine.py"
click node_hooks_index "https://github.com/pratheep-bit/frapast/blob/main/scanner/hooks/engine.py"
click node_python_index "https://github.com/pratheep-bit/frapast/blob/main/scanner/python/engine.py"
click node_callgraph "https://github.com/pratheep-bit/frapast/blob/main/scanner/callgraph/builder.py"
click node_rules "https://github.com/pratheep-bit/frapast/blob/main/scanner/rules/engine.py"
click node_severity "https://github.com/pratheep-bit/frapast/blob/main/scanner/severity/engine.py"
click node_taxonomy "https://github.com/pratheep-bit/frapast/blob/main/scanner/taxonomy/taxonomy_registry.yaml"
click node_fp "https://github.com/pratheep-bit/frapast/blob/main/scanner/fp/engine.py"
click node_ledger "https://github.com/pratheep-bit/frapast/blob/main/scanner/ledger_io.py"
click node_proof "https://github.com/pratheep-bit/frapast/blob/main/scanner/proof/orchestrator.py"
click node_reporting "https://github.com/pratheep-bit/frapast/blob/main/scanner/reporting/engine.py"
click node_dashboard "https://github.com/pratheep-bit/frapast/blob/main/scanner/web/server.py"
click node_ci "https://github.com/pratheep-bit/frapast/blob/main/action.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_cli,node_config,node_records toneBlue
class node_schema_index,node_hooks_index,node_python_index,node_indexes toneAmber
class node_callgraph,node_rules,node_severity,node_taxonomy,node_fp,node_ledger toneMint
class node_proof,node_reporting,node_dashboard,node_ci toneRose
class node_target,node_bench,node_browser toneNeutral
```

## Components

### Entry & Control

- [CLI launcher](https://github.com/pratheep-bit/frapast/blob/main/scanner/cli.py): Python CLI · `scanner/cli.py`
- [Scan configuration](https://github.com/pratheep-bit/frapast/blob/main/scanner/config.py): configuration · `scanner/config.py`
- [Shared records](https://github.com/pratheep-bit/frapast/blob/main/scanner/shared/records.py): data models · Normalized index and finding record shapes. · `scanner/shared/records.py`

### Static Indexing

- [DocType indexer](https://github.com/pratheep-bit/frapast/blob/main/scanner/schema/engine.py): schema analysis · `scanner/schema/engine.py`
- [Hooks indexer](https://github.com/pratheep-bit/frapast/blob/main/scanner/hooks/engine.py): hooks analysis · `scanner/hooks/engine.py`
- [Python AST indexer](https://github.com/pratheep-bit/frapast/blob/main/scanner/python/engine.py): AST analysis · Discovers symbols, endpoints, calls, imports, and source constructs. · `scanner/python/engine.py`
- **Normalized indexes**: analysis data

### Detection & Enrichment

- [Frappe call graph](https://github.com/pratheep-bit/frapast/blob/main/scanner/callgraph/builder.py): reachability analysis · Adds direct calls, RPC, hook, and document-method dispatch. · `scanner/callgraph/builder.py`
- [Rule engine](https://github.com/pratheep-bit/frapast/blob/main/scanner/rules/engine.py): detector evaluation · YAML-defined security detectors produce deduplicated candidates. · `scanner/rules/engine.py`
- [Severity scoring](https://github.com/pratheep-bit/frapast/blob/main/scanner/severity/engine.py): risk classification · Combines privilege, impact, blast radius, and proof tier. · `scanner/severity/engine.py`
- [Security taxonomy](https://github.com/pratheep-bit/frapast/blob/main/scanner/taxonomy/taxonomy_registry.yaml): classification data · `scanner/taxonomy/taxonomy_registry.yaml`
- [False-positive handling](https://github.com/pratheep-bit/frapast/blob/main/scanner/fp/engine.py): finding categorization · `scanner/fp/engine.py`
- [Findings ledger](https://github.com/pratheep-bit/frapast/blob/main/scanner/ledger_io.py): persistent tracking · Persists tracked findings with schema and integrity validation. · `scanner/ledger_io.py`

### Proof, Reporting & UI

- [Proof orchestrator](https://github.com/pratheep-bit/frapast/blob/main/scanner/proof/orchestrator.py): runtime verification · Retains static evidence while marking proof outcomes. · `scanner/proof/orchestrator.py`
- [Report exports](https://github.com/pratheep-bit/frapast/blob/main/scanner/reporting/engine.py): output rendering · Terminal, JSON, YAML, SARIF, and Markdown outputs. · `scanner/reporting/engine.py`
- [Local dashboard](https://github.com/pratheep-bit/frapast/blob/main/scanner/web/server.py): loopback HTTP UI · Local scan, proof, export, and progress interface. · `scanner/web/server.py`
- [GitHub Actions](https://github.com/pratheep-bit/frapast/blob/main/action.yml): CI integration · `action.yml`

### Other components

- **Frappe app source**: target filesystem · Arbitrary application source and framework conventions.
- **Frappe bench**: external HTTP/RPC service · Configured local or remote verification target.
- **Local browser**: loopback client

## Connections

- CLI launcher → Scan configuration: loads
- CLI launcher → Frappe app source: scans
- CLI launcher → DocType indexer: orchestrates
- CLI launcher → Hooks indexer: orchestrates
- CLI launcher → Python AST indexer: orchestrates
- Frappe app source → DocType indexer: DocType JSON
- Frappe app source → Hooks indexer: hooks.py
- Frappe app source → Python AST indexer: Python modules
- DocType indexer → Normalized indexes: schema metadata
- Hooks indexer → Normalized indexes: event declarations
- Python AST indexer → Normalized indexes: AST symbols
- Normalized indexes → Frappe call graph: indexed constructs
- Frappe call graph → Rule engine: reachability context
- Normalized indexes → Rule engine: source metadata
- Rule engine → Severity scoring: candidate findings
- Security taxonomy → Severity scoring: classification mapping
- Severity scoring → False-positive handling: scored findings
- False-positive handling → Findings ledger: tracked findings
- False-positive handling → Proof orchestrator: static candidates
- Proof orchestrator → Frappe bench: Tier 2 HTTP/RPC
- Proof orchestrator → Findings ledger: proof outcomes
- Findings ledger → Report exports: findings
- CLI launcher → Report exports: selects output
- Local dashboard → CLI launcher: starts scans
- Local dashboard → Proof orchestrator: runs proof
- Local dashboard → Report exports: exports
- Local browser → Local dashboard: loopback access
- GitHub Actions → CLI launcher: runs scanner
