# 0xsteph/pentest-ai architecture

> Architecture diagram of the GitHub repository 0xsteph/pentest-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xsteph/pentest-ai
- Repository: https://github.com/0xsteph/pentest-ai

## Overview

#### Purpose and entry points
`pentest-ai` (`ptai`) is a Python 3.10+ local-first, AI-coordinated penetration-testing system. Its central contract is that candidate findings must be reproducible by deterministic machine oracles before being reported as verified. Primary entry points are the standalone CLI in `cli/main.py`, REST/dashboard server in `api/server.py`, and MCP server in `mcp_server/server.py`. Packaging, console command, and runtime dependencies are defined in `pyproject.toml`.

#### Engagement orchestration and safety boundary
An engagement begins with target/scope confirmation, consent, execution context, rate/scope controls, and orchestration. The orchestrator sequences specialist phases and persists engagement state; target expansion and tool/probe activity must pass scope enforcement. Human-in-the-loop pause/takeover and compliance behavior are engine-level concerns.
- `engine/orchestrator.py`
- `engine/scope.py`
- `engine/exec_context.py`
- `engine/aup_consent.py`

#### Specialist-agent phase layer
Specialist agents encapsulate recon, authenticated web/API/browser testing, AD/cloud/credential/privesc work, vulnerability aggregation, chaining, validation, detection, and reporting. They share the base-agent contract and are selected/ordered by orchestration rather than being independent applications. The web path is architecturally central because it combines crawling, authentication, scanners, and curated probes.
- `agents/base.py`
- `agents/web/web_agent.py`
- `agents/recon/recon_agent.py`
- `agents/poc_validator/poc_agent.py`

#### Deterministic detection and proof pipeline
The probe registry exposes curated test implementations; probes receive scoped context, use reusable HTTP/payload primitives, and emit candidate observations/evidence. Candidate findings are normalized, deduplicated, triaged, and passed to a verifier/oracle gate. Verification—not scanner or LLM output—is the boundary that promotes a result to a reportable finding. Out-of-band classes use the OOB subsystem for callback-based evidence.
- `engine/probes/registry.py`
- `engine/probes/context.py`
- `engine/verifier.py`
- `engine/oracles.py`
- `engine/oob/client.py`

#### State, evidence, and portable outputs
The findings database is the system-of-record boundary between execution phases: it stores findings, evidence artifacts, verdict visibility, and lifecycle state. Verified findings can become replayable capsules and attack chains, then flow to report/export formats including SARIF and JUnit. This separates raw tool/probe observations from durable, consumable security results.
- `engine/findings_db.py`
- `engine/evidence.py`
- `engine/capsule.py`
- `engine/chain_capsule.py`
- `engine/exporters/contract.py`

#### LLM and external integration boundary
LLMs coordinate agent loops and reason over results but are not authoritative detectors. The LLM factory supports Anthropic, OpenAI-compatible endpoints, LiteLLM, and local Ollama, with cost tracking for standalone runs. MCP exposes tools/probes/engagement APIs to external AI clients; REST/WebSocket serves dashboards and integrations. External security binaries are discovered/installed and invoked through the tool registry; scanner output still enters the verification pipeline.
- `engine/agent_loop.py`
- `engine/llm/factory.py`
- `mcp_server/security_tools.py`
- `tools/registry.py`
- `api/server.py`

#### Authentication, infrastructure, and deployment
Authenticated scanning maintains reusable sessions and resolves credential references from environment variables, 1Password, Vault, or AWS Secrets Manager rather than embedding secret values. Default execution is local with local persistence; optional cloud workspace authentication/sync is exposed through CLI auth. OAST defaults to an external collaborator but can use a local server/self-hosted endpoint. Docker supports containerized operation, while GitHub Action and CI mode support pipeline gating.
- `engine/authenticated_scan.py`
- `engine/auth_session.py`
- `cli/credential_resolvers/aws_sm.py`
- `engine/oob/local_server.py`
- `Dockerfile`

