How umfhero/purpleteamai works
1. Overall shape
PurpleTeamAI is a desktop security assessment system built as an Electron app with a React + TypeScript renderer and a privileged Electron main process. The architecture is a one-way pipeline: user selects a target, the backend scans it, deterministic analysis runs, LLM enrichment produces human-readable findings, and reports/deltas are generated for review.
2. Trust boundary and IPC model
The renderer is intentionally constrained: context isolation is on and node integration is off, so the UI cannot directly access the filesystem or spawn processes. All privileged operations go through a preload bridge and IPC channels. This boundary is important in the diagram because the Electron main process owns scanning, persistence, and report generation.
3. Frontend presentation layer
The frontend/src tree is a standard React app with page-level views for Scan Target, Dashboard, and Reports. Shared components render security-specific outputs such as the Security Score Card, OWASP Coverage Matrix, Hallucination Metrics Panel, and Report Viewer. The UI is dark-themed and appears to be centered on operational review rather than generic navigation.
4. Client-side state and orchestration
The renderer uses a small local state layer in src/lib (scanStore, useScanStore, utility hooks) to hold scan/session data and drive page transitions. This layer does not perform scanning itself; it consumes data delivered from Electron and coordinates what the user sees, including scan progress, results, and cached reports.
5. Target validation and scan control
Before scanning begins, targets are constrained by an allowlist in frontend/allowed-targets.json. This is a key architectural guardrail: only pre-approved hosts can enter the scan pipeline. The scanner also supports aborting mid-run, which matters for the data flow because scan jobs are long-running and progress-sensitive.
6. Scanner subsystem
The electron/scanner module is the execution engine. It launches Nmap as a child process, performs a two-phase scan (fast top-100 ports first, full scan second), parses XML output into structured data, and normalizes findings. It also adds post-processing detections such as missing HTTPS and missing security headers, then persists scan history to disk as timestamped JSON.
7. Deterministic analysis subsystem
The electron/analysis module is where the project’s non-LLM logic lives. It maps findings to OWASP Top 10 categories using keyword scoring and regex rules, computes a 0–100 security score, and runs the hallucination guard that compares AI output against scan truth. It also includes delta comparison logic to classify vulnerabilities as new, resolved, or persisting across scans.
8. LLM enrichment subsystem
The electron/llm module sends compressed scan data to Google Gemini for plain-English interpretation and remediation guidance. The LLM is constrained through structured prompting, low temperature, retry/backoff behavior, and batching for large result sets. The important architectural point is that Gemini is not the source of truth; it is an enrichment layer sitting after deterministic scanning and classification.
9. Report generation and persistence
The electron/reports module turns scan and delta data into PDF reports in multiple styles: assessment, pentest, and delta comparison. Reports are cached and stored on disk with metadata so they can be reopened from the Reports page. This creates a separate persistence path from the raw scan history, optimized for presentation rather than reprocessing.
10. Data flow through the system
The core flow is: approved target → Nmap scan → XML parsing/normalization → OWASP mapping and security scoring → Gemini analysis → hallucination validation → UI display/report generation. On repeat scans, the system adds a second flow: current scan + prior scan → delta classification → score/coverage changes → delta report. This makes the repository best understood as a pipeline with a strong deterministic core and an AI-assisted narrative layer.
11. Evaluation and controlled test environment
The repo includes a separate test-site application that serves as a deliberately vulnerable localhost training target, with pages and endpoints for common web issues. This is not part of the production app; it is the evaluation harness used to verify detection, scoring, and remediation behavior under known conditions. The documentation also indicates testing against external training targets like testphp.vulnweb.com.
12. External dependencies that matter architecturally
The only external services that materially shape the architecture are Nmap for scanning and Gemini for analysis, with Ollama mentioned as a fallback path. The rest of the system is local and file-backed: scan history, report cache, allowlists, and evaluation artifacts all live within the desktop app’s environment.
Main entry points: scanner Scanner · analysis Analysis · main.ts Main Process · ScanTarget.tsx Scan Target
Components 17
Renderer UI
React + TypeScript desktop presentation layer and local state orchestration.
- Scan Target · Target entry screen and scan initiation flow.
frontend/src/pages/ScanTarget.tsx - Dashboard · Operational overview and scan status view.
frontend/src/pages/Dashboard.tsx - Reports · Saved report browser and review page.
frontend/src/pages/Reports.tsx - Security Widgets · Score, coverage, hallucination, and report display components.
frontend/src/components - Scan Store · Client-side scan/session state and view coordination.
frontend/src/lib/scanStore.ts - Allowlist · Approved target list that constrains what can be scanned.
frontend/allowed-targets.json
Electron Backend
Privileged main-process pipeline for scanning, analysis, LLM enrichment, and reports.
- Preload Bridge · Context-isolated bridge between renderer and privileged backend.
frontend/electron/preload.ts - Main Process · Privileged app entry point and IPC coordinator.
frontend/electron/main.ts - Scanner · Runs Nmap, parses results, normalizes findings, and persists scan history.
frontend/electron/scanner - Nmap Runner · Two-phase network scan execution via Nmap.
frontend/electron/scanner/nmap.ts - XML Parser · Transforms Nmap XML output into structured scan data.
frontend/electron/scanner/parser.ts - Analysis · OWASP mapping, security scoring, hallucination checks, and delta comparison.
frontend/electron/analysis - LLM Enrichment · Sends compressed scan data to Gemini for narrative findings and remediation.
frontend/electron/llm - Report Generator · Creates assessment, pentest, and delta PDF reports with disk-backed cache.
frontend/electron/reports - Scan History · Timestamped JSON scan records stored on disk.
frontend/electron/scanner/index.ts - Report Cache · Stored report artifacts and metadata for reopening later.
frontend/electron/reports/index.ts
Test Site
Deliberately vulnerable local training target used for evaluation.
- Test Site · Local intentionally vulnerable web application used for evaluation.
test-site/server.js
Connections 19
- Scan Target → Allowlist: validates target · UI constrains scan entry to approved hosts.
- Scan Target → Preload Bridge: start scan · Renderer requests privileged operations through the bridge.
- Dashboard → Scan Store: reads state · Dashboard renders current scan progress and results.
- Reports → Report Cache: opens reports · Reports page reads cached report artifacts.
- Security Widgets → Dashboard: renders · Shared widgets support operational views.
- Security Widgets → Reports: renders · Report and metrics widgets support review flows.
- Preload Bridge → Main Process: ipc · Bridge forwards renderer requests into the main process.
- Main Process → Scanner: orchestrates · Main process coordinates scan execution and downstream processing.
- Scanner → Nmap Runner: executes · Scanner launches Nmap as a child process.
- Scanner → XML Parser: parses · Scanner converts XML output into structured findings.
- Scanner → Scan History: persists · Raw scan results are written to disk.
- XML Parser → Analysis: feeds findings · Structured scan data enters deterministic analysis.
- Analysis → LLM Enrichment: enriches · Analysis output is packaged for LLM interpretation.
- Analysis → Report Generator: supplies deltas · Delta comparison and score changes feed reporting.
- LLM Enrichment → Analysis: validated by · Hallucination guard checks AI output against scan truth.
- Report Generator → Report Cache: stores · Generated PDFs and metadata are cached for later viewing.
- Scanner → Analysis: scan data · Deterministic analysis consumes scan results and history.
- Main Process → Scan Store: updates ui · Backend events refresh renderer state through IPC.
- Test Site → Nmap Runner: scan target · Evaluation harness provides a known vulnerable host.