# umfhero/purpleteamai architecture

> Architecture diagram of the GitHub repository umfhero/purpleteamai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/umfhero/purpleteamai
- Repository: https://github.com/umfhero/purpleteamai

## Overview

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: [`frontend/electron/scanner`](https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/scanner) (Scanner), [`frontend/electron/analysis`](https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/analysis) (Analysis), [`frontend/electron/main.ts`](https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/main.ts) (Main Process), [`frontend/src/pages/ScanTarget.tsx`](https://github.com/umfhero/purpleteamai/blob/main/frontend/src/pages/ScanTarget.tsx) (Scan Target)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_frontend["Renderer UI"]
  node_node_scan_target["Scan Target<br/>page<br/>[ScanTarget.tsx]"]
  node_node_dashboard["Dashboard<br/>page<br/>[Dashboard.tsx]"]
  node_node_reports_page["Reports<br/>page<br/>[Reports.tsx]"]
  node_node_ui_components["Security Widgets<br/>ui components"]
  node_node_scan_store[("Scan Store<br/>state store<br/>[scanStore.ts]")]
  node_node_allowlist["Allowlist<br/>guardrail"]
end

subgraph group_group_electron["Electron Backend"]
  node_node_preload["Preload Bridge<br/>ipc bridge<br/>[preload.ts]"]
  node_node_main["Main Process<br/>electron main<br/>[main.ts]"]
  node_node_scanner["Scanner<br/>scan engine"]
  node_node_nmap["Nmap Runner<br/>child process<br/>[nmap.ts]"]
  node_node_parser["XML Parser<br/>parse layer<br/>[parser.ts]"]
  node_node_analysis["Analysis"]
  node_node_llm["LLM Enrichment<br/>ai enrichment"]
  node_node_reports["Report Generator<br/>reporting"]
  node_node_scan_history[("Scan History<br/>persistence<br/>[index.ts]")]
  node_node_report_cache[("Report Cache<br/>persistence<br/>[index.ts]")]
end

subgraph group_group_testsite["Test Site"]
  node_node_testsite["Test Site<br/>vulnerable target<br/>[server.js]"]
end

node_node_scan_target -->|"validates target"| node_node_allowlist
node_node_scan_target -->|"start scan"| node_node_preload
node_node_dashboard -->|"reads state"| node_node_scan_store
node_node_reports_page -->|"opens reports"| node_node_report_cache
node_node_ui_components -->|"renders"| node_node_dashboard
node_node_ui_components -->|"renders"| node_node_reports_page
node_node_preload -->|"ipc"| node_node_main
node_node_main -->|"orchestrates"| node_node_scanner
node_node_scanner -->|"executes"| node_node_nmap
node_node_scanner -->|"parses"| node_node_parser
node_node_scanner -->|"persists"| node_node_scan_history
node_node_parser -->|"feeds findings"| node_node_analysis
node_node_analysis -->|"enriches"| node_node_llm
node_node_analysis -->|"supplies deltas"| node_node_reports
node_node_llm -->|"validated by"| node_node_analysis
node_node_reports -->|"stores"| node_node_report_cache
node_node_scanner -->|"scan data"| node_node_analysis
node_node_main -->|"updates ui"| node_node_scan_store
node_node_testsite -->|"scan target"| node_node_nmap

click node_node_scan_target "https://github.com/umfhero/purpleteamai/blob/main/frontend/src/pages/ScanTarget.tsx"
click node_node_dashboard "https://github.com/umfhero/purpleteamai/blob/main/frontend/src/pages/Dashboard.tsx"
click node_node_reports_page "https://github.com/umfhero/purpleteamai/blob/main/frontend/src/pages/Reports.tsx"
click node_node_ui_components "https://github.com/umfhero/purpleteamai/tree/main/frontend/src/components"
click node_node_scan_store "https://github.com/umfhero/purpleteamai/blob/main/frontend/src/lib/scanStore.ts"
click node_node_allowlist "https://github.com/umfhero/purpleteamai/blob/main/frontend/allowed-targets.json"
click node_node_preload "https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/preload.ts"
click node_node_main "https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/main.ts"
click node_node_scanner "https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/scanner"
click node_node_nmap "https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/scanner/nmap.ts"
click node_node_parser "https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/scanner/parser.ts"
click node_node_analysis "https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/analysis"
click node_node_llm "https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/llm"
click node_node_reports "https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/reports"
click node_node_scan_history "https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/scanner/index.ts"
click node_node_report_cache "https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/reports/index.ts"
click node_node_testsite "https://github.com/umfhero/purpleteamai/blob/main/test-site/server.js"

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_node_scan_target,node_node_dashboard,node_node_reports_page,node_node_ui_components,node_node_scan_store,node_node_allowlist toneBlue
class node_node_preload,node_node_main,node_node_scanner,node_node_nmap,node_node_parser,node_node_analysis,node_node_llm,node_node_reports,node_node_scan_history,node_node_report_cache toneAmber
class node_node_testsite toneMint
```

## Components

### Renderer UI

React + TypeScript desktop presentation layer and local state orchestration.

- [Scan Target](https://github.com/umfhero/purpleteamai/blob/main/frontend/src/pages/ScanTarget.tsx): page · Target entry screen and scan initiation flow. · `frontend/src/pages/ScanTarget.tsx`
- [Dashboard](https://github.com/umfhero/purpleteamai/blob/main/frontend/src/pages/Dashboard.tsx): page · Operational overview and scan status view. · `frontend/src/pages/Dashboard.tsx`
- [Reports](https://github.com/umfhero/purpleteamai/blob/main/frontend/src/pages/Reports.tsx): page · Saved report browser and review page. · `frontend/src/pages/Reports.tsx`
- [Security Widgets](https://github.com/umfhero/purpleteamai/tree/main/frontend/src/components): ui components · Score, coverage, hallucination, and report display components. · `frontend/src/components`
- [Scan Store](https://github.com/umfhero/purpleteamai/blob/main/frontend/src/lib/scanStore.ts): state store · Client-side scan/session state and view coordination. · `frontend/src/lib/scanStore.ts`
- [Allowlist](https://github.com/umfhero/purpleteamai/blob/main/frontend/allowed-targets.json): guardrail · 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](https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/preload.ts): ipc bridge · Context-isolated bridge between renderer and privileged backend. · `frontend/electron/preload.ts`
- [Main Process](https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/main.ts): electron main · Privileged app entry point and IPC coordinator. · `frontend/electron/main.ts`
- [Scanner](https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/scanner): scan engine · Runs Nmap, parses results, normalizes findings, and persists scan history. · `frontend/electron/scanner`
- [Nmap Runner](https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/scanner/nmap.ts): child process · Two-phase network scan execution via Nmap. · `frontend/electron/scanner/nmap.ts`
- [XML Parser](https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/scanner/parser.ts): parse layer · Transforms Nmap XML output into structured scan data. · `frontend/electron/scanner/parser.ts`
- [Analysis](https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/analysis): deterministic analysis · OWASP mapping, security scoring, hallucination checks, and delta comparison. · `frontend/electron/analysis`
- [LLM Enrichment](https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/llm): ai enrichment · Sends compressed scan data to Gemini for narrative findings and remediation. · `frontend/electron/llm`
- [Report Generator](https://github.com/umfhero/purpleteamai/tree/main/frontend/electron/reports): reporting · Creates assessment, pentest, and delta PDF reports with disk-backed cache. · `frontend/electron/reports`
- [Scan History](https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/scanner/index.ts): persistence · Timestamped JSON scan records stored on disk. · `frontend/electron/scanner/index.ts`
- [Report Cache](https://github.com/umfhero/purpleteamai/blob/main/frontend/electron/reports/index.ts): persistence · 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](https://github.com/umfhero/purpleteamai/blob/main/test-site/server.js): vulnerable target · Local intentionally vulnerable web application used for evaluation. · `test-site/server.js`

## Connections

- 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.
