02 — HunterX System Architecture

Status: Ratified Version: 1.0.0 Applies to: Core, all modules, plugins, adapters, SDKs, deployment


1. Architectural Principles

HunterX follows Clean Architecture with strict dependency inversion. The binding rules (enforced by lint gates in CI, see 04 - Coding Standards.md §7):

  1. Dependency Rule (outward-bound-free): source code dependencies point inward only. The Domain layer knows nothing about Infrastructure, Frameworks, or Delivery.
  2. Abstraction over implementation: the Core depends on interfaces (ports); implementations (adapters) are injected at composition root.
  3. Loose coupling via events and messages: subsystems communicate through an Event Bus and Message Bus; no subsystem imports another subsystem’s internals.
  4. AI isolation: AI providers are reachable only through the AI Provider Abstraction. Agents and skills never call LLMs directly.
  5. Pluggability as a contract: every capability is a plugin behind an interface. The core never imports a concrete plugin.
  6. Deterministic core, stochastic periphery: AI, randomness, and timing are pinned and recorded so plans and reports are reproducible.

2. System Context Diagram (C4 Level 1)

                        +---------------------------+
                        |  Engagement Operator      |
                        |  (Pentester / Analyst)    |
                        +-------------+-------------+
                                      |
                    +-----------------+-----------------+
                    |               HunterX             |
                    |   AI-Powered Security Operations  |
                    |           Platform                |
                    +--------+--------+--------+--------+
                             |        |        |
              +--------------+        |        +-----------------+
              |                       |                          |
      +-------+--------+     +--------+-------+         +--------+--------+
      | External Tools |     | AI Providers   |         | External Data   |
      | (nmap, nuclei, |     | (Local/Ollama, |         | (CVE, CWE,      |
      | sqlmap, burp,  |     | Cloud LLMs)    |         |  CAPEC, MITRE,  |
      |  ... 100+ )    |     +----------------+         |  EPSS, CT, DNS) |
      +----------------+                                +-----------------+

3. Container Diagram (C4 Level 2)

+------------------------------------------------------------------------------------+
|                              HUNTERX PLATFORM                                      |
|                                                                                    |
|  +------------------+   +------------------+   +------------------+                |
|  |   CLI             |   |   REST API        |   |   Scheduler      |                |
|  |   (Typer/Click)   |   |   (FastAPI)       |   |   (APScheduler)  |                |
|  +--------+---------+   +--------+---------+   +--------+---------+                |
|           |                     |                     |                             |
|           +---------------------+---------------------+                             |
|                                 |                                                   |
|                        +--------v---------+                                        |
|                        |   ORCHESTRATION  |                                        |
|                        |   (Mission)      |                                        |
|                        +--------+---------+                                        |
|                                 |                                                   |
|                 +---------------+----------------+                                 |
|                 |               |                 |                                |
|        +--------v-----+  +-----v--------+  +-----v---------+                       |
|        | Planner      |  | Workflow     |  | Agent Fleet   |                       |
|        | (AI + rules) |  | Engine       |  | (Multi-Agent) |                       |
|        +--------+-----+  +-----+--------+  +-----+---------+                       |
|                 |               |                 |                                |
|                 +-------+-------+-----------------+                                |
|                         |                                                         |
|               +---------v---------+                                               |
|               |   REASONING/      |                                               |
|               |   DECISION CORE   |                                               |
|               +---------+---------+                                               |
|                         |                                                         |
|      +------------------+--------------------+                                    |
|      |                  |                    |                                   |
| +----v-----+     +------v------+     +-------v-------+                           |
| | Tool     |     | Plugin      |     | AI Provider   |                           |
| | Execution|     | Host        |     | Abstraction   |                           |
| | Sandbox  |     | (SDK)       |     | (Routing,     |                           |
| +----+-----+     +------+------+     |  Cache,       |                           |
|      |                  |            |  Retry,       |                           |
| +----v-----+     +------v------+     |  Circuit)     |                           |
| | Parsers  |     | Registry    |     +-------+-------+                           |
| +----+-----+     +-------------+             |                                    |
|      |                                       |                                    |
| +----v---------------------------------------v----+                               |
| |           DATA & INFRASTRUCTURE LAYER           |                               |
| |  SQL (Target Intel DB) | Graph (KG) | Object    |                               |
| |  Store (Evidence) | Cache (Redis) | Queue (Rabbit) | Event Bus | Log/Telemetry |
| +--------------------------------------------------+-----------------------------+

