How youngsecurity/pentest-agent-system works
1. This repository is a multi-part security tooling workspace, not a single app. The main production system described by the README is the “Nmap Real-time Visualization System,” but the tree also contains a separate Python-based security analyst/agent package and a small Deno area for experiments/tests.
2. The core runtime architecture is split into a FastAPI backend and a Svelte frontend. The backend owns scan execution, parsing, progress state, and WebSocket delivery; the frontend owns the interactive UI, real-time rendering, and client-side connection management.
3. In the backend, app/main.py is the application entrypoint and app/core/config.py holds runtime configuration. API routes are separated by responsibility: health.py for liveness checks, nmap.py for scan control and scan-related REST endpoints, and websocket.py for push-based scan updates.
4. The backend is organized as a service-oriented pipeline for Nmap processing. app/services/nmap/runner.py executes Nmap, parser.py turns raw output into structured data, locator.py handles discovery of the Nmap binary or related environment details, and service.py acts as the orchestration layer between routes and the lower-level execution/parsing logic.
5. The Nmap data model boundary is explicit. app/models/nmap.py defines the structured scan result objects that travel between parsing, API responses, and client-side visualization, keeping raw process output isolated from structured scan state.
6. Real-time delivery is handled by a dedicated WebSocket subsystem in app/services/ws/manager.py. This manager is the boundary between backend scan progress and connected clients: it tracks sessions/connections and broadcasts incremental updates as scans run, which is what enables live visualization instead of polling.
7. Progress and operational state are supported by utility modules rather than embedded in the routes. app/utils/progress_tracker.py and app/utils/logging_utils.py suggest centralized tracking/logging concerns, while app/services/interfaces.py and exceptions.py define service contracts and error boundaries. The tests in backend/tests/unit/services/... mirror this layering and verify the nmap and websocket subsystems independently.
8. The frontend is a Svelte application with a very small composition surface: src/main.ts bootstraps App.svelte, and the project-level README indicates the UI is built around real-time terminal-style output plus structured progress/port/vulnerability views. Vite is the build/runtime toolchain (vite.config.js, package.json), which matters because the frontend is a separate SPA served to the browser and connected back to FastAPI over WebSockets.
9. There is a second, distinct Python package under python/src/pentest_agent_system focused on AI-assisted security analysis rather than live Nmap visualization. Its architecture includes agents (modules/agents), a model handler, tool integration, a database manager, Metasploit integration, and UI components built around a chat/pentest/testing workflow.
10. The Python package is also layered around orchestration. security_analyst_orchestrator_agent.py, security_analyst_agent.py, vulnerability_extractor_agent.py, mitre_attack_mapper_agent.py, and attack_plan_generator_agent.py indicate an agent pipeline that transforms scan or exploit data into analysis, mapping, and attack planning outputs; callbacks/, utils/, and models/ support that flow with reusable infrastructure.
11. External process and tool boundaries are important in both subsystems. The backend wraps the Nmap CLI as an external subprocess, while the Python security-analyst package appears to integrate with model inference and Metasploit as external dependencies. Those integrations are isolated behind service/module boundaries so the rest of the code can work with structured results rather than raw tool output.
12. Persistence appears lightweight and file-based in the main backend, with storage/data.json suggesting local state or result storage rather than a heavy database layer. This fits the README’s “stateless design with file-based progress tracking” and means the architecture is centered on streaming updates plus structured scan results, not on long-term backend persistence.
13. The test layout reinforces the system boundaries. Backend tests focus on websocket behavior and Nmap service internals; Python tests cover agent behavior, parsing, vulnerability detection, and end-to-end security analyst flows. For an architecture diagram, the key edges are: browser/UI ↔ WebSocket/API ↔ FastAPI service layer ↔ Nmap subprocess/parsers, plus a separate Python agent pipeline that consumes security data and produces analysis outputs.
Main entry points: service.py Nmap service · security_analyst_orchestrator_agent.py Orchestrator · main.py App entry · App.svelte App UI
Components 33
Backend
FastAPI runtime for Nmap execution, parsing, progress tracking, and WebSocket updates.
- App entry · Backend application entrypoint and wiring.
backend/app/main.py - Config · Backend environment and application settings.
backend/app/core/config.py - Health API · Liveness and readiness checks.
backend/app/api/routes/health.py - Nmap API · REST endpoints for scan control and scan-related operations.
backend/app/api/routes/nmap.py - WebSocket API · Push channel for live scan progress and updates.
backend/app/api/routes/websocket.py - Nmap service · Coordinates scan execution, parsing, and API-facing scan state.
backend/app/services/nmap/service.py - Runner · Launches the Nmap CLI and captures output.
backend/app/services/nmap/runner.py - Parser · Converts raw Nmap output into structured scan data.
backend/app/services/nmap/parser.py - Locator · Finds the Nmap binary and related execution environment details.
backend/app/services/nmap/locator.py - WS manager · Tracks client sessions and broadcasts incremental scan progress.
backend/app/services/ws/manager.py - Scan model · Structured scan result objects shared across parsing, API, and UI boundaries.
backend/app/models/nmap.py - Progress tracker · Centralized scan progress state management.
backend/app/utils/progress_tracker.py - Logging utils · Centralized backend logging helpers.
backend/app/utils/logging_utils.py - Interfaces · Shared service abstractions and boundaries.
backend/app/services/interfaces.py - Exceptions · Backend service error types and domain exceptions.
backend/app/services/exceptions.py
Frontend
Svelte SPA that renders live scan results and manages browser connections.
- Bootstrap · Browser entrypoint that mounts the Svelte app.
frontend/src/main.ts - App UI · Main user interface for live visualization and scan views.
frontend/src/App.svelte - Vite build · Frontend build and dev server configuration.
frontend/vite.config.js
Python agent
Separate pentest/security analyst package with agent orchestration and tooling.
- Agent entry · Entry point for the pentest agent package.
python/src/pentest_agent_system/main.py - Orchestrator · Coordinates the security analyst workflow across specialized agents.
python/src/pentest_agent_system/modules/agents/security_analyst_orchestrator_agent.py - Security analyst · Primary analysis agent for security reasoning and synthesis.
python/src/pentest_agent_system/modules/security_analyst_agent.py - Vuln extractor · Extracts vulnerabilities and evidence from scan or exploit data.
python/src/pentest_agent_system/modules/agents/vulnerability_extractor_agent.py - MITRE mapper · Maps findings to MITRE ATT&CK style techniques and patterns.
python/src/pentest_agent_system/modules/agents/mitre_attack_mapper_agent.py - Attack planner · Generates attack plan outputs from analysis context.
python/src/pentest_agent_system/modules/agents/attack_plan_generator_agent.py - Model handler · Wraps model inference and AI model access.
python/src/pentest_agent_system/models/model_handler.py - Tools · Common tool and external dependency integration layer.
python/src/pentest_agent_system/modules/tools.py - Metasploit · Metasploit integration boundary for exploitation-oriented workflows.
python/src/pentest_agent_system/modules/metasploit_agent.py - DB manager · Lightweight persistence and data management for the agent system.
python/src/pentest_agent_system/modules/db_manager.py - Result schema · Structured output schema for agent results.
python/src/pentest_agent_system/utils/result_schema.py
Deno
Small experimental area for Deno-based scripts and tests.
- Deno main · Deno runtime entrypoint for experiments or tests.
deno/main.ts - Deno tests · Deno test harness.
deno/main_test.ts
Connections 35
- App entry → Config: loads · Startup reads runtime configuration.
- App entry → Health API: mounts · Application wires health routes.
- App entry → Nmap API: mounts · Application wires scan control routes.
- App entry → WebSocket API: mounts · Application wires WebSocket routes.
- Nmap API → Nmap service: calls · REST endpoints delegate scan orchestration.
- WebSocket API → WS manager: uses · WebSocket endpoints rely on the connection hub.
- Nmap service → Locator: resolves · Service finds the Nmap executable/environment.
- Nmap service → Runner: executes · Service launches scans through the runner.
- Nmap service → Parser: parses · Service converts raw output into structured results.
- Parser → Scan model: builds · Parser produces structured scan models.
- Runner → Scan model: feeds · Runner output is normalized into scan data.
- Nmap service → Progress tracker: updates · Service advances scan progress state.
- Progress tracker → WS manager: publishes · Progress state is broadcast to connected clients.
- WS manager → WebSocket API: serves · Manager backs live delivery for WebSocket clients.
- Nmap service → Interfaces: implements · Service layer follows shared contracts.
- Nmap service → Exceptions: raises · Service boundary emits domain errors.
- Nmap service → Data file: persists · Scan state may be stored in local file-backed data.
- Bootstrap → App UI: mounts · Svelte bootstrap renders the main app.
- App UI → Vite build: built by · Frontend is packaged and served through Vite.
- App UI → WebSocket API: connects to · UI consumes live scan updates from backend WebSocket delivery.
- App UI → Nmap API: requests · UI triggers scan actions through REST endpoints.
- Agent entry → Orchestrator: starts · Package entrypoint launches the agent workflow.
- Orchestrator → Security analyst: delegates · Orchestrator coordinates the core analyst agent.
- Orchestrator → Vuln extractor: delegates · Workflow extracts vulnerabilities as a stage.
- Orchestrator → MITRE mapper: delegates · Workflow maps findings to ATT&CK style techniques.
- Orchestrator → Attack planner: delegates · Workflow generates attack planning outputs.
- Security analyst → Model handler: uses · Agent relies on model inference wrapper.
- Security analyst → Tools: uses · Agent accesses external tools and helpers.
- Tools → Metasploit: bridges · Tool layer isolates Metasploit integration.
- Security analyst → DB manager: stores · Agent uses persistence for results or context.
- Orchestrator → Result schema: formats · Workflow emits structured result objects.
- Orchestrator → Data file: reads/writes · Agent package can share lightweight file-backed state.
- Deno main → Deno tests: verified by · Deno script is covered by its test harness.
- Docs → App entry: describes · Documentation explains the main backend runtime.
- Docs → Orchestrator: describes · Documentation also covers the agent pipeline.