# kalilakshman/ai-security-agent- architecture

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

- Interactive diagram: https://gitdiagram.com/kalilakshman/ai-security-agent-
- Repository: https://github.com/kalilakshman/ai-security-agent-

## Overview

#### Purpose and Entry Points
`security-ai` is a Python 3.12 CLI orchestrator for authorized security assessments. It converts a target and profile into a policy-governed tool workflow, preserves evidence, analyzes results, and emits reports. The primary command surface and optional interactive dashboard are in `app/cli.py`, `app/main.py`, and `app/ui.py`.

#### Orchestration and Workflow Planning
The core control plane builds a dependency-aware assessment plan from target context, available capabilities, and profile settings. Planning is separated from execution so `plan` can inspect a workflow without invoking tools. Key stages reside in `core/planner.py`, `core/workflow.py`, and `core/scheduler.py`.

#### Mandatory Security Boundary
Scope and authorization constraints are enforced before tool execution and apply to locally registered tools and MCP-exposed capabilities. This is the critical guardrail boundary intended to prevent an LLM or caller from directly bypassing target-policy checks. Primary implementation paths are `core/policy.py`, `core/interfaces.py`, and `core/mcp/policy.py`.

#### Execution, Resilience, and Evidence
The executor runs planned steps independently with concurrency, timeout/retry handling, and resumable atomic checkpoints; individual tool failures retain partial scan progress rather than aborting the overall assessment. Raw tool output is then normalized and analyzed into findings that distinguish evidence from interpretation. See `core/executor.py`, `core/checkpoint.py`, and `core/analyzer.py`.

#### Tool Integration and Extensibility
Two integration styles expose scanner capabilities: adapter implementations for tools/services such as Nmap, ZAP, Metasploit, and tshark; and native plugins for command-line scanners such as Nikto, Nuclei, and Gobuster. Registries and base contracts provide discovery metadata to the planner and CLI. Paths: `core/adapters/base.py`, `core/adapters/registry.py`, `plugins/base.py`, `plugins/manager.py`.

#### LLM and MCP External Boundaries
The planner can use provider-independent LLM clients backed by OpenRouter, OpenAI-compatible APIs, or local Ollama. MCP support registers external stdio or HTTP/SSE JSON-RPC servers, discovers tools, applies policy, and routes calls through a gateway. These are external trust and availability boundaries: `core/llm/factory.py`, `core/llm/openrouter.py`, `core/mcp/gateway.py`, `core/mcp/client.py`.

#### Persistence, Reporting, and Runtime
Assessment history and structured records persist through SQLAlchemy, with SQLite indicated by the CLI workflow. Report renderers transform normalized results into Markdown, HTML, and PDF outputs. Runtime configuration is YAML/environment-driven; deployment supports Docker Compose and a Docker image. Paths: `memory/database.py`, `memory/models.py`, `reports/markdown.py`, `reports/html.py`, `reports/pdf.py`, `config/config.yaml`, `docker-compose.yml`.

