# torbenanderson/icebox-cli architecture

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

- Interactive diagram: https://gitdiagram.com/torbenanderson/icebox-cli
- Repository: https://github.com/torbenanderson/icebox-cli

## Overview

1. **What this repo is**
   - Icebox is a **single Rust CLI binary** (`src/main.rs`, `src/lib.rs`) for brokered secret handling.
   - Its architectural goal is to keep API keys/passwords **out of agent state**, store them encrypted on disk, and only unwrap them at execution time.

2. **Top-level runtime flow**
   - User command enters the CLI.
   - Parsing and command dispatch happen in the Rust application layer.
   - Commands then route into the appropriate subsystem: **config/agent management**, **vault storage**, **enclave-backed key handling**, or future **secure run** flows.

3. **Identity is the central domain model**
   - The `agent` and `config` modules model named agents and the active agent registry.
   - `register-agent` is the bootstrap path: it creates an agent identity, writes registry state, and initializes the per-agent storage directory.
   - Agent names are constrained and each agent gets an isolated namespace under `ICEBOX_HOME` / `~/.icebox`.

4. **Filesystem layout is an explicit boundary**
   - Persistent state is rooted under `~/.icebox` or `ICEBOX_HOME`.
   - The main artifacts are:
     - `config.json` for agent registry and active selection
     - `identities/<name>/identity.pub` for the public identity key
     - `identities/<name>/enclave.keyref` as a stable label for the wrapping key
     - `identities/<name>/key.enc` for wrapped private-key material
     - planned/related vault files such as `vault.enc`
   - This filesystem layout is part of the architecture, not just implementation detail.

5. **Secret storage and retrieval**
   - The `vault` module represents encrypted secret storage per agent.
   - The current MVP slice supports adding secrets; the broader design includes listing, removing, and running commands with injected credentials.
   - The vault is intended to store only encrypted values, with plaintext appearing only transiently during trusted execution.

6. **Secure Enclave is the hard security boundary**
   - The `enclave` and platform-specific DID backend files (`src/did/backend_darwin.rs`, `backend_stub.rs`) show that key wrapping is backend-driven.
   - On macOS, the Secure Enclave is the intended trust anchor for local key protection.
   - The README makes clear that this is the **MVP lane**; Linux is currently only for non-enclave development/test paths.

7. **Identity backend abstraction is deliberate**
   - The codebase is already structured around a split between **local-enclave** and future **paired-remote-signer** identity lanes.
   - `src/did.rs` and backend modules indicate the design is meant to support multiple identity/wrapping implementations behind one contract.
   - That means the diagram should show a stable identity interface with pluggable backend implementations underneath.

8. **Command execution is a planned trust boundary**
   - `runner` is the module for the future `run` path: decrypt secret, inject into a subprocess, capture results.
   - The README emphasizes that Icebox itself avoids persisting secrets in agent state, but the invoked subprocess is still a trust boundary and can exfiltrate via stdout, files, or network.
   - This is the main “broker” flow the project is aiming toward, even though it is not fully implemented yet.

9. **Contracts and schemas are part of the architecture**
   - `docs/architecture/contracts/*.schema.json` define the intended shapes for config, manifest, bundle manifest, and vault-related data.
   - These schemas act as a boundary between code, docs, and persisted artifacts.
   - The architecture diagram should treat them as validation contracts for on-disk and interchange formats.

10. **Documentation is unusually central**
   - `docs/architecture/` is effectively the system design source of truth: security model, identity/enclave model, vault integrity, platform strategy, and ADRs.
   - `docs/plan/` tracks roadmap/state, while `docs/reference/` holds error codes and versioning.
   - For architecture understanding, the repo is “docs-driven”: code implements a narrowly scoped MVP, but many critical boundaries are documented first.

11. **Quality and verification pipeline**
   - Tests are split into `integration`, `e2e`, `security`, and `system`, mirroring different architectural concerns.
   - The e2e tests map closely to product milestones such as keypair generation, enclave wrapping, no-plaintext-on-disk, duplicate guards, active-agent tracking, and vault creation.
   - CI workflows also enforce formatting, linting, docs, schema checks, security audit, and mutation testing.

