# sandstrompl/whyreach architecture

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

- Interactive diagram: https://gitdiagram.com/sandstrompl/whyreach
- Repository: https://github.com/sandstrompl/whyreach

## Overview

whyreach is a read-only Docker connectivity diagnosis tool, exposed through a CLI and an MCP server. A request is validated and permission-checked, resolved into a source and destination, then the engine gathers Docker and network-namespace evidence, evaluates rules, and returns findings with proof and fixes. The product also supports environment inspection, standalone probes, doctor checks, and report saving. The README documents the overall workflow; sampled source and the SOURCE INDEX support the cited internal links, but some subsystem details remain unsampled.

Main entry points: [`internal/engine/engine.go`](https://github.com/sandstrompl/whyreach/blob/main/internal/engine/engine.go) (Diagnosis engine), [`internal/policy/policy.go`](https://github.com/sandstrompl/whyreach/blob/main/internal/policy/policy.go) (Safety policy), [`internal/cli/cli.go`](https://github.com/sandstrompl/whyreach/blob/main/internal/cli/cli.go) (CLI commands), [`internal/mcpserver/server.go`](https://github.com/sandstrompl/whyreach/blob/main/internal/mcpserver/server.go) (MCP tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI commands<br/>[cli.go]"]
  node_mcp["MCP tools<br/>[server.go]"]
end

subgraph group_control["Policy and orchestration"]
  node_policy["Safety policy<br/>[policy.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_engine["Diagnosis engine<br/>[engine.go]"]
  node_target["Target parsing<br/>[target.go]"]
end

subgraph group_observe["Network evidence"]
  node_docker["Docker metadata<br/>[containers.go]"]
  node_host["Host network facts<br/>[host.go]"]
  node_executor["Probe executors<br/>[executor.go]"]
  node_probecontainer["Probe container<br/>[probecontainer.go]"]
  node_probes["DNS and TCP probes<br/>[dns.go]"]
end

subgraph group_diagnose["Diagnosis and results"]
  node_evidence[("Evidence store and views<br/>[view.go]")]
  node_rules["Cause rules<br/>[wr007_localhost.go]"]
  node_reports["Report generation<br/>[bundles.go]"]
end

node_developer(("Developer or agent"))
node_dockerdaemon[("Docker Engine")]

node_developer -->|"runs commands"| node_cli
node_developer -->|"calls tools"| node_mcp
node_cli -->|"submits requests"| node_policy
node_mcp -->|"routes tool calls"| node_policy
node_policy -->|"uses settings"| node_config
node_policy -->|"parses targets"| node_target
node_policy -->|"runs diagnosis"| node_engine
node_engine -->|"collects metadata"| node_docker
node_engine -->|"collects host facts"| node_host
node_engine -->|"runs checks"| node_executor
node_executor -->|"executes checks"| node_probes
node_executor -->|"delegates probing"| node_probecontainer
node_probecontainer -->|"creates probe container"| node_dockerdaemon
node_engine -->|"records observations"| node_evidence
node_engine -->|"evaluates findings"| node_rules
node_rules -->|"reads evidence"| node_evidence
node_cli -->|"renders reports"| node_reports
node_mcp -->|"saves reports"| node_reports
node_docker -->|"reads metadata"| node_dockerdaemon

click node_cli "https://github.com/sandstrompl/whyreach/blob/main/internal/cli/cli.go"
click node_mcp "https://github.com/sandstrompl/whyreach/blob/main/internal/mcpserver/server.go"
click node_policy "https://github.com/sandstrompl/whyreach/blob/main/internal/policy/policy.go"
click node_config "https://github.com/sandstrompl/whyreach/blob/main/internal/config/config.go"
click node_engine "https://github.com/sandstrompl/whyreach/blob/main/internal/engine/engine.go"
click node_target "https://github.com/sandstrompl/whyreach/blob/main/internal/target/target.go"
click node_docker "https://github.com/sandstrompl/whyreach/blob/main/internal/collect/docker/containers.go"
click node_host "https://github.com/sandstrompl/whyreach/blob/main/internal/collect/host/host.go"
click node_executor "https://github.com/sandstrompl/whyreach/blob/main/internal/executor/executor.go"
click node_probecontainer "https://github.com/sandstrompl/whyreach/blob/main/internal/executor/probecontainer.go"
click node_probes "https://github.com/sandstrompl/whyreach/blob/main/internal/probe/dns.go"
click node_evidence "https://github.com/sandstrompl/whyreach/blob/main/internal/evidence/view.go"
click node_rules "https://github.com/sandstrompl/whyreach/blob/main/internal/rules/wr007_localhost.go"
click node_reports "https://github.com/sandstrompl/whyreach/blob/main/internal/report/bundles.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_cli,node_mcp toneBlue
class node_policy,node_config,node_engine,node_target,node_dockerdaemon toneAmber
class node_docker,node_host,node_executor,node_probecontainer,node_probes toneMint
class node_evidence,node_rules,node_reports toneRose
class node_developer toneIndigo
```

## Components

### User interfaces

- [CLI commands](https://github.com/sandstrompl/whyreach/blob/main/internal/cli/cli.go): `internal/cli/cli.go`
- [MCP tools](https://github.com/sandstrompl/whyreach/blob/main/internal/mcpserver/server.go): `internal/mcpserver/server.go`

### Policy and orchestration

- [Safety policy](https://github.com/sandstrompl/whyreach/blob/main/internal/policy/policy.go): `internal/policy/policy.go`
- [Configuration](https://github.com/sandstrompl/whyreach/blob/main/internal/config/config.go): `internal/config/config.go`
- [Diagnosis engine](https://github.com/sandstrompl/whyreach/blob/main/internal/engine/engine.go): `internal/engine/engine.go`
- [Target parsing](https://github.com/sandstrompl/whyreach/blob/main/internal/target/target.go): `internal/target/target.go`

### Network evidence

- [Docker metadata](https://github.com/sandstrompl/whyreach/blob/main/internal/collect/docker/containers.go): `internal/collect/docker/containers.go`
- [Host network facts](https://github.com/sandstrompl/whyreach/blob/main/internal/collect/host/host.go): `internal/collect/host/host.go`
- [Probe executors](https://github.com/sandstrompl/whyreach/blob/main/internal/executor/executor.go): `internal/executor/executor.go`
- [Probe container](https://github.com/sandstrompl/whyreach/blob/main/internal/executor/probecontainer.go): `internal/executor/probecontainer.go`
- [DNS and TCP probes](https://github.com/sandstrompl/whyreach/blob/main/internal/probe/dns.go): `internal/probe/dns.go`

### Diagnosis and results

- [Evidence store and views](https://github.com/sandstrompl/whyreach/blob/main/internal/evidence/view.go): `internal/evidence/view.go`
- [Cause rules](https://github.com/sandstrompl/whyreach/blob/main/internal/rules/wr007_localhost.go): `internal/rules/wr007_localhost.go`
- [Report generation](https://github.com/sandstrompl/whyreach/blob/main/internal/report/bundles.go): `internal/report/bundles.go`

### Other components

- **Developer or agent**
- **Docker Engine**

## Connections

- Developer or agent → CLI commands: runs commands
- Developer or agent → MCP tools: calls tools
- CLI commands → Safety policy: submits requests (evidence: `internal/cli/cli.go`)
- MCP tools → Safety policy: routes tool calls (evidence: `internal/mcpserver/server.go`)
- Safety policy → Configuration: uses settings (evidence: `internal/policy/policy.go`)
- Safety policy → Target parsing: parses targets (evidence: `internal/policy/policy.go`)
- Safety policy → Diagnosis engine: runs diagnosis (evidence: `internal/policy/policy.go`)
- Diagnosis engine → Docker metadata: collects metadata
- Diagnosis engine → Host network facts: collects host facts
- Diagnosis engine → Probe executors: runs checks
- Probe executors → DNS and TCP probes: executes checks (evidence: `internal/executor/executor.go`)
- Probe executors → Probe container: delegates probing (evidence: `internal/executor/executor.go`)
- Probe container → Docker Engine: creates probe container (evidence: `internal/executor/probecontainer.go`)
- Diagnosis engine → Evidence store and views: records observations
- Diagnosis engine → Cause rules: evaluates findings (evidence: `internal/engine/engine.go`)
- Cause rules → Evidence store and views: reads evidence (evidence: `internal/rules/wr007_localhost.go`)
- CLI commands → Report generation: renders reports
- MCP tools → Report generation: saves reports (evidence: `internal/mcpserver/server.go`)
- Docker metadata → Docker Engine: reads metadata