4. Layered Architecture (C4 Level 3 — component view)

+----------------------------------------------------------------------------------+
| DELIVERY LAYER                                                                   |
|   CLI Commands   REST API   Webhook Sink   Scheduler Jobs                        |
+----------------------------------------------------------------------------------+
| APPLICATION LAYER (use-cases / application services)                              |
|   MissionService   WorkflowService   ReportService   AuthService   AdminService  |
+----------------------------------------------------------------------------------+
| DOMAIN LAYER (pure Python, no framework imports)                                  |
|   Entities: Target, Asset, Finding, Evidence, Mission, Plan, Task, Report         |
|   Value Objects: Port, Service, Risk, Severity, Confidence, Payload               |
|   Domain Services: Planner, Correlator, Validator, RiskScorer, Deduplicator       |
|   Ports (interfaces): ToolPort, StorePort, AIPort, QueuePort, CachePort,          |
|                       EventPort, SecretPort, SandboxPort, LogPort, MetricPort     |
+----------------------------------------------------------------------------------+
| INFRASTRUCTURE LAYER                                                              |
|   Adapters: SQLAlchemy/PostgreSQL, Neo4j, S3/FS, Redis, RabbitMQ, EventBus,       |
|             Vault, DockerSandbox, OpenTelemetry, JSONLogger                       |
|   Tool Integration: ToolExecutor, Parsers, Normalizers, Adapters, Knowledge Files |
|   AI Integration: OpenAIAdapter, OllamaAdapter, local model adapter, caches       |
+----------------------------------------------------------------------------------+

Dependency direction: Delivery → Application → Domain. Infrastructure implements Domain ports and is injected upward at composition root. Nothing in the Domain layer imports fastapi, sqlalchemy, redis, requests, or any third-party library outside the allowed core set.


5. Subsystem Specifications

5.1 Core Engine

The Core Engine is the Domain layer’s heart. It owns:

Responsibilities:

Non-responsibilities:

5.2 AI Engine (Reasoning & Decision Core)

The AI Engine converts goals into validated decisions.

Sub-components:

Component Responsibility
GoalAdapter Converts agent/mission goals into structured AI tasks
PromptManager Builds versioned, schema-tight prompts (no secrets, scoped context)
ProviderRouter Selects provider/model per task class, cost, latency, policy
AIMiddlewarePipeline Logging, masking, schema validation, augmentation
OutputValidator Validates raw LLM output against JSON Schema; rejects malformed
ConsensusEngine Aggregates N samples; strict (unanimous) or relaxed (majority)
ConfidenceScorer Assigns confidence 0.0–1.0 from agreement + calibration
AICache Exact + semantic cache keyed on prompt+model+params
RetryHandler / CircuitBreaker Provider resilience

Rules:

5.3 Workflow Engine

Executes Directed Acyclic Graphs (DAGs) of steps.

Step types: condition, parallel, loop, wait, agent, tool, skill, submission, transform, notify.

5.4 Mission Engine

The Mission Engine is the top-level orchestrator of a complete assessment.

5.5 Planner

The Planner decides what to do next.

Two modes:

  1. Template planner — deterministic expansion of mission profile templates into a plan DAG (reproducible, plan_id = hash(profile, target_scope, params, version)).
  2. AI planner — adaptive replanning during execution: given live findings, the planner proposes next actions, reorders phases, prunes exhausted branches, and requests operator approval for high-risk actions.

Output: a Plan (DAG of PlanSteps), each step referencing a workflow step, tool, skill, or agent with explicit preconditions.

5.6 Knowledge Base

The Knowledge Base is the read-side, versioned corpus of structured knowledge:

Consumed by the Planner (what to run), the AI Engine (grounding), and the Workflow Engine (step definitions).

5.7 Knowledge Graph

The Knowledge Graph stores entities and their relationships for a mission and across missions:

Used for:

5.8 Plugin System

The Plugin System is the extension backbone. See 05 - Plugin SDK Specification.md.

5.9 Tool SDK & Adapter Layer

