# hadriansecurity/openhack architecture

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

- Interactive diagram: https://gitdiagram.com/hadriansecurity/openhack
- Repository: https://github.com/hadriansecurity/openhack

## Overview

1. **What this repository is**
   - `openhack` is a Python 3.9+ command-line tool and workflow framework for source-guided security review.
   - It is not a service; the “system” is a file-based workspace under `runs/<target>/<run-id>/` plus agent prompt files and schemas that drive a human-approved, checkpointed review loop.

2. **Top-level architecture**
   - The repository is split into four main planes:
     - `src/openhack/`: core runtime, CLI, validators, and run-state logic.
     - `agents/`: Markdown agent definitions for reconnaissance, scenario routing, and expert review.
     - `templates/` and `config/`: prompt/result templates and JSON schema contracts.
     - `runs/`: generated per-run artifacts and audit state, gitignored and treated as durable workflow storage.

3. **Execution model**
   - The CLI is the primary entry point (`src/openhack/cli.py`, `__main__.py`).
   - Each command advances one checkpoint in a run: initialize, recon, scenario routing, scenario execution, finding triage, summarize, validate.
   - The harness or operator supplies the model execution environment; `openhack` supplies the durable workflow state, prompt generation, validation, and artifact materialization.

4. **Run workspace as the core boundary**
   - Every run is isolated under `runs/<target>/<run-id>/`.
   - The workspace contains the cloned target source, recon outputs, scenario backlog, finished scenario results, finding candidates, triage decisions, final findings, and logs.
   - This boundary is important: all later phases derive from files in that run directory rather than from in-memory model context.

5. **Workflow data flow**
   - The pipeline is intentionally narrow:
     - recon items → routing units → scenarios → scenario results → finding candidates → triage decisions → findings.
   - Recon discovers surfaces; routing clusters them into reviewable units; the scenario router turns those units into scoped work items; expert agents verify or reject them; triage independently decides which verified candidates become final findings.

6. **Core runtime modules**
   - `src/openhack/run.py`, `paths.py`, `models.py`, `schemas.py`, and `results.py` define run metadata, path handling, typed records, and schema-backed artifacts.
   - `backlog.py`, `scenarios.py`, `triage.py`, `queue.py`, and `summary.py` implement the lifecycle around scenario backlogs, candidate queues, triage queues, and resume summaries.
   - `validate.py` and `coverage.py` enforce integrity, prompt hashes, coverage expectations, and consistency across generated artifacts.

7. **Reconnaissance subsystem**
   - `src/openhack/recon.py`, `inventory.py`, `inventory_patterns.py`, `request_boundaries.py`, `router_context.py`, and `routing_units.py` support source reconnaissance and surface normalization.
   - Recon writes compact artifacts such as recon items, routes, inputs, sinks, exposures, request boundaries, coverage gaps, and routing units.
   - `src/openhack/semgrep_recon.py` optionally enriches recon with bundled Semgrep rules from `config/semgrep/openhack-recon.yml`; these hits are treated as hints, not findings.

8. **Agent registry and orchestration**
   - `agents/orchestration/` defines the workflow roles: run orchestration, scenario routing, and finding triage.
   - `agents/reconnaissance/` contains source-recon guidance for discovering review surfaces.
   - `agents/experts/` contains 12 OWASP/MITRE-aligned expert families, each represented as a compact Markdown manifest that states ownership, signals, false positives, and handoff guidance.
   - `src/openhack/registry.py` and `expert_scope.py` bind these manifests into a selectable expert scope for a run.

9. **Prompting and artifact templates**
   - `templates/` holds the prompt and result shapes for scenario routing, scenario review, finding triage, and findings.
   - These templates keep agent I/O stable and machine-checkable.
   - `config/*.json` provides schema contracts for scenario results, finding candidates, triage decisions, and scenario/router outputs, making the file-based workflow validateable across phases.

10. **Logging, auditability, and resume**
   - `src/openhack/log.py` and `scripts/commands/log-event.py` support append-only event tracing.
   - Each command emits structured records into run logs and trace files so the run can be audited and resumed deterministically.
   - `summarize-run` derives the next checkpoint from the filesystem state, which is the key recovery boundary after interruption.

11. **Scripts vs. library**
   - `scripts/commands/` contains thin command implementations for operational tasks like initializing runs, rendering prompts, recording results, and validating runs.
   - The reusable logic lives in `src/openhack/`, while the scripts act as CLI-facing adapters over that library.
   - This separation matters for architecture: the command layer is orchestration, not business logic.

