# xalgorix/xalgorix architecture

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

- Interactive diagram: https://gitdiagram.com/xalgorix/xalgorix
- Repository: https://github.com/xalgorix/xalgorix

## Overview

#### Purpose and entry points
Xalgorix is a self-hosted AI penetration-testing platform: an LLM agent executes authorized scans, an independent verifier re-tests candidate findings, and the system produces evidence-backed reports. The Go binary entry point is `cmd/xalgorix/main.go`; setup and OS-specific execution are in `cmd/xalgorix/setup.go`, `cmd/xalgorix/exec_unix.go`, and `cmd/xalgorix/exec_windows.go`. It supports CLI scans, a local web server/dashboard, and service-mode lifecycle commands.

#### Runtime composition
The primary runtime is Go (module metadata: `go.mod`), with a React/TypeScript dashboard built from `webui/` and bundled into `internal/web/static/`. Container deployment is defined by `Dockerfile`, `docker-compose.yml`, and `docker-entrypoint.sh`. The intended container is a privileged, disposable scanning sandbox with Chromium and offensive tools available; native Linux is the primary supported runtime.

#### Scan orchestration and durable state
The web backend owns scan lifecycle, admission/scheduling, pause/resume/abort, recovery, and persisted scan records. `internal/web/server.go` wires HTTP/WebSocket serving; `internal/web/orchestrator.go` and `internal/web/scheduler.go` coordinate instances; `internal/web/scan_record.go` and `internal/web/durability.go` persist/recover them. Shared per-scan state—findings, notes, browser state, and terminal state—lives under `internal/scanctx/context.go`, `internal/scanctx/vulnstore.go`, and `internal/scanctx/notestore.go`.

#### Agent, methodology, and verification
`internal/agent/agent.go` runs the LLM-directed reasoning/tool loop. Planning and methodology guidance are separated into `internal/agent/planner.go`, `internal/agent/plan_tools.go`, and prompt/message construction files. The agent can use phase- and domain-specific skill material from `internal/tools/skills/skills.go` and `internal/tools/skills/data/`. `internal/agent/verifier.go` independently re-exploits candidate vulnerabilities before they become confirmed findings, forming the principal quality boundary between discovery and reporting.

#### Tool execution and safety boundaries
The agent accesses capabilities through a central tool registry at `internal/tools/registry.go`. Major adapters include terminal/process execution (`internal/tools/terminal/terminal.go`), HTTP traffic (`internal/tools/httpclient/httpclient.go`), browser automation and WebSocket bridge (`internal/tools/browser/browser.go`, `internal/tools/browser/wsbridge.go`), source/code search, file editing, Python, proxy, and out-of-band interactions. Scope and execution protections are distinct: target restrictions are enforced by `internal/scopeguard/scopeguard.go`; command/filesystem policy by `internal/sandbox/policy.go` and `internal/safe/safe.go`; outbound pacing by `internal/ratelimit/ratelimit.go`.

#### External services and provider boundaries
LLM communication is abstracted by `internal/llm/client.go`, `internal/llm/router.go`, and `internal/llm/resolver.go`, supporting provider-native and OpenAI-compatible endpoints. Authentication/profile flows for providers are implemented in `internal/auth/driver.go` and provider-specific drivers. Optional external integrations include AgentMail through `internal/tools/agentmail/agentmail.go`, out-of-band interaction infrastructure through `internal/oob/interactsh.go`, and configurable proxy routing via `internal/proxy/manager.go`.

#### Presentation and outputs
The backend exposes REST endpoints and live WebSocket events, with fan-out managed by `internal/web/ws_hub.go`. The React UI begins at `webui/src/main.tsx` and routes through `webui/src/router.tsx`; API and websocket client state are under `webui/src/api/client.ts` and `webui/src/store/ws.ts`. Confirmed findings flow into PDF/report generation in `internal/reporting/generate.go`, with severity/risk mapping in `internal/reporting/severity.go` and `internal/reporting/risk.go`.

