# 0x1adi/klarion architecture

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

- Interactive diagram: https://gitdiagram.com/0x1adi/klarion
- Repository: https://github.com/0x1adi/klarion

## Overview

Klarion scans source and Git changes for candidate credentials, then adjudicates candidates with an AI verifier and reports confirmed or uncertain findings. The main user workflows are filesystem scans, staged/changed/history Git scans, and pre-write or pre-commit protection through Claude Code hooks and MCP tools; baselines help distinguish existing findings. The graph includes documented report formats and verifier choices. Some subsystems are represented from the README or source index rather than sampled implementation, so their internal links are limited to documented or indexed relationships.

Main entry points: [`internal/detect/detector.go`](https://github.com/0x1adi/klarion/blob/main/internal/detect/detector.go) (Secret detector), [`internal/verify/apply.go`](https://github.com/0x1adi/klarion/blob/main/internal/verify/apply.go) (Verifier builder), [`cmd/klarion/run.go`](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/run.go) (Scan runner), [`cmd/klarion/hook.go`](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/hook.go) (Claude Code hook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Commands and workflows"]
  node_scan_cmd["Folder scan<br/>[scan.go]"]
  node_run_cmd["Scan runner<br/>[run.go]"]
  node_git_cmd["Git scan<br/>[git.go]"]
  node_protect_cmd["Protect setup<br/>[protect.go]"]
  node_baseline_cmd["Baseline commands<br/>[baseline.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_gitdata["Git change reader<br/>[git.go]"]
end

subgraph group_detect["Candidate detection"]
  node_walker["Filesystem walker<br/>[walk.go]"]
  node_scanner["File scanner<br/>[scanner.go]"]
  node_detector["Secret detector<br/>[detector.go]"]
  node_structural["Structural checks<br/>[structural.go]"]
  node_decode["Encoded scanning<br/>[decode.go]"]
  node_rules["Built-in rules<br/>[builtin.go]"]
  node_entropy["Entropy scoring<br/>[entropy.go]"]
end

subgraph group_judge["Verification"]
  node_verify_builder["Verifier builder<br/>[apply.go]"]
  node_anthropic["Anthropic judge<br/>[anthropic.go]"]
  node_openai["OpenAI-compatible judge<br/>[openai.go]"]
  node_claude_cli["Claude CLI judge<br/>[claudecli.go]"]
  node_cache[("Verdict cache<br/>[cache.go]")]
end

subgraph group_results["Findings and reports"]
  node_findings["Finding model<br/>[finding.go]"]
  node_baseline[("Baseline state<br/>[baseline.go]")]
  node_reports["Report formats<br/>[report.go]"]
end

subgraph group_integrations["Protection integrations"]
  node_hook["Claude Code hook<br/>[hook.go]"]
  node_mcp_cmd["MCP command<br/>[mcp.go]"]
  node_mcp_server["MCP server<br/>[server.go]"]
  node_mcp_tools["MCP scan tools<br/>[tools.go]"]
end

node_user(("Engineer"))
node_agent(("MCP agent"))
node_claude(("Claude Code"))
node_model(("AI model service"))
node_git_repo[("Git repository")]

node_user -->|"runs scan"| node_scan_cmd
node_user -->|"checks changes"| node_git_cmd
node_scan_cmd -->|"scans paths"| node_scanner
node_scanner -->|"walks roots"| node_walker
node_scanner -->|"scans file content"| node_detector
node_detector -->|"matches rules"| node_rules
node_detector -->|"checks structure"| node_structural
node_detector -->|"rescans encodings"| node_decode
node_detector -->|"scores randomness"| node_entropy
node_detector -->|"emits candidates"| node_findings
node_git_cmd -->|"reads changes"| node_gitdata
node_git_cmd -->|"scans changed lines"| node_detector
node_git_repo -->|"supplies revisions"| node_gitdata
node_run_cmd -->|"loads settings"| node_config
node_run_cmd -->|"builds pipeline"| node_detector
node_run_cmd -->|"adjudicates findings"| node_verify_builder
node_run_cmd -->|"formats results"| node_reports
node_verify_builder -->|"selects provider"| node_anthropic
node_verify_builder -->|"selects provider"| node_openai
node_verify_builder -->|"selects provider"| node_claude_cli
node_verify_builder -.->|"reuses verdicts"| node_cache
node_anthropic -.->|"requests judgments"| node_model
node_openai -.->|"requests judgments"| node_model
node_verify_builder -->|"returns verdicts"| node_findings
node_baseline_cmd -->|"creates baseline"| node_baseline
node_baseline -->|"tracks findings"| node_findings
node_reports -->|"renders findings"| node_findings
node_user -->|"sets protection"| node_protect_cmd
node_protect_cmd -->|"configures Git hooks"| node_gitdata
node_claude -->|"intercepts writes"| node_hook
node_hook -->|"scans tool content"| node_detector
node_hook -->|"reads commit files"| node_gitdata
node_hook -->|"checks candidates"| node_verify_builder
node_agent -->|"starts server"| node_mcp_cmd
node_mcp_cmd -->|"serves MCP"| node_mcp_server
node_agent -->|"calls scan tools"| node_mcp_tools
node_mcp_tools -.->|"scans content"| node_detector
node_mcp_tools -.->|"judges candidates"| node_verify_builder
node_mcp_server -.->|"dispatches tools"| node_mcp_tools

click node_scan_cmd "https://github.com/0x1adi/klarion/blob/main/cmd/klarion/scan.go"
click node_run_cmd "https://github.com/0x1adi/klarion/blob/main/cmd/klarion/run.go"
click node_git_cmd "https://github.com/0x1adi/klarion/blob/main/cmd/klarion/git.go"
click node_protect_cmd "https://github.com/0x1adi/klarion/blob/main/cmd/klarion/protect.go"
click node_baseline_cmd "https://github.com/0x1adi/klarion/blob/main/cmd/klarion/baseline.go"
click node_config "https://github.com/0x1adi/klarion/blob/main/internal/config/config.go"
click node_walker "https://github.com/0x1adi/klarion/blob/main/internal/scan/walk.go"
click node_scanner "https://github.com/0x1adi/klarion/blob/main/internal/scan/scanner.go"
click node_detector "https://github.com/0x1adi/klarion/blob/main/internal/detect/detector.go"
click node_structural "https://github.com/0x1adi/klarion/blob/main/internal/detect/structural.go"
click node_decode "https://github.com/0x1adi/klarion/blob/main/internal/detect/decode.go"
click node_rules "https://github.com/0x1adi/klarion/blob/main/internal/rules/builtin.go"
click node_entropy "https://github.com/0x1adi/klarion/blob/main/internal/entropy/entropy.go"
click node_gitdata "https://github.com/0x1adi/klarion/blob/main/internal/git/git.go"
click node_verify_builder "https://github.com/0x1adi/klarion/blob/main/internal/verify/apply.go"
click node_anthropic "https://github.com/0x1adi/klarion/blob/main/internal/verify/anthropic.go"
click node_openai "https://github.com/0x1adi/klarion/blob/main/internal/verify/openai.go"
click node_claude_cli "https://github.com/0x1adi/klarion/blob/main/internal/verify/claudecli.go"
click node_cache "https://github.com/0x1adi/klarion/blob/main/internal/verify/cache.go"
click node_findings "https://github.com/0x1adi/klarion/blob/main/internal/finding/finding.go"
click node_baseline "https://github.com/0x1adi/klarion/blob/main/internal/baseline/baseline.go"
click node_reports "https://github.com/0x1adi/klarion/blob/main/internal/report/report.go"
click node_hook "https://github.com/0x1adi/klarion/blob/main/cmd/klarion/hook.go"
click node_mcp_cmd "https://github.com/0x1adi/klarion/blob/main/cmd/klarion/mcp.go"
click node_mcp_server "https://github.com/0x1adi/klarion/blob/main/internal/mcp/server.go"
click node_mcp_tools "https://github.com/0x1adi/klarion/blob/main/internal/mcp/tools.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_scan_cmd,node_run_cmd,node_git_cmd,node_protect_cmd,node_baseline_cmd,node_config,node_gitdata toneBlue
class node_walker,node_scanner,node_detector,node_structural,node_decode,node_rules,node_entropy,node_git_repo toneAmber
class node_verify_builder,node_anthropic,node_openai,node_claude_cli,node_cache toneMint
class node_findings,node_baseline,node_reports toneRose
class node_hook,node_mcp_cmd,node_mcp_server,node_mcp_tools,node_user,node_agent,node_claude,node_model toneIndigo
```

## Components

### Commands and workflows

- [Folder scan](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/scan.go): `cmd/klarion/scan.go`
- [Scan runner](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/run.go): `cmd/klarion/run.go`
- [Git scan](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/git.go): `cmd/klarion/git.go`
- [Protect setup](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/protect.go): `cmd/klarion/protect.go`
- [Baseline commands](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/baseline.go): `cmd/klarion/baseline.go`
- [Configuration](https://github.com/0x1adi/klarion/blob/main/internal/config/config.go): `internal/config/config.go`
- [Git change reader](https://github.com/0x1adi/klarion/blob/main/internal/git/git.go): `internal/git/git.go`

### Candidate detection

- [Filesystem walker](https://github.com/0x1adi/klarion/blob/main/internal/scan/walk.go): `internal/scan/walk.go`
- [File scanner](https://github.com/0x1adi/klarion/blob/main/internal/scan/scanner.go): `internal/scan/scanner.go`
- [Secret detector](https://github.com/0x1adi/klarion/blob/main/internal/detect/detector.go): `internal/detect/detector.go`
- [Structural checks](https://github.com/0x1adi/klarion/blob/main/internal/detect/structural.go): `internal/detect/structural.go`
- [Encoded scanning](https://github.com/0x1adi/klarion/blob/main/internal/detect/decode.go): `internal/detect/decode.go`
- [Built-in rules](https://github.com/0x1adi/klarion/blob/main/internal/rules/builtin.go): `internal/rules/builtin.go`
- [Entropy scoring](https://github.com/0x1adi/klarion/blob/main/internal/entropy/entropy.go): `internal/entropy/entropy.go`

### Verification

- [Verifier builder](https://github.com/0x1adi/klarion/blob/main/internal/verify/apply.go): `internal/verify/apply.go`
- [Anthropic judge](https://github.com/0x1adi/klarion/blob/main/internal/verify/anthropic.go): `internal/verify/anthropic.go`
- [OpenAI-compatible judge](https://github.com/0x1adi/klarion/blob/main/internal/verify/openai.go): `internal/verify/openai.go`
- [Claude CLI judge](https://github.com/0x1adi/klarion/blob/main/internal/verify/claudecli.go): `internal/verify/claudecli.go`
- [Verdict cache](https://github.com/0x1adi/klarion/blob/main/internal/verify/cache.go): `internal/verify/cache.go`

### Findings and reports

- [Finding model](https://github.com/0x1adi/klarion/blob/main/internal/finding/finding.go): `internal/finding/finding.go`
- [Baseline state](https://github.com/0x1adi/klarion/blob/main/internal/baseline/baseline.go): `internal/baseline/baseline.go`
- [Report formats](https://github.com/0x1adi/klarion/blob/main/internal/report/report.go): `internal/report/report.go`

### Protection integrations

- [Claude Code hook](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/hook.go): `cmd/klarion/hook.go`
- [MCP command](https://github.com/0x1adi/klarion/blob/main/cmd/klarion/mcp.go): `cmd/klarion/mcp.go`
- [MCP server](https://github.com/0x1adi/klarion/blob/main/internal/mcp/server.go): `internal/mcp/server.go`
- [MCP scan tools](https://github.com/0x1adi/klarion/blob/main/internal/mcp/tools.go): `internal/mcp/tools.go`

### Other components

- **Engineer**
- **MCP agent**
- **Claude Code**
- **AI model service**
- **Git repository**

## Connections

- Engineer → Folder scan: runs scan (evidence: `README.md`)
- Engineer → Git scan: checks changes (evidence: `README.md`)
- Folder scan → File scanner: scans paths (evidence: `cmd/klarion/scan.go`)
- File scanner → Filesystem walker: walks roots (evidence: `internal/scan/scanner.go`)
- File scanner → Secret detector: scans file content (evidence: `internal/scan/scanner.go`)
- Secret detector → Built-in rules: matches rules (evidence: `internal/detect/detector.go`)
- Secret detector → Structural checks: checks structure (evidence: `README.md`)
- Secret detector → Encoded scanning: rescans encodings (evidence: `internal/detect/detector.go`)
- Secret detector → Entropy scoring: scores randomness (evidence: `internal/detect/detector.go`)
- Secret detector → Finding model: emits candidates (evidence: `internal/detect/detector.go`)
- Git scan → Git change reader: reads changes (evidence: `cmd/klarion/git.go`)
- Git scan → Secret detector: scans changed lines (evidence: `cmd/klarion/git.go`)
- Git repository → Git change reader: supplies revisions (evidence: `internal/git/git.go`)
- Scan runner → Configuration: loads settings (evidence: `cmd/klarion/run.go`)
- Scan runner → Secret detector: builds pipeline (evidence: `cmd/klarion/run.go`)
- Scan runner → Verifier builder: adjudicates findings (evidence: `cmd/klarion/run.go`)
- Scan runner → Report formats: formats results (evidence: `cmd/klarion/run.go`)
- Verifier builder → Anthropic judge: selects provider (evidence: `internal/verify/apply.go`)
- Verifier builder → OpenAI-compatible judge: selects provider (evidence: `internal/verify/apply.go`)
- Verifier builder → Claude CLI judge: selects provider (evidence: `internal/verify/apply.go`)
- Verifier builder → Verdict cache: reuses verdicts (evidence: `README.md`)
- Anthropic judge → AI model service: requests judgments (evidence: `README.md`)
- OpenAI-compatible judge → AI model service: requests judgments (evidence: `README.md`)
- Verifier builder → Finding model: returns verdicts (evidence: `internal/verify/apply.go`)
- Baseline commands → Baseline state: creates baseline (evidence: `cmd/klarion/baseline.go`)
- Baseline state → Finding model: tracks findings (evidence: `internal/baseline/baseline.go`)
- Report formats → Finding model: renders findings (evidence: `internal/report/report.go`)
- Engineer → Protect setup: sets protection (evidence: `README.md`)
- Protect setup → Git change reader: configures Git hooks (evidence: `cmd/klarion/protect.go`)
- Claude Code → Claude Code hook: intercepts writes (evidence: `README.md`)
- Claude Code hook → Secret detector: scans tool content (evidence: `cmd/klarion/hook.go`)
- Claude Code hook → Git change reader: reads commit files (evidence: `cmd/klarion/hook.go`)
- Claude Code hook → Verifier builder: checks candidates (evidence: `cmd/klarion/hook.go`)
- MCP agent → MCP command: starts server (evidence: `README.md`)
- MCP command → MCP server: serves MCP (evidence: `cmd/klarion/mcp.go`)
- MCP agent → MCP scan tools: calls scan tools (evidence: `README.md`)
- MCP scan tools → Secret detector: scans content
- MCP scan tools → Verifier builder: judges candidates
- MCP server → MCP scan tools: dispatches tools
