# ghostsecurity/reaper architecture

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

- Interactive diagram: https://gitdiagram.com/ghostsecurity/reaper
- Repository: https://github.com/ghostsecurity/reaper

## Overview

#### Purpose and entry point
Reaper is a Go-based local HTTPS MITM proxy for application-security testing. It captures in-scope HTTP(S) traffic, persists requests/responses locally, and exposes CLI commands for proxy lifecycle and traffic inspection. The executable starts at `cmd/reaper/main.go`; version metadata is in `version/version.go`.

#### CLI control plane
The CLI is organized as command handlers under `internal/cli/`, with a root command coordinating subcommands. Lifecycle commands start, stop, and communicate with the background proxy process; query commands retrieve, search, format, tail, clear, and inspect stored traffic.
- `internal/cli/root.go`
- `internal/cli/start.go`
- `internal/cli/get.go`
- `internal/cli/search.go`
- `internal/cli/logs.go`

Platform-specific startup behavior is separated between `internal/cli/start_unix.go` and `internal/cli/start_windows.go`.

#### Daemon boundary
A local daemon separates short-lived CLI invocations from the long-running interception service. CLI-side connection logic and daemon-side serving communicate through an explicit protocol layer, allowing commands such as status, shutdown, and traffic queries to target the running process rather than directly owning proxy execution.
- `internal/daemon/client.go`
- `internal/daemon/server.go`
- `internal/daemon/protocol.go`
- `internal/daemon/daemon.go`

#### Interception and TLS handling
The proxy subsystem is the traffic-plane boundary between target applications and remote services. It handles proxying, certificate generation/management for HTTPS interception, and scope filtering so only configured in-scope traffic is captured.
- `internal/proxy/proxy.go`
- `internal/proxy/cert.go`
- `internal/proxy/scope.go`

Control flow is: client application → local MITM proxy → scope decision → upstream destination; eligible request/response exchanges are emitted for storage.

#### Persistence and query model
Captured traffic is represented by storage models and written to a local SQLite-backed store. This forms the durable boundary between live interception and later CLI inspection, enabling search and request/response retrieval after capture.
- `internal/storage/models.go`
- `internal/storage/store.go`
- `internal/storage/sqlite.go`

The main data flow is proxy capture → storage abstraction → SQLite database → daemon protocol → CLI rendering/output.

#### Runtime and distribution
The runtime is a compiled Go binary, primarily documented for Linux and macOS. Installation can use the repository script, while release packaging is driven by GoReleaser. GitHub Actions validates Go tests/linting and publishes releases.
- `scripts/install.sh`
- `.goreleaser.yaml`
- `.github/workflows/release.yml`
- `go.mod`