12. **Current implementation status**
   - The repository is still **pre-MVP / alpha**.
   - Implemented: CLI scaffolding, identity bootstrap (`register-agent`), encrypted secret add flow, config/state handling, and supporting test coverage.
   - Planned: list/remove/run, multi-agent workflows, DID publishing, seed backup, and server/browser-extension phases.

13. **How to draw the diagram**
   - Put the **CLI binary** at the center.
   - Draw one boundary around **local filesystem state** (`ICEBOX_HOME`), one around **Secure Enclave / platform key wrapping**, and one around the **subprocess execution target**.
   - Show data moving from CLI → config/agent selection → enclave-backed key material → encrypted vault storage, with the future `run` path decrypting only at the point of execution.

Main entry points: [`src/lib.rs`](https://github.com/torbenanderson/icebox-cli/blob/main/src/lib.rs) (Core lib), [`src/did.rs`](https://github.com/torbenanderson/icebox-cli/blob/main/src/did.rs) (Identity API), [`src/vault.rs`](https://github.com/torbenanderson/icebox-cli/blob/main/src/vault.rs) (Vault), [`tests/e2e.rs`](https://github.com/torbenanderson/icebox-cli/blob/main/tests/e2e.rs) (E2E tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_cli(("CLI<br/>binary entry<br/>[main.rs]"))
  node_core["Core lib<br/>crate core<br/>[lib.rs]"]
  node_agent["Agent<br/>identity model<br/>[agent.rs]"]
  node_config["Config<br/>registry state<br/>[config.rs]"]
  node_vault[("Vault<br/>secret store<br/>[vault.rs]")]
  node_runner["Runner<br/>exec broker<br/>[runner.rs]"]
end

subgraph group_storage["Local State"]
  node_fsroot[("ICEBOX_HOME<br/>filesystem root")]
  node_identitydir["Identity files<br/>filesystem layout"]
  node_vaultfile["Vault file<br/>encrypted artifact"]
end

subgraph group_security["Security Boundary"]
  node_did["Identity API<br/>backend contract<br/>[did.rs]"]
  node_darwin["macOS backend<br/>enclave backend<br/>[backend_darwin.rs]"]
  node_stub["Stub backend<br/>test backend<br/>[backend_stub.rs]"]
  node_enclave{{"Enclave<br/>key boundary<br/>[enclave.rs]"}}
end

subgraph group_contracts["Contracts"]
  node_configschema["Config schema<br/>json schema<br/>[config.schema.json]"]
  node_vaultschema["Vault schema<br/>json schema<br/>[vault.schema.json]"]
end

subgraph group_docs["Architecture Docs"]
  node_overviewdoc["Overview<br/>[overview.md]"]
  node_securitydoc["Security model<br/>arch doc<br/>[security-model.md]"]
  node_identitydoc["Identity design<br/>arch doc"]
  node_layoutdoc["Data layout<br/>arch doc"]
end

subgraph group_verification["Verification"]
  node_e2e["E2E tests<br/>test suite<br/>[e2e.rs]"]
  node_ci["CI workflow<br/>pipeline<br/>[ci.yml]"]
end

node_cli -->|"dispatches"| node_core
node_core -->|"routes"| node_config
node_core -->|"models"| node_agent
node_core -->|"routes"| node_vault
node_core -->|"abstracts"| node_did
node_core -.->|"plans"| node_runner
node_config -->|"persists"| node_fsroot
node_agent -->|"namespaces"| node_identitydir
node_vault -->|"stores"| node_vaultfile
node_vault -->|"anchors"| node_fsroot
node_did -->|"implements"| node_darwin
node_did -->|"implements"| node_stub
node_did -->|"wraps via"| node_enclave
node_enclave -->|"writes"| node_identitydir
node_runner -.->|"reads"| node_vault
node_runner -.->|"unseals via"| node_did
node_configschema -->|"validates"| node_config
node_vaultschema -->|"validates"| node_vault
node_overviewdoc -->|"references"| node_securitydoc
node_overviewdoc -->|"references"| node_identitydoc
node_overviewdoc -->|"references"| node_layoutdoc
node_e2e -->|"verifies"| node_core
node_e2e -->|"verifies"| node_did
node_e2e -->|"verifies"| node_vault
node_ci -->|"runs"| node_e2e
node_ci -->|"checks"| node_configschema

click node_cli "https://github.com/torbenanderson/icebox-cli/blob/main/src/main.rs"
click node_core "https://github.com/torbenanderson/icebox-cli/blob/main/src/lib.rs"
click node_agent "https://github.com/torbenanderson/icebox-cli/blob/main/src/agent.rs"
click node_config "https://github.com/torbenanderson/icebox-cli/blob/main/src/config.rs"
click node_vault "https://github.com/torbenanderson/icebox-cli/blob/main/src/vault.rs"
click node_did "https://github.com/torbenanderson/icebox-cli/blob/main/src/did.rs"
click node_darwin "https://github.com/torbenanderson/icebox-cli/blob/main/src/did/backend_darwin.rs"
click node_stub "https://github.com/torbenanderson/icebox-cli/blob/main/src/did/backend_stub.rs"
click node_enclave "https://github.com/torbenanderson/icebox-cli/blob/main/src/enclave.rs"
click node_runner "https://github.com/torbenanderson/icebox-cli/blob/main/src/runner.rs"
click node_configschema "https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/contracts/config.schema.json"
click node_vaultschema "https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/contracts/vault.schema.json"
click node_overviewdoc "https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/overview.md"
click node_securitydoc "https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/security-model.md"
click node_identitydoc "https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/identity-and-enclave.md"
click node_layoutdoc "https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/data-models-and-layout.md"
click node_e2e "https://github.com/torbenanderson/icebox-cli/blob/main/tests/e2e.rs"
click node_ci "https://github.com/torbenanderson/icebox-cli/blob/main/.github/workflows/ci.yml"

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_core,node_agent,node_config,node_vault,node_runner toneBlue
class node_fsroot,node_identitydir,node_vaultfile toneAmber
class node_did,node_darwin,node_stub,node_enclave toneMint
class node_configschema,node_vaultschema toneRose
class node_overviewdoc,node_securitydoc,node_identitydoc,node_layoutdoc toneIndigo
class node_e2e,node_ci toneTeal
```

## Components

### Runtime

CLI entrypoint and core Rust modules

- [CLI](https://github.com/torbenanderson/icebox-cli/blob/main/src/main.rs): binary entry · Command-line entrypoint and dispatch surface · `src/main.rs`
- [Core lib](https://github.com/torbenanderson/icebox-cli/blob/main/src/lib.rs): crate core · Shared application layer for command routing and orchestration · `src/lib.rs`
- [Agent](https://github.com/torbenanderson/icebox-cli/blob/main/src/agent.rs): identity model · Named agent identity and active-registry domain · `src/agent.rs`
- [Config](https://github.com/torbenanderson/icebox-cli/blob/main/src/config.rs): registry state · Persistent agent registry and active selection handling · `src/config.rs`
- [Vault](https://github.com/torbenanderson/icebox-cli/blob/main/src/vault.rs): secret store · Encrypted per-agent secret storage and vault operations · `src/vault.rs`
- [Runner](https://github.com/torbenanderson/icebox-cli/blob/main/src/runner.rs): exec broker · Planned secret-unwrapping and subprocess execution path · `src/runner.rs`

### Local State

Persistent files under ICEBOX_HOME or ~/.icebox

- **ICEBOX_HOME**: filesystem root · Persistent on-disk state rooted at ~/.icebox or ICEBOX_HOME
- **Identity files**: filesystem layout · Per-agent identity namespace with public key and wrapped key material
- **Vault file**: encrypted artifact · Encrypted vault payload stored per agent

### Security Boundary

Identity wrapping and enclave-backed key handling

- [Identity API](https://github.com/torbenanderson/icebox-cli/blob/main/src/did.rs): backend contract · Stable interface for identity and key-wrapping implementations · `src/did.rs`
- [macOS backend](https://github.com/torbenanderson/icebox-cli/blob/main/src/did/backend_darwin.rs): enclave backend · Secure Enclave-backed implementation for Darwin · `src/did/backend_darwin.rs`
- [Stub backend](https://github.com/torbenanderson/icebox-cli/blob/main/src/did/backend_stub.rs): test backend · Non-enclave development and fallback implementation · `src/did/backend_stub.rs`
- [Enclave](https://github.com/torbenanderson/icebox-cli/blob/main/src/enclave.rs): key boundary · Local trust anchor for wrapping private key material · `src/enclave.rs`

### Contracts

Schema-defined persisted and interchange formats

- [Config schema](https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/contracts/config.schema.json): json schema · Contract for registry and active-agent state · `docs/architecture/contracts/config.schema.json`
- [Vault schema](https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/contracts/vault.schema.json): json schema · Contract for encrypted vault data shape · `docs/architecture/contracts/vault.schema.json`

### Architecture Docs

Design source of truth and ADRs

- [Overview](https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/overview.md): arch overview · High-level repository and system architecture narrative · `docs/architecture/overview.md`
- [Security model](https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/security-model.md): arch doc · Threat model, trust boundaries, and security assumptions · `docs/architecture/security-model.md`
- [Identity design](https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/identity-and-enclave.md): arch doc · Identity, enclave, and backend split documentation · `docs/architecture/identity-and-enclave.md`
- [Data layout](https://github.com/torbenanderson/icebox-cli/blob/main/docs/architecture/data-models-and-layout.md): arch doc · Filesystem layout and persistent artifact structure · `docs/architecture/data-models-and-layout.md`

### Verification

Tests and CI checks that enforce the design

- [E2E tests](https://github.com/torbenanderson/icebox-cli/blob/main/tests/e2e.rs): test suite · End-to-end coverage for bootstrap, enclave wrapping, and vault behavior · `tests/e2e.rs`
- [CI workflow](https://github.com/torbenanderson/icebox-cli/blob/main/.github/workflows/ci.yml): pipeline · Automated formatting, linting, docs, schema, security, and mutation checks · `.github/workflows/ci.yml`

## Connections

- CLI → Core lib: dispatches · CLI parses commands and hands off into the application layer
- Core lib → Config: routes · Command handling reaches registry and active-agent state
- Core lib → Agent: models · Core logic works with named agent identities
- Core lib → Vault: routes · Secret add and future vault operations flow through the vault module
- Core lib → Identity API: abstracts · Core relies on a stable identity/wrapping contract
- Core lib → Runner: plans · Future run path will broker secret injection at execution time
- Config → ICEBOX_HOME: persists · Registry state is stored under the local Icebox home directory
- Agent → Identity files: namespaces · Each agent gets an isolated filesystem namespace
- Vault → Vault file: stores · Vault data is kept as encrypted on-disk artifacts
- Vault → ICEBOX_HOME: anchors · Vault storage is rooted in the local state directory
- Identity API → macOS backend: implements · Darwin backend provides the enclave-backed implementation
- Identity API → Stub backend: implements · Stub backend supports non-enclave development and tests
- Identity API → Enclave: wraps via · Identity contract delegates key wrapping to the enclave boundary
- Enclave → Identity files: writes · Wrapped key material and identity artifacts live in per-agent storage
- Runner → Vault: reads · Execution flow will decrypt or load secrets from the vault transiently
- Runner → Identity API: unseals via · Runner depends on the identity contract to recover secrets at execution time
- Config schema → Config: validates · Schema defines the registry state shape
- Vault schema → Vault: validates · Schema defines the vault data contract
- Overview → Security model: references · Architecture overview is supported by the security model
- Overview → Identity design: references · Overview points to identity and enclave design
- Overview → Data layout: references · Overview points to the explicit filesystem layout
- E2E tests → Core lib: verifies · E2E tests cover CLI flows and state transitions
- E2E tests → Identity API: verifies · E2E tests cover backend wrapping behavior
- E2E tests → Vault: verifies · E2E tests cover vault creation and sealed storage
- CI workflow → E2E tests: runs · CI enforces the test suite and surrounding quality gates
- CI workflow → Config schema: checks · CI validates docs and schema contracts