Main entry points: [`internal/tools/registry.go`](https://github.com/xalgorix/xalgorix/blob/main/internal/tools/registry.go) (Tool registry), [`internal/agent/agent.go`](https://github.com/xalgorix/xalgorix/blob/main/internal/agent/agent.go) (LLM agent loop), [`internal/web/orchestrator.go`](https://github.com/xalgorix/xalgorix/blob/main/internal/web/orchestrator.go) (Scan orchestrator), [`internal/web/server.go`](https://github.com/xalgorix/xalgorix/blob/main/internal/web/server.go) (Web server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; deployment"]
  node_go_entry{{"Go CLI entry<br/>entrypoint<br/>[main.go]"}}
  node_container["Scanning container<br/>deployment"]
end

subgraph group_web["Web control plane"]
  node_web_server["Web server<br/>HTTP/WebSocket backend<br/>[server.go]"]
  node_orchestrator["Scan orchestrator<br/>lifecycle coordinator<br/>[orchestrator.go]"]
  node_scheduler["Scan scheduler<br/>admission scheduler<br/>[scheduler.go]"]
  node_scan_records[("Durable scan records<br/>persistence<br/>[scan_record.go]")]
  node_scan_context[("Per-scan context<br/>shared scan state<br/>[context.go]")]
  node_ws_hub["WebSocket hub<br/>event fan-out<br/>[ws_hub.go]"]
  node_dashboard["React dashboard<br/>web client<br/>[main.tsx]"]
end

subgraph group_agent["Agent execution"]
  node_agent_loop["LLM agent loop<br/>reasoning executor<br/>[agent.go]"]
  node_planner["Planning &amp; methodology<br/>agent planning<br/>[planner.go]"]
  node_verifier{{"Independent verifier<br/>finding quality gate<br/>[verifier.go]"}}
end

subgraph group_tools["Tooling &amp; safety"]
  node_tool_registry["Tool registry<br/>capability gateway<br/>[registry.go]"]
  node_terminal["Terminal execution<br/>process adapter<br/>[terminal.go]"]
  node_browser["Browser automation<br/>browser adapter<br/>[browser.go]"]
  node_scope_guard{{"Scope guard<br/>target policy<br/>[scopeguard.go]"}}
  node_sandbox_policy{{"Sandbox policy<br/>execution policy<br/>[policy.go]"}}
  node_rate_limit["Outbound rate limit<br/>pacing policy<br/>[ratelimit.go]"]
end

subgraph group_external["Providers &amp; outputs"]
  node_llm_router["LLM provider router<br/>provider abstraction<br/>[router.go]"]
  node_reporting["Report generator<br/>PDF reporting<br/>[generate.go]"]
end

node_go_entry -->|"starts local server"| node_web_server
node_container -->|"runs"| node_go_entry
node_dashboard -->|"REST and WebSocket"| node_web_server
node_web_server -->|"scan commands"| node_orchestrator
node_web_server -->|"publishes live events"| node_ws_hub
node_ws_hub -->|"scan updates"| node_dashboard
node_orchestrator -->|"admission and scheduling"| node_scheduler
node_orchestrator -->|"persist and recover"| node_scan_records
node_orchestrator -->|"creates scan state"| node_scan_context
node_scheduler -->|"launches scan"| node_agent_loop
node_agent_loop -->|"plans methodology"| node_planner
node_agent_loop -->|"LLM requests"| node_llm_router
node_agent_loop -->|"uses capabilities"| node_tool_registry
node_tool_registry -->|"process tools"| node_terminal
node_tool_registry -->|"browser tools"| node_browser
node_tool_registry -->|"checks targets"| node_scope_guard
node_tool_registry -->|"checks execution"| node_sandbox_policy
node_tool_registry -->|"paces outbound traffic"| node_rate_limit
node_agent_loop -->|"candidate findings"| node_verifier
node_verifier -->|"confirmed findings"| node_scan_context
node_scan_context -->|"evidence and findings"| node_reporting

click node_go_entry "https://github.com/xalgorix/xalgorix/blob/main/cmd/xalgorix/main.go"
click node_container "https://github.com/xalgorix/xalgorix/blob/main/Dockerfile"
click node_web_server "https://github.com/xalgorix/xalgorix/blob/main/internal/web/server.go"
click node_orchestrator "https://github.com/xalgorix/xalgorix/blob/main/internal/web/orchestrator.go"
click node_scheduler "https://github.com/xalgorix/xalgorix/blob/main/internal/web/scheduler.go"
click node_scan_records "https://github.com/xalgorix/xalgorix/blob/main/internal/web/scan_record.go"
click node_scan_context "https://github.com/xalgorix/xalgorix/blob/main/internal/scanctx/context.go"
click node_ws_hub "https://github.com/xalgorix/xalgorix/blob/main/internal/web/ws_hub.go"
click node_dashboard "https://github.com/xalgorix/xalgorix/blob/main/webui/src/main.tsx"
click node_agent_loop "https://github.com/xalgorix/xalgorix/blob/main/internal/agent/agent.go"
click node_planner "https://github.com/xalgorix/xalgorix/blob/main/internal/agent/planner.go"
click node_verifier "https://github.com/xalgorix/xalgorix/blob/main/internal/agent/verifier.go"
click node_tool_registry "https://github.com/xalgorix/xalgorix/blob/main/internal/tools/registry.go"
click node_terminal "https://github.com/xalgorix/xalgorix/blob/main/internal/tools/terminal/terminal.go"
click node_browser "https://github.com/xalgorix/xalgorix/blob/main/internal/tools/browser/browser.go"
click node_scope_guard "https://github.com/xalgorix/xalgorix/blob/main/internal/scopeguard/scopeguard.go"
click node_sandbox_policy "https://github.com/xalgorix/xalgorix/blob/main/internal/sandbox/policy.go"
click node_rate_limit "https://github.com/xalgorix/xalgorix/blob/main/internal/ratelimit/ratelimit.go"
click node_llm_router "https://github.com/xalgorix/xalgorix/blob/main/internal/llm/router.go"
click node_reporting "https://github.com/xalgorix/xalgorix/blob/main/internal/reporting/generate.go"

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_go_entry,node_container toneBlue
class node_web_server,node_orchestrator,node_scheduler,node_scan_records,node_scan_context,node_ws_hub,node_dashboard toneAmber
class node_agent_loop,node_planner,node_verifier toneMint
class node_tool_registry,node_terminal,node_browser,node_scope_guard,node_sandbox_policy,node_rate_limit toneRose
class node_llm_router,node_reporting toneIndigo
```

## Components

### Entry & deployment

- [Go CLI entry](https://github.com/xalgorix/xalgorix/blob/main/cmd/xalgorix/main.go): entrypoint · CLI, server, and service-mode commands. · `cmd/xalgorix/main.go`
- [Scanning container](https://github.com/xalgorix/xalgorix/blob/main/Dockerfile): deployment · Privileged disposable sandbox with browser and security tools. · `Dockerfile`

### Web control plane

- [Web server](https://github.com/xalgorix/xalgorix/blob/main/internal/web/server.go): HTTP/WebSocket backend · Serves dashboard APIs and scan control endpoints. · `internal/web/server.go`
- [Scan orchestrator](https://github.com/xalgorix/xalgorix/blob/main/internal/web/orchestrator.go): lifecycle coordinator · Owns scan lifecycle, recovery, and control actions. · `internal/web/orchestrator.go`
- [Scan scheduler](https://github.com/xalgorix/xalgorix/blob/main/internal/web/scheduler.go): admission scheduler · `internal/web/scheduler.go`
- [Durable scan records](https://github.com/xalgorix/xalgorix/blob/main/internal/web/scan_record.go): persistence · Persists scan state for recovery. · `internal/web/scan_record.go`
- [Per-scan context](https://github.com/xalgorix/xalgorix/blob/main/internal/scanctx/context.go): shared scan state · Holds findings, notes, browser, and terminal state. · `internal/scanctx/context.go`
- [WebSocket hub](https://github.com/xalgorix/xalgorix/blob/main/internal/web/ws_hub.go): event fan-out · `internal/web/ws_hub.go`
- [React dashboard](https://github.com/xalgorix/xalgorix/blob/main/webui/src/main.tsx): web client · Visualizes scans and controls the backend. · `webui/src/main.tsx`

### Agent execution

- [LLM agent loop](https://github.com/xalgorix/xalgorix/blob/main/internal/agent/agent.go): reasoning executor · Runs iterative reasoning and tool use. · `internal/agent/agent.go`
- [Planning & methodology](https://github.com/xalgorix/xalgorix/blob/main/internal/agent/planner.go): agent planning · Builds plans and applies phase/domain guidance. · `internal/agent/planner.go`
- [Independent verifier](https://github.com/xalgorix/xalgorix/blob/main/internal/agent/verifier.go): finding quality gate · Re-exploits candidate vulnerabilities before confirmation. · `internal/agent/verifier.go`

### Tooling & safety

- [Tool registry](https://github.com/xalgorix/xalgorix/blob/main/internal/tools/registry.go): capability gateway · Central registry for agent-accessible tools. · `internal/tools/registry.go`
- [Terminal execution](https://github.com/xalgorix/xalgorix/blob/main/internal/tools/terminal/terminal.go): process adapter · `internal/tools/terminal/terminal.go`
- [Browser automation](https://github.com/xalgorix/xalgorix/blob/main/internal/tools/browser/browser.go): browser adapter · Browser control and WebSocket bridge. · `internal/tools/browser/browser.go`
- [Scope guard](https://github.com/xalgorix/xalgorix/blob/main/internal/scopeguard/scopeguard.go): target policy · Enforces authorized target restrictions. · `internal/scopeguard/scopeguard.go`
- [Sandbox policy](https://github.com/xalgorix/xalgorix/blob/main/internal/sandbox/policy.go): execution policy · Constrains commands and filesystem access. · `internal/sandbox/policy.go`
- [Outbound rate limit](https://github.com/xalgorix/xalgorix/blob/main/internal/ratelimit/ratelimit.go): pacing policy · `internal/ratelimit/ratelimit.go`

### Providers & outputs

- [LLM provider router](https://github.com/xalgorix/xalgorix/blob/main/internal/llm/router.go): provider abstraction · Routes native and OpenAI-compatible LLM requests. · `internal/llm/router.go`
- [Report generator](https://github.com/xalgorix/xalgorix/blob/main/internal/reporting/generate.go): PDF reporting · Produces evidence-backed reports from confirmed findings. · `internal/reporting/generate.go`

## Connections

- Go CLI entry → Web server: starts local server
- Scanning container → Go CLI entry: runs
- React dashboard → Web server: REST and WebSocket
- Web server → Scan orchestrator: scan commands
- Web server → WebSocket hub: publishes live events
- WebSocket hub → React dashboard: scan updates
- Scan orchestrator → Scan scheduler: admission and scheduling
- Scan orchestrator → Durable scan records: persist and recover
- Scan orchestrator → Per-scan context: creates scan state
- Scan scheduler → LLM agent loop: launches scan
- LLM agent loop → Planning & methodology: plans methodology
- LLM agent loop → LLM provider router: LLM requests
- LLM agent loop → Tool registry: uses capabilities
- Tool registry → Terminal execution: process tools
- Tool registry → Browser automation: browser tools
- Tool registry → Scope guard: checks targets
- Tool registry → Sandbox policy: checks execution
- Tool registry → Outbound rate limit: paces outbound traffic
- LLM agent loop → Independent verifier: candidate findings
- Independent verifier → Per-scan context: confirmed findings
- Per-scan context → Report generator: evidence and findings