12. **Operational and packaging boundaries**
   - The project is distributed as an editable, workspace-first Python package via `pyproject.toml` and `setup.py`.
   - The repository root itself is part of the runtime contract because `agents/`, `config/`, `templates/`, and `runs/` are read as workspace data.
   - `OPENHACK_ROOT` exists to relocate that workspace boundary when the CLI is invoked externally.

13. **Validation and CI**
   - `validate-run` is the central integrity gate for schemas, prompt hashes, coverage, and materialization consistency.
   - `.github/workflows/ci.yml` provides repository-level automation, but the system’s main correctness model is local run validation rather than a long-running backend service.

14. **What an architecture diagram should emphasize**
   - The key diagram should show a stateful, file-backed pipeline with human approval gates between phases.
   - The important boundaries are: target source checkout, recon normalization, router backlog generation, per-scenario expert review, independent triage, and final finding materialization.
   - The major external dependency is the source repository under review; the rest of the system is local Python tooling plus optional Semgrep enrichment and the surrounding model harness.

Main entry points: [`runs`](https://github.com/hadriansecurity/openhack/tree/main/runs) (Run workspace), [`src/openhack/backlog.py`](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/backlog.py) (Workflow core), [`src/openhack/recon.py`](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/recon.py) (Recon engine), [`src/openhack/cli.py`](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/cli.py) (CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["Core runtime"]
  node_node_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_node_main["Module main<br/>entrypoint<br/>[__main__.py]"]
  node_node_runstate["Run state<br/>state model<br/>[run.py]"]
  node_node_workflow["Workflow core<br/>lifecycle<br/>[backlog.py]"]
  node_node_recon["Recon engine<br/>recon pipeline<br/>[recon.py]"]
  node_node_inventory["Inventory<br/>surface discovery<br/>[inventory.py]"]
  node_node_routing["Routing units<br/>surface clustering<br/>[routing_units.py]"]
  node_node_validation["Validation<br/>integrity checks<br/>[validate.py]"]
  node_node_registry["Expert registry<br/>scope binding<br/>[registry.py]"]
  node_node_semgrep["Semgrep hints<br/>optional enrichment<br/>[semgrep_recon.py]"]
end

subgraph group_group_agents["Agents"]
  node_node_orchestrator["Orchestrator<br/>agent role<br/>[orchestrator.md]"]
  node_node_router_agent["Scenario router<br/>agent role<br/>[scenario-router.md]"]
  node_node_triage_agent["Finding triage<br/>agent role<br/>[finding-triage.md]"]
  node_node_recon_agent["Recon guide<br/>agent role<br/>[source-recon.md]"]
  node_node_experts["Expert families<br/>expert manifests"]
end

subgraph group_group_contracts["Contracts"]
  node_node_scenario_prompt["Scenario prompt<br/>template<br/>[scenario-prompt.md]"]
  node_node_triage_prompt["Triage prompt<br/>template"]
  node_node_schemas["JSON schemas<br/>contracts"]
end

subgraph group_group_workspace["Run workspace"]
  node_node_workspace[("Run workspace<br/>durable storage")]
  node_node_scenario_results["Scenario results<br/>artifact stage"]
  node_node_triage_decisions["Triage decisions<br/>artifact stage"]
  node_node_findings["Findings<br/>final artifacts"]
end

subgraph group_group_targets["External target"]
  node_node_target_repo["Target source<br/>external repo"]
end

node_node_main -->|"launches"| node_node_cli
node_node_cli -->|"loads"| node_node_runstate
node_node_cli -->|"advances"| node_node_workflow
node_node_workflow -->|"starts"| node_node_recon
node_node_recon -->|"discovers"| node_node_inventory
node_node_recon -->|"normalizes"| node_node_routing
node_node_recon -.->|"enriches"| node_node_semgrep
node_node_routing -->|"guided by"| node_node_router_agent
node_node_router_agent -->|"uses"| node_node_scenario_prompt
node_node_registry -->|"selects"| node_node_experts
node_node_workflow -->|"scopes"| node_node_registry
node_node_workflow -->|"writes"| node_node_scenario_results
node_node_scenario_results -->|"feeds"| node_node_triage_decisions
node_node_triage_agent -->|"uses"| node_node_triage_prompt
node_node_triage_decisions -->|"promotes"| node_node_findings
node_node_schemas -->|"checked by"| node_node_validation
node_node_workspace -->|"contains"| node_node_target_repo
node_node_workspace -->|"stores"| node_node_scenario_results
node_node_workspace -->|"stores"| node_node_triage_decisions
node_node_workspace -->|"stores"| node_node_findings
node_node_validation -->|"verifies"| node_node_workspace
node_node_recon_agent -->|"guides"| node_node_recon
node_node_orchestrator -->|"coordinates"| node_node_workflow

click node_node_cli "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/cli.py"
click node_node_main "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/__main__.py"
click node_node_runstate "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/run.py"
click node_node_workflow "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/backlog.py"
click node_node_recon "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/recon.py"
click node_node_inventory "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/inventory.py"
click node_node_routing "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/routing_units.py"
click node_node_validation "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/validate.py"
click node_node_registry "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/registry.py"
click node_node_semgrep "https://github.com/hadriansecurity/openhack/blob/main/src/openhack/semgrep_recon.py"
click node_node_orchestrator "https://github.com/hadriansecurity/openhack/blob/main/agents/orchestration/orchestrator.md"
click node_node_router_agent "https://github.com/hadriansecurity/openhack/blob/main/agents/orchestration/scenario-router.md"
click node_node_triage_agent "https://github.com/hadriansecurity/openhack/blob/main/agents/orchestration/finding-triage.md"
click node_node_recon_agent "https://github.com/hadriansecurity/openhack/blob/main/agents/reconnaissance/source-recon.md"
click node_node_experts "https://github.com/hadriansecurity/openhack/tree/main/agents/experts"
click node_node_scenario_prompt "https://github.com/hadriansecurity/openhack/blob/main/templates/scenario-prompt.md"
click node_node_triage_prompt "https://github.com/hadriansecurity/openhack/blob/main/templates/finding-triage-prompt.md"
click node_node_schemas "https://github.com/hadriansecurity/openhack/blob/main/config/scenario-schema.json"
click node_node_workspace "https://github.com/hadriansecurity/openhack/tree/main/runs"
click node_node_scenario_results "https://github.com/hadriansecurity/openhack/tree/main/runs"
click node_node_triage_decisions "https://github.com/hadriansecurity/openhack/tree/main/runs"
click node_node_findings "https://github.com/hadriansecurity/openhack/tree/main/runs"

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_node_cli,node_node_main,node_node_runstate,node_node_workflow,node_node_recon,node_node_inventory,node_node_routing,node_node_validation,node_node_registry,node_node_semgrep toneBlue
class node_node_orchestrator,node_node_router_agent,node_node_triage_agent,node_node_recon_agent,node_node_experts toneAmber
class node_node_scenario_prompt,node_node_triage_prompt,node_node_schemas toneMint
class node_node_workspace,node_node_scenario_results,node_node_triage_decisions,node_node_findings toneRose
class node_node_target_repo toneIndigo
```

## Components

### Core runtime

Python CLI, run state, and validation logic.

- [CLI](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/cli.py): entrypoint · Primary command entrypoint and command dispatch. · `src/openhack/cli.py`
- [Module main](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/__main__.py): entrypoint · Package execution entrypoint. · `src/openhack/__main__.py`
- [Run state](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/run.py): state model · Run metadata, paths, typed records, and artifact models. · `src/openhack/run.py`
- [Workflow core](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/backlog.py): lifecycle · Backlog, scenarios, triage, queueing, and resume summary. · `src/openhack/backlog.py`
- [Recon engine](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/recon.py): recon pipeline · Source reconnaissance, normalization, and routing unit generation. · `src/openhack/recon.py`
- [Inventory](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/inventory.py): surface discovery · Source inventory and pattern extraction. · `src/openhack/inventory.py`
- [Routing units](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/routing_units.py): surface clustering · Normalizes recon outputs into reviewable routing units. · `src/openhack/routing_units.py`
- [Validation](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/validate.py): integrity checks · Schema, prompt hash, coverage, and materialization validation. · `src/openhack/validate.py`
- [Expert registry](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/registry.py): scope binding · Binds agent manifests into selectable expert scope. · `src/openhack/registry.py`
- [Semgrep hints](https://github.com/hadriansecurity/openhack/blob/main/src/openhack/semgrep_recon.py): optional enrichment · Optional recon enrichment from bundled Semgrep rules. · `src/openhack/semgrep_recon.py`

### Agents

Markdown agent roles used by the workflow.

- [Orchestrator](https://github.com/hadriansecurity/openhack/blob/main/agents/orchestration/orchestrator.md): agent role · Run orchestration manifest. · `agents/orchestration/orchestrator.md`
- [Scenario router](https://github.com/hadriansecurity/openhack/blob/main/agents/orchestration/scenario-router.md): agent role · Manifest for routing recon units into scenarios. · `agents/orchestration/scenario-router.md`
- [Finding triage](https://github.com/hadriansecurity/openhack/blob/main/agents/orchestration/finding-triage.md): agent role · Manifest for deciding which verified candidates become findings. · `agents/orchestration/finding-triage.md`
- [Recon guide](https://github.com/hadriansecurity/openhack/blob/main/agents/reconnaissance/source-recon.md): agent role · Source reconnaissance guidance. · `agents/reconnaissance/source-recon.md`
- [Expert families](https://github.com/hadriansecurity/openhack/tree/main/agents/experts): expert manifests · OWASP/MITRE-aligned expert manifests for scenario review. · `agents/experts`

### Contracts

Prompt templates and JSON schemas that stabilize file-based I/O.

- [Scenario prompt](https://github.com/hadriansecurity/openhack/blob/main/templates/scenario-prompt.md): template · Prompt contract for routing and scenario review. · `templates/scenario-prompt.md`
- [Triage prompt](https://github.com/hadriansecurity/openhack/blob/main/templates/finding-triage-prompt.md): template · Prompt contract for finding triage. · `templates/finding-triage-prompt.md`
- [JSON schemas](https://github.com/hadriansecurity/openhack/blob/main/config/scenario-schema.json): contracts · Machine-checkable schemas for scenarios, results, candidates, triage, and findings. · `config/scenario-schema.json`

### Run workspace

Per-run durable artifacts under runs/<target>/<run-id>/.

- [Run workspace](https://github.com/hadriansecurity/openhack/tree/main/runs): durable storage · Per-run isolated filesystem state under runs/<target>/<run-id>/. · `runs`
- [Scenario results](https://github.com/hadriansecurity/openhack/tree/main/runs): artifact stage · Finished scenario outputs and review evidence. · `runs`
- [Triage decisions](https://github.com/hadriansecurity/openhack/tree/main/runs): artifact stage · Independent accept/reject decisions for verified candidates. · `runs`
- [Findings](https://github.com/hadriansecurity/openhack/tree/main/runs): final artifacts · Materialized final findings and audit state. · `runs`

### External target

Source repository under review and optional recon enrichment.

- **Target source**: external repo · Source repository under review, cloned into the run workspace.

## Connections

- Module main → CLI: launches · Package entrypoint invokes the CLI.
- CLI → Run state: loads · Commands resolve run metadata and paths.
- CLI → Workflow core: advances · Each command advances one checkpoint in the workflow.
- Workflow core → Recon engine: starts · Initial checkpoint prepares reconnaissance artifacts.
- Recon engine → Inventory: discovers · Recon discovers source surfaces and patterns.
- Recon engine → Routing units: normalizes · Recon output is compacted into routing units.
- Recon engine → Semgrep hints: enriches · Optional Semgrep hits add hints to recon.
- Routing units → Scenario router: guided by · Scenario routing uses the routing agent manifest.
- Scenario router → Scenario prompt: uses · Routing and review prompts define the scenario I/O shape.
- Expert registry → Expert families: selects · Registry binds expert manifests into a run scope.
- Workflow core → Expert registry: scopes · Workflow determines which experts are available.
- Workflow core → Scenario results: writes · Scenario execution materializes results in the workspace.
- Scenario results → Triage decisions: feeds · Verified scenario outputs become candidate inputs for triage.
- Finding triage → Triage prompt: uses · Triage is driven by a dedicated prompt contract.
- Triage decisions → Findings: promotes · Accepted decisions become final findings.
- JSON schemas → Validation: checked by · Validation enforces schema and artifact consistency.
- Run workspace → Target source: contains · Run workspace holds the cloned target source.
- Run workspace → Scenario results: stores · Workspace persists intermediate scenario artifacts.
- Run workspace → Triage decisions: stores · Workspace persists triage state.
- Run workspace → Findings: stores · Workspace persists final findings and audit state.
- Validation → Run workspace: verifies · Validation checks the filesystem-backed run state.
- Recon guide → Recon engine: guides · Recon guidance shapes surface discovery.
- Orchestrator → Workflow core: coordinates · Orchestration manifest maps the workflow roles.