Main entry points: [`internal/cli/root.go`](https://github.com/ghostsecurity/reaper/blob/main/internal/cli/root.go) (Root command), [`internal/proxy/proxy.go`](https://github.com/ghostsecurity/reaper/blob/main/internal/proxy/proxy.go) (MITM proxy), [`internal/daemon/client.go`](https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/client.go) (Daemon client), [`cmd/reaper/main.go`](https://github.com/ghostsecurity/reaper/blob/main/cmd/reaper/main.go) (Reaper binary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI Control Plane"]
  node_root_cli["Root command<br/>CLI router<br/>[root.go]"]
  node_lifecycle_cli["Start lifecycle<br/>CLI command<br/>[start.go]"]
  node_query_cli["Traffic queries<br/>CLI commands<br/>[get.go]"]
  node_search_cli["Traffic search<br/>CLI command<br/>[search.go]"]
  node_logs_cli["Log output<br/>CLI command<br/>[logs.go]"]
  node_platform_startup["Platform startup<br/>OS launcher<br/>[start_unix.go]"]
end

subgraph group_daemon["Local Daemon"]
  node_daemon_client["Daemon client<br/>protocol client<br/>[client.go]"]
  node_daemon_server["Daemon server<br/>protocol server<br/>[server.go]"]
  node_protocol["Daemon protocol<br/>local protocol<br/>[protocol.go]"]
  node_daemon_runtime["Daemon runtime<br/>service lifecycle<br/>[daemon.go]"]
end

subgraph group_proxy["Traffic Plane"]
  node_mitm_proxy["MITM proxy<br/>HTTPS proxy<br/>[proxy.go]"]
  node_tls_certs["TLS certificates<br/>certificate manager<br/>[cert.go]"]
  node_scope_filter["Scope filter<br/>traffic policy<br/>[scope.go]"]
end

subgraph group_storage["Traffic Storage"]
  node_traffic_models["Traffic models<br/>storage models<br/>[models.go]"]
  node_store["Storage abstraction<br/>traffic repository<br/>[store.go]"]
  node_sqlite[("Local SQLite<br/>database<br/>[sqlite.go]")]
end

subgraph group_delivery["Build &amp; Distribution"]
  node_install["Install script<br/>installer<br/>[install.sh]"]
  node_release["Release packaging<br/>GoReleaser<br/>[.goreleaser.yaml]"]
  node_release_ci["Release workflow<br/>GitHub Actions<br/>[release.yml]"]
  node_go_module["Go module<br/>build manifest<br/>[go.mod]"]
end

node_binary{{"Reaper binary<br/>Go executable<br/>[main.go]"}}
node_version["Version metadata<br/>[version.go]"]
node_client_app(("Client application<br/>proxy client"))
node_upstream(("Upstream destination<br/>remote service"))

node_binary -->|"starts"| node_root_cli
node_version -.->|"versions"| node_binary
node_root_cli -->|"routes"| node_lifecycle_cli
node_root_cli -->|"routes"| node_query_cli
node_root_cli -->|"routes"| node_search_cli
node_root_cli -->|"routes"| node_logs_cli
node_lifecycle_cli -->|"launches via"| node_platform_startup
node_lifecycle_cli -->|"controls"| node_daemon_client
node_query_cli -->|"queries"| node_daemon_client
node_search_cli -->|"searches"| node_daemon_client
node_logs_cli -->|"reads"| node_daemon_client
node_daemon_client -->|"uses"| node_protocol
node_protocol -->|"serves"| node_daemon_server
node_daemon_server -->|"controls"| node_daemon_runtime
node_daemon_runtime -->|"runs"| node_mitm_proxy
node_client_app -->|"proxies through"| node_mitm_proxy
node_mitm_proxy -->|"uses"| node_tls_certs
node_mitm_proxy -->|"evaluates"| node_scope_filter
node_mitm_proxy -->|"forwards to"| node_upstream
node_scope_filter -->|"eligible exchanges"| node_traffic_models
node_traffic_models -->|"persists through"| node_store
node_daemon_server -->|"retrieves traffic"| node_store
node_store -->|"stores in"| node_sqlite
node_go_module -.->|"builds"| node_binary
node_install -.->|"installs"| node_binary
node_release_ci -->|"publishes with"| node_release
node_release -->|"packages"| node_binary

click node_binary "https://github.com/ghostsecurity/reaper/blob/main/cmd/reaper/main.go"
click node_version "https://github.com/ghostsecurity/reaper/blob/main/version/version.go"
click node_root_cli "https://github.com/ghostsecurity/reaper/blob/main/internal/cli/root.go"
click node_lifecycle_cli "https://github.com/ghostsecurity/reaper/blob/main/internal/cli/start.go"
click node_query_cli "https://github.com/ghostsecurity/reaper/blob/main/internal/cli/get.go"
click node_search_cli "https://github.com/ghostsecurity/reaper/blob/main/internal/cli/search.go"
click node_logs_cli "https://github.com/ghostsecurity/reaper/blob/main/internal/cli/logs.go"
click node_platform_startup "https://github.com/ghostsecurity/reaper/blob/main/internal/cli/start_unix.go"
click node_daemon_client "https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/client.go"
click node_daemon_server "https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/server.go"
click node_protocol "https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/protocol.go"
click node_daemon_runtime "https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/daemon.go"
click node_mitm_proxy "https://github.com/ghostsecurity/reaper/blob/main/internal/proxy/proxy.go"
click node_tls_certs "https://github.com/ghostsecurity/reaper/blob/main/internal/proxy/cert.go"
click node_scope_filter "https://github.com/ghostsecurity/reaper/blob/main/internal/proxy/scope.go"
click node_traffic_models "https://github.com/ghostsecurity/reaper/blob/main/internal/storage/models.go"
click node_store "https://github.com/ghostsecurity/reaper/blob/main/internal/storage/store.go"
click node_sqlite "https://github.com/ghostsecurity/reaper/blob/main/internal/storage/sqlite.go"
click node_install "https://github.com/ghostsecurity/reaper/blob/main/scripts/install.sh"
click node_release "https://github.com/ghostsecurity/reaper/blob/main/.goreleaser.yaml"
click node_release_ci "https://github.com/ghostsecurity/reaper/blob/main/.github/workflows/release.yml"
click node_go_module "https://github.com/ghostsecurity/reaper/blob/main/go.mod"

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_root_cli,node_lifecycle_cli,node_query_cli,node_search_cli,node_logs_cli,node_platform_startup toneBlue
class node_daemon_client,node_daemon_server,node_protocol,node_daemon_runtime toneAmber
class node_mitm_proxy,node_tls_certs,node_scope_filter toneMint
class node_traffic_models,node_store,node_sqlite toneRose
class node_install,node_release,node_release_ci,node_go_module toneIndigo
class node_binary,node_version,node_client_app,node_upstream toneNeutral
```

## Components

### CLI Control Plane

- [Root command](https://github.com/ghostsecurity/reaper/blob/main/internal/cli/root.go): CLI router · `internal/cli/root.go`
- [Start lifecycle](https://github.com/ghostsecurity/reaper/blob/main/internal/cli/start.go): CLI command · Starts, stops, and manages the background service. · `internal/cli/start.go`
- [Traffic queries](https://github.com/ghostsecurity/reaper/blob/main/internal/cli/get.go): CLI commands · Gets, searches, formats, tails, and inspects captured traffic. · `internal/cli/get.go`
- [Traffic search](https://github.com/ghostsecurity/reaper/blob/main/internal/cli/search.go): CLI command · `internal/cli/search.go`
- [Log output](https://github.com/ghostsecurity/reaper/blob/main/internal/cli/logs.go): CLI command · `internal/cli/logs.go`
- [Platform startup](https://github.com/ghostsecurity/reaper/blob/main/internal/cli/start_unix.go): OS launcher · Uses Unix- or Windows-specific daemon startup behavior. · `internal/cli/start_unix.go`

### Local Daemon

Separates CLI invocations from the long-running proxy.

- [Daemon client](https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/client.go): protocol client · `internal/daemon/client.go`
- [Daemon server](https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/server.go): protocol server · Serves lifecycle and traffic-query requests from CLI processes. · `internal/daemon/server.go`
- [Daemon protocol](https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/protocol.go): local protocol · Defines status, shutdown, and traffic-query messages. · `internal/daemon/protocol.go`
- [Daemon runtime](https://github.com/ghostsecurity/reaper/blob/main/internal/daemon/daemon.go): service lifecycle · `internal/daemon/daemon.go`

### Traffic Plane

- [MITM proxy](https://github.com/ghostsecurity/reaper/blob/main/internal/proxy/proxy.go): HTTPS proxy · Intercepts in-scope HTTP(S) exchanges. · `internal/proxy/proxy.go`
- [TLS certificates](https://github.com/ghostsecurity/reaper/blob/main/internal/proxy/cert.go): certificate manager · `internal/proxy/cert.go`
- [Scope filter](https://github.com/ghostsecurity/reaper/blob/main/internal/proxy/scope.go): traffic policy · Determines whether an exchange is eligible for capture. · `internal/proxy/scope.go`

### Traffic Storage

- [Traffic models](https://github.com/ghostsecurity/reaper/blob/main/internal/storage/models.go): storage models · `internal/storage/models.go`
- [Storage abstraction](https://github.com/ghostsecurity/reaper/blob/main/internal/storage/store.go): traffic repository · `internal/storage/store.go`
- [Local SQLite](https://github.com/ghostsecurity/reaper/blob/main/internal/storage/sqlite.go): database · Durable captured request and response store. · `internal/storage/sqlite.go`

### Build & Distribution

- [Install script](https://github.com/ghostsecurity/reaper/blob/main/scripts/install.sh): installer · `scripts/install.sh`
- [Release packaging](https://github.com/ghostsecurity/reaper/blob/main/.goreleaser.yaml): GoReleaser · `.goreleaser.yaml`
- [Release workflow](https://github.com/ghostsecurity/reaper/blob/main/.github/workflows/release.yml): GitHub Actions · `.github/workflows/release.yml`
- [Go module](https://github.com/ghostsecurity/reaper/blob/main/go.mod): build manifest · `go.mod`

### Other components

- [Reaper binary](https://github.com/ghostsecurity/reaper/blob/main/cmd/reaper/main.go): Go executable · `cmd/reaper/main.go`
- [Version metadata](https://github.com/ghostsecurity/reaper/blob/main/version/version.go): version · `version/version.go`
- **Client application**: proxy client
- **Upstream destination**: remote service

## Connections

- Reaper binary → Root command: starts
- Version metadata → Reaper binary: versions
- Root command → Start lifecycle: routes
- Root command → Traffic queries: routes
- Root command → Traffic search: routes
- Root command → Log output: routes
- Start lifecycle → Platform startup: launches via
- Start lifecycle → Daemon client: controls
- Traffic queries → Daemon client: queries
- Traffic search → Daemon client: searches
- Log output → Daemon client: reads
- Daemon client → Daemon protocol: uses
- Daemon protocol → Daemon server: serves
- Daemon server → Daemon runtime: controls
- Daemon runtime → MITM proxy: runs
- Client application → MITM proxy: proxies through
- MITM proxy → TLS certificates: uses
- MITM proxy → Scope filter: evaluates
- MITM proxy → Upstream destination: forwards to
- Scope filter → Traffic models: eligible exchanges
- Traffic models → Storage abstraction: persists through
- Daemon server → Storage abstraction: retrieves traffic
- Storage abstraction → Local SQLite: stores in
- Go module → Reaper binary: builds
- Install script → Reaper binary: installs
- Release workflow → Release packaging: publishes with
- Release packaging → Reaper binary: packages