Main entry points: [`engine/findings_db.py`](https://github.com/0xsteph/pentest-ai/blob/main/engine/findings_db.py) (Findings Database), [`engine/orchestrator.py`](https://github.com/0xsteph/pentest-ai/blob/main/engine/orchestrator.py) (Orchestrator), [`engine/probes/registry.py`](https://github.com/0xsteph/pentest-ai/blob/main/engine/probes/registry.py) (Probe Registry), [`engine/probes/context.py`](https://github.com/0xsteph/pentest-ai/blob/main/engine/probes/context.py) (Scoped Probe Context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_cli["CLI<br/>command interface<br/>[main.py]"]
  node_api["REST Dashboard<br/>API server<br/>[server.py]"]
  node_mcp["MCP Server<br/>MCP interface<br/>[server.py]"]
end

subgraph group_control["Engagement Control"]
  node_orchestrator{{"Orchestrator<br/>engagement engine<br/>[orchestrator.py]"}}
  node_scope{{"Scope &amp; Consent<br/>safety boundary<br/>[scope.py]"}}
  node_agent_loop["Agent Loop<br/>AI coordinator<br/>[agent_loop.py]"]
  node_llm_factory["LLM Factory<br/>model provider adapter<br/>[factory.py]"]
end

subgraph group_agents["Specialist Agents"]
  node_base_agents["Specialist Agents<br/>agent layer<br/>[base.py]"]
  node_web_agent["Web Testing Agent<br/>web specialist<br/>[web_agent.py]"]
  node_recon_agent["Recon Agent<br/>recon specialist<br/>[recon_agent.py]"]
  node_auth_scan["Authenticated Scanning<br/>session manager"]
end

subgraph group_proof["Detection &amp; Proof"]
  node_probe_registry["Probe Registry<br/>curated probes<br/>[registry.py]"]
  node_probe_context["Scoped Probe Context<br/>execution context<br/>[context.py]"]
  node_oob["OOB Evidence<br/>callback subsystem<br/>[client.py]"]
  node_verifier{{"Verifier<br/>proof gate<br/>[verifier.py]"}}
  node_oracles["Machine Oracles<br/>deterministic checks<br/>[oracles.py]"]
end

subgraph group_state["Results &amp; Integrations"]
  node_findings_db[("Findings Database<br/>system of record<br/>[findings_db.py]")]
  node_capsules["Replay &amp; Chain Capsules<br/>portable proof<br/>[capsule.py]"]
  node_exporters["Report Exporters<br/>output contract<br/>[contract.py]"]
  node_tool_registry["Tool Registry<br/>external tool adapter<br/>[registry.py]"]
end

node_cli -->|"starts engagement"| node_orchestrator
node_api -->|"controls"| node_orchestrator
node_mcp -->|"engagement API"| node_orchestrator
node_mcp -->|"probe tools"| node_probe_registry
node_orchestrator -->|"enforces before activity"| node_scope
node_orchestrator -->|"coordinates"| node_agent_loop
node_agent_loop -->|"uses models"| node_llm_factory
node_orchestrator -->|"selects phases"| node_base_agents
node_base_agents -->|"specializes"| node_recon_agent
node_base_agents -->|"specializes"| node_web_agent
node_web_agent -->|"reuses sessions"| node_auth_scan
node_web_agent -->|"runs probes"| node_probe_registry
node_recon_agent -->|"expands scoped targets"| node_probe_context
node_scope -->|"constrains"| node_probe_context
node_probe_registry -->|"executes with"| node_probe_context
node_probe_registry -->|"invokes binaries"| node_tool_registry
node_probe_registry -->|"requests callbacks"| node_oob
node_probe_context -->|"candidate observations"| node_findings_db
node_oob -->|"callback evidence"| node_findings_db
node_findings_db -->|"candidates and evidence"| node_verifier
node_verifier -->|"evaluates via"| node_oracles
node_verifier -->|"persists verdict"| node_findings_db
node_findings_db -->|"verified findings"| node_capsules
node_findings_db -->|"verified results"| node_exporters
node_api -->|"dashboard visibility"| node_findings_db

click node_cli "https://github.com/0xsteph/pentest-ai/blob/main/cli/main.py"
click node_api "https://github.com/0xsteph/pentest-ai/blob/main/api/server.py"
click node_mcp "https://github.com/0xsteph/pentest-ai/blob/main/mcp_server/server.py"
click node_orchestrator "https://github.com/0xsteph/pentest-ai/blob/main/engine/orchestrator.py"
click node_scope "https://github.com/0xsteph/pentest-ai/blob/main/engine/scope.py"
click node_agent_loop "https://github.com/0xsteph/pentest-ai/blob/main/engine/agent_loop.py"
click node_llm_factory "https://github.com/0xsteph/pentest-ai/blob/main/engine/llm/factory.py"
click node_base_agents "https://github.com/0xsteph/pentest-ai/blob/main/agents/base.py"
click node_web_agent "https://github.com/0xsteph/pentest-ai/blob/main/agents/web/web_agent.py"
click node_recon_agent "https://github.com/0xsteph/pentest-ai/blob/main/agents/recon/recon_agent.py"
click node_probe_registry "https://github.com/0xsteph/pentest-ai/blob/main/engine/probes/registry.py"
click node_probe_context "https://github.com/0xsteph/pentest-ai/blob/main/engine/probes/context.py"
click node_oob "https://github.com/0xsteph/pentest-ai/blob/main/engine/oob/client.py"
click node_verifier "https://github.com/0xsteph/pentest-ai/blob/main/engine/verifier.py"
click node_oracles "https://github.com/0xsteph/pentest-ai/blob/main/engine/oracles.py"
click node_findings_db "https://github.com/0xsteph/pentest-ai/blob/main/engine/findings_db.py"
click node_capsules "https://github.com/0xsteph/pentest-ai/blob/main/engine/capsule.py"
click node_exporters "https://github.com/0xsteph/pentest-ai/blob/main/engine/exporters/contract.py"
click node_tool_registry "https://github.com/0xsteph/pentest-ai/blob/main/tools/registry.py"
click node_auth_scan "https://github.com/0xsteph/pentest-ai/blob/main/engine/authenticated_scan.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_cli,node_api,node_mcp toneBlue
class node_orchestrator,node_scope,node_agent_loop,node_llm_factory toneAmber
class node_base_agents,node_web_agent,node_recon_agent,node_auth_scan toneMint
class node_probe_registry,node_probe_context,node_oob,node_verifier,node_oracles toneRose
class node_findings_db,node_capsules,node_exporters,node_tool_registry toneIndigo
```

## Components

### Entry Points

- [CLI](https://github.com/0xsteph/pentest-ai/blob/main/cli/main.py): command interface · Standalone engagement and authentication command surface. · `cli/main.py`
- [REST Dashboard](https://github.com/0xsteph/pentest-ai/blob/main/api/server.py): API server · REST and WebSocket interface for dashboards and integrations. · `api/server.py`
- [MCP Server](https://github.com/0xsteph/pentest-ai/blob/main/mcp_server/server.py): MCP interface · Exposes engagement, tool, and probe APIs to AI clients. · `mcp_server/server.py`

### Engagement Control

- [Orchestrator](https://github.com/0xsteph/pentest-ai/blob/main/engine/orchestrator.py): engagement engine · Sequences phases and persists engagement execution state. · `engine/orchestrator.py`
- [Scope & Consent](https://github.com/0xsteph/pentest-ai/blob/main/engine/scope.py): safety boundary · Enforces target, consent, rate, and execution constraints. · `engine/scope.py`
- [Agent Loop](https://github.com/0xsteph/pentest-ai/blob/main/engine/agent_loop.py): AI coordinator · Runs LLM-guided specialist-agent loops without authorizing findings. · `engine/agent_loop.py`
- [LLM Factory](https://github.com/0xsteph/pentest-ai/blob/main/engine/llm/factory.py): model provider adapter · Selects local and hosted LLM providers. · `engine/llm/factory.py`

### Specialist Agents

- [Specialist Agents](https://github.com/0xsteph/pentest-ai/blob/main/agents/base.py): agent layer · Shared contract for recon, web, validation, and other phases. · `agents/base.py`
- [Web Testing Agent](https://github.com/0xsteph/pentest-ai/blob/main/agents/web/web_agent.py): web specialist · Combines crawling, authentication, scanners, and curated web probes. · `agents/web/web_agent.py`
- [Recon Agent](https://github.com/0xsteph/pentest-ai/blob/main/agents/recon/recon_agent.py): recon specialist · `agents/recon/recon_agent.py`
- [Authenticated Scanning](https://github.com/0xsteph/pentest-ai/blob/main/engine/authenticated_scan.py): session manager · Maintains reusable authenticated sessions and credential references. · `engine/authenticated_scan.py`

### Detection & Proof

- [Probe Registry](https://github.com/0xsteph/pentest-ai/blob/main/engine/probes/registry.py): curated probes · Selects deterministic tests for scoped execution. · `engine/probes/registry.py`
- [Scoped Probe Context](https://github.com/0xsteph/pentest-ai/blob/main/engine/probes/context.py): execution context · Supplies probes with controlled target and runtime context. · `engine/probes/context.py`
- [OOB Evidence](https://github.com/0xsteph/pentest-ai/blob/main/engine/oob/client.py): callback subsystem · Collects callback evidence for out-of-band vulnerability classes. · `engine/oob/client.py`
- [Verifier](https://github.com/0xsteph/pentest-ai/blob/main/engine/verifier.py): proof gate · Promotes candidates only when deterministic oracle checks succeed. · `engine/verifier.py`
- [Machine Oracles](https://github.com/0xsteph/pentest-ai/blob/main/engine/oracles.py): deterministic checks · Reproducible authority for verified findings. · `engine/oracles.py`

### Results & Integrations

- [Findings Database](https://github.com/0xsteph/pentest-ai/blob/main/engine/findings_db.py): system of record · Stores findings, evidence, verdicts, and lifecycle state. · `engine/findings_db.py`
- [Replay & Chain Capsules](https://github.com/0xsteph/pentest-ai/blob/main/engine/capsule.py): portable proof · Packages verified findings and attack chains for replay. · `engine/capsule.py`
- [Report Exporters](https://github.com/0xsteph/pentest-ai/blob/main/engine/exporters/contract.py): output contract · Produces consumable outputs including SARIF and JUnit. · `engine/exporters/contract.py`
- [Tool Registry](https://github.com/0xsteph/pentest-ai/blob/main/tools/registry.py): external tool adapter · Discovers and invokes security binaries. · `tools/registry.py`

## Connections

- CLI → Orchestrator: starts engagement
- REST Dashboard → Orchestrator: controls
- MCP Server → Orchestrator: engagement API
- MCP Server → Probe Registry: probe tools
- Orchestrator → Scope & Consent: enforces before activity
- Orchestrator → Agent Loop: coordinates
- Agent Loop → LLM Factory: uses models
- Orchestrator → Specialist Agents: selects phases
- Specialist Agents → Recon Agent: specializes
- Specialist Agents → Web Testing Agent: specializes
- Web Testing Agent → Authenticated Scanning: reuses sessions
- Web Testing Agent → Probe Registry: runs probes
- Recon Agent → Scoped Probe Context: expands scoped targets
- Scope & Consent → Scoped Probe Context: constrains
- Probe Registry → Scoped Probe Context: executes with
- Probe Registry → Tool Registry: invokes binaries
- Probe Registry → OOB Evidence: requests callbacks
- Scoped Probe Context → Findings Database: candidate observations
- OOB Evidence → Findings Database: callback evidence
- Findings Database → Verifier: candidates and evidence
- Verifier → Machine Oracles: evaluates via
- Verifier → Findings Database: persists verdict
- Findings Database → Replay & Chain Capsules: verified findings
- Findings Database → Report Exporters: verified results
- REST Dashboard → Findings Database: dashboard visibility