Main entry points: [`core/planner.py`](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/planner.py) (Assessment planner), [`core/executor.py`](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/executor.py) (Resilient executor), [`core/policy.py`](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/policy.py) (Scope & authorization), [`core/workflow.py`](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/workflow.py) (Workflow model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Command Surface"]
  node_cli["CLI commands<br/>Python CLI<br/>[cli.py]"]
  node_dashboard["Interactive dashboard<br/>optional UI<br/>[ui.py]"]
  node_config["Runtime configuration<br/>YAML/env config<br/>[config.yaml]"]
end

subgraph group_control["Assessment Control Plane"]
  node_planner["Assessment planner<br/>planning engine<br/>[planner.py]"]
  node_workflow["Workflow model<br/>plan graph<br/>[workflow.py]"]
  node_scheduler["Step scheduler<br/>dependency scheduler<br/>[scheduler.py]"]
  node_policy{{"Scope &amp; authorization<br/>mandatory policy boundary<br/>[policy.py]"}}
  node_tool_contracts["Tool interfaces<br/>capability contracts<br/>[interfaces.py]"]
  node_executor["Resilient executor<br/>concurrent execution engine<br/>[executor.py]"]
  node_checkpoints[("Atomic checkpoints<br/>resume state<br/>[checkpoint.py]")]
end

subgraph group_integration["Tool &amp; External Integrations"]
  node_adapter_registry["Adapter registry<br/>tool discovery<br/>[registry.py]"]
  node_adapter_contracts["Adapter contracts<br/>adapter base<br/>[base.py]"]
  node_plugin_manager["Plugin manager<br/>native plugin discovery<br/>[manager.py]"]
  node_plugin_contracts["Plugin contracts<br/>plugin base<br/>[base.py]"]
  node_local_tools["Local scanners &amp; services<br/>tool implementations"]
  node_llm_factory["LLM provider factory<br/>LLM abstraction<br/>[factory.py]"]
  node_openrouter["OpenRouter client<br/>LLM provider client<br/>[openrouter.py]"]
  node_mcp_gateway{{"MCP policy gateway<br/>external tool boundary<br/>[gateway.py]"}}
  node_mcp_client["MCP client<br/>JSON-RPC transport<br/>[client.py]"]
end

subgraph group_results["Evidence, Records &amp; Reports"]
  node_analyzer["Evidence analyzer<br/>result normalization<br/>[analyzer.py]"]
  node_database[("Assessment records<br/>SQLAlchemy persistence<br/>[database.py]")]
  node_reports["Report renderers<br/>[markdown.py]"]
end

node_cli -->|"creates plan"| node_planner
node_dashboard -->|"starts assessment"| node_planner
node_config -->|"profiles"| node_planner
node_planner -->|"builds"| node_workflow
node_workflow -->|"dependencies"| node_scheduler
node_scheduler -->|"ready steps"| node_executor
node_planner -->|"available capabilities"| node_adapter_registry
node_planner -->|"available capabilities"| node_plugin_manager
node_adapter_registry -->|"registers"| node_adapter_contracts
node_plugin_manager -->|"loads"| node_plugin_contracts
node_adapter_contracts -->|"implements"| node_local_tools
node_plugin_contracts -->|"implements"| node_local_tools
node_planner -.->|"optional planning aid"| node_llm_factory
node_llm_factory -.->|"selects provider"| node_openrouter
node_executor -->|"authorizes invocation"| node_policy
node_policy -->|"permits scoped calls"| node_local_tools
node_executor -->|"MCP invocation"| node_mcp_gateway
node_mcp_gateway -->|"policy-checked routing"| node_mcp_client
node_mcp_client -.->|"discovered capabilities governed"| node_policy
node_executor -->|"save/resume"| node_checkpoints
node_executor -->|"raw outputs"| node_analyzer
node_analyzer -->|"findings and evidence"| node_database
node_database -->|"assessment records"| node_reports

click node_cli "https://github.com/kalilakshman/ai-security-agent-/blob/main/app/cli.py"
click node_dashboard "https://github.com/kalilakshman/ai-security-agent-/blob/main/app/ui.py"
click node_config "https://github.com/kalilakshman/ai-security-agent-/blob/main/config/config.yaml"
click node_planner "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/planner.py"
click node_workflow "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/workflow.py"
click node_scheduler "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/scheduler.py"
click node_policy "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/policy.py"
click node_tool_contracts "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/interfaces.py"
click node_executor "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/executor.py"
click node_checkpoints "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/checkpoint.py"
click node_adapter_registry "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/adapters/registry.py"
click node_adapter_contracts "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/adapters/base.py"
click node_plugin_manager "https://github.com/kalilakshman/ai-security-agent-/blob/main/plugins/manager.py"
click node_plugin_contracts "https://github.com/kalilakshman/ai-security-agent-/blob/main/plugins/base.py"
click node_llm_factory "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/llm/factory.py"
click node_openrouter "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/llm/openrouter.py"
click node_mcp_gateway "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/mcp/gateway.py"
click node_mcp_client "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/mcp/client.py"
click node_analyzer "https://github.com/kalilakshman/ai-security-agent-/blob/main/core/analyzer.py"
click node_database "https://github.com/kalilakshman/ai-security-agent-/blob/main/memory/database.py"
click node_reports "https://github.com/kalilakshman/ai-security-agent-/blob/main/reports/markdown.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_dashboard,node_config toneBlue
class node_planner,node_workflow,node_scheduler,node_policy,node_tool_contracts,node_executor,node_checkpoints toneAmber
class node_adapter_registry,node_adapter_contracts,node_plugin_manager,node_plugin_contracts,node_local_tools,node_llm_factory,node_openrouter,node_mcp_gateway,node_mcp_client toneMint
class node_analyzer,node_database,node_reports toneRose
```

## Components

### Command Surface

- [CLI commands](https://github.com/kalilakshman/ai-security-agent-/blob/main/app/cli.py): Python CLI · Starts assessments and supports plan-only inspection. · `app/cli.py`
- [Interactive dashboard](https://github.com/kalilakshman/ai-security-agent-/blob/main/app/ui.py): optional UI · `app/ui.py`
- [Runtime configuration](https://github.com/kalilakshman/ai-security-agent-/blob/main/config/config.yaml): YAML/env config · `config/config.yaml`

### Assessment Control Plane

- [Assessment planner](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/planner.py): planning engine · Builds a dependency-aware plan from target, profile, and capabilities. · `core/planner.py`
- [Workflow model](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/workflow.py): plan graph · `core/workflow.py`
- [Step scheduler](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/scheduler.py): dependency scheduler · `core/scheduler.py`
- [Scope & authorization](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/policy.py): mandatory policy boundary · Guards every local and MCP capability invocation. · `core/policy.py`
- [Tool interfaces](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/interfaces.py): capability contracts · `core/interfaces.py`
- [Resilient executor](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/executor.py): concurrent execution engine · Runs independent steps with timeout, retry, and partial-progress retention. · `core/executor.py`
- [Atomic checkpoints](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/checkpoint.py): resume state · `core/checkpoint.py`

### Tool & External Integrations

- [Adapter registry](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/adapters/registry.py): tool discovery · Discovers service and scanner adapters for planning. · `core/adapters/registry.py`
- [Adapter contracts](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/adapters/base.py): adapter base · `core/adapters/base.py`
- [Plugin manager](https://github.com/kalilakshman/ai-security-agent-/blob/main/plugins/manager.py): native plugin discovery · `plugins/manager.py`
- [Plugin contracts](https://github.com/kalilakshman/ai-security-agent-/blob/main/plugins/base.py): plugin base · `plugins/base.py`
- **Local scanners & services**: tool implementations · Adapters and plugins expose Nmap, ZAP, Metasploit, Nikto, Nuclei, and Gobuster.
- [LLM provider factory](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/llm/factory.py): LLM abstraction · `core/llm/factory.py`
- [OpenRouter client](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/llm/openrouter.py): LLM provider client · `core/llm/openrouter.py`
- [MCP policy gateway](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/mcp/gateway.py): external tool boundary · Routes policy-checked MCP tool calls. · `core/mcp/gateway.py`
- [MCP client](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/mcp/client.py): JSON-RPC transport · Connects to stdio or HTTP/SSE MCP servers. · `core/mcp/client.py`

### Evidence, Records & Reports

- [Evidence analyzer](https://github.com/kalilakshman/ai-security-agent-/blob/main/core/analyzer.py): result normalization · Separates raw evidence from interpreted findings. · `core/analyzer.py`
- [Assessment records](https://github.com/kalilakshman/ai-security-agent-/blob/main/memory/database.py): SQLAlchemy persistence · Stores assessment history and structured records, including SQLite-backed runs. · `memory/database.py`
- [Report renderers](https://github.com/kalilakshman/ai-security-agent-/blob/main/reports/markdown.py): Markdown / HTML / PDF · `reports/markdown.py`

## Connections

- CLI commands → Assessment planner: creates plan
- Interactive dashboard → Assessment planner: starts assessment
- Runtime configuration → Assessment planner: profiles
- Assessment planner → Workflow model: builds
- Workflow model → Step scheduler: dependencies
- Step scheduler → Resilient executor: ready steps
- Assessment planner → Adapter registry: available capabilities
- Assessment planner → Plugin manager: available capabilities
- Adapter registry → Adapter contracts: registers
- Plugin manager → Plugin contracts: loads
- Adapter contracts → Local scanners & services: implements
- Plugin contracts → Local scanners & services: implements
- Assessment planner → LLM provider factory: optional planning aid
- LLM provider factory → OpenRouter client: selects provider
- Resilient executor → Scope & authorization: authorizes invocation
- Scope & authorization → Local scanners & services: permits scoped calls
- Resilient executor → MCP policy gateway: MCP invocation
- MCP policy gateway → MCP client: policy-checked routing
- MCP client → Scope & authorization: discovered capabilities governed
- Resilient executor → Atomic checkpoints: save/resume
- Resilient executor → Evidence analyzer: raw outputs
- Evidence analyzer → Assessment records: findings and evidence
- Assessment records → Report renderers: assessment records