Two-tier integration contract:

  1. Tool Adapter SDK (06 - Tool Adapter SDK.md): Python interfaces — BaseAdapter, ScannerAdapter, CrawlerAdapter, EnumeratorAdapter, AnalyzerAdapter, ReporterAdapter, ValidationAdapter.
  2. Tool Knowledge File (07 - Tool Knowledge Base Specification.md): YAML metadata describing how to invoke, parse, and reason about a tool.

Every adapter implements: execute(), parse(), normalize(), validate(), healthcheck(), capabilities().

5.10 Parser Engine & Normalizer

The Parser Engine and Normalizer convert arbitrary tool output into the Unified Security Schema.

Pipeline: tool stdout/stderr/file → Parser → Normalizer → CanonicalEvent → Domain entity → Store.

5.11 Correlation Engine

The Correlation Engine derives insight from the store and graph:

5.12 Reporting Engine

Generates all output artifacts. See 21 - Reporting Standards.md.

5.13 CLI

The CLI is a first-class interface. See 19 - CLI Standards.md.

5.14 REST API

The REST API exposes the platform programmatically. See 20 - REST API Standards.md.

5.15 Target Intelligence Database (TIDB)

The Target Intelligence Database is the SQL core store. See 09 - Database Design.md.

5.16 Cache

5.17 Scheduler

5.18 Queue

5.19 Logging

5.20 Configuration

5.21 Secrets

5.22 Telemetry

5.23 Event Bus


6. Key Runtime Flows

6.1 Mission Lifecycle Flow

Operator submits target+profile
  → MissionService validates scope & legality
  → MissionEngine creates Mission (state: DRAFT)
  → Planner expands mission profile into Plan DAG (state: PLANNED)
  → Operator approval gate (if required by profile) (state: APPROVED)
  → WorkflowEngine executes plan steps (state: RUNNING)
        per step:
          tool run → parser → normalizer → store → correlate → update graph
          AI calls for planning/triage/correlation (through AI Engine)
  → Validation phase (proof-of-exploit / false-positive filter) (state: VALIDATED)
  → Correlation & risk aggregation (state: CORRELATED)
  → ReportingEngine generates artifacts (state: COMPLETED)
  → Archive with retention policy (state: ARCHIVED)

6.2 Tool Execution Flow

Workflow step requests tool execution
  → ToolExecutor resolves adapter + knowledge file + sandbox policy
  → Sandbox prepares: scope envelope, time limit, resource limits, env secrets
  → Adapter.execute() runs tool (process or remote worker)
  → ParserEngine parses output (streamed)
  → Normalizer maps to canonical entities
  → CanonicalEvents written to TIDB (transactional, versioned)
  → Events emitted (tool.completed, finding.created)
  → Correlation Engine triggered on new findings

6.3 AI Reasoning Flow

Goal emitted by agent/planner
  → GoalAdapter → structured AITask
  → PromptManager builds prompt (context from KG subgraph + knowledge base)
  → ProviderRouter selects provider/model
  → Middleware (masking, validation, logging)
  → Provider executes (with cache check first)
  → OutputValidator validates schema
  → ConsensusEngine aggregates samples
  → ConfidenceScorer scores confidence
  → Validated ReasoningResult + provenance returned to requester

7. Deployment Topologies

Topology Use case Components
Single node Personal, small team Everything in one process/container
Single node + workers Team scanning API/UI process + N worker processes
Distributed Enterprise API nodes, scheduler, worker fleet, shared Redis/Queue/DB/Graph
Air-gapped Sensitive environments All services local; AI local (Ollama); mirrors of external datasets

All topologies share the same codebase and configuration schema; only the deployment profile differs.


8. Architectural Decision Records (Summary)

ADR Decision
ADR-001 Clean Architecture with ports & adapters; no framework imports in domain
ADR-002 PostgreSQL as primary TIDB; Neo4j for Knowledge Graph; object store for evidence
ADR-003 Async-first execution (asyncio) with process isolation for untrusted tool runs
ADR-004 AI only through provider abstraction; agents never call LLMs directly
ADR-005 YAML knowledge files as single source of tool truth
ADR-006 Event-driven integration via typed Event Bus + Message Bus
ADR-007 Plan IDs and finding hashes are deterministic (content-addressed)
ADR-008 Long operations are async jobs; API returns 202 + job_id
ADR-009 Plugins execute in isolated sandboxes with capability-based permissions
ADR-010 Secrets isolated in vault-backed secret store; masked at all boundaries

9. Cross-Cutting Concerns


10. References