# krakenfx/kraken-cli architecture

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

- Interactive diagram: https://gitdiagram.com/krakenfx/kraken-cli
- Repository: https://github.com/krakenfx/kraken-cli

## Overview

Kraken CLI exposes Kraken market data, account, trading, and research workflows through one command interface, with JSON or table output and an MCP server that reuses CLI dispatch. A typical workflow is an agent or user invoking a command, the CLI resolving configuration and credentials, a domain command performing the operation, and output being rendered. The README documents paper trading, recording/replay, sessions, workspaces, and the research lab as additional capabilities. Several of those paths are supported by the tree and documentation, but their internal runtime links are not shown in the excerpts.

Main entry points: [`src/commands/mod.rs`](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/mod.rs) (Command dispatch), [`src/cli.rs`](https://github.com/krakenfx/kraken-cli/blob/main/src/cli.rs) (CLI parser), [`src/commands/futures.rs`](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/futures.rs) (Spot and futures), [`src/client.rs`](https://github.com/krakenfx/kraken-cli/blob/main/src/client.rs) (HTTP clients)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry surfaces"]
  node_cli["CLI parser<br/>[cli.rs]"]
  node_mcp["MCP server<br/>[server.rs]"]
  node_commands["Command dispatch<br/>[mod.rs]"]
  node_mcp_registry["Tool registry<br/>[registry.rs]"]
end

subgraph group_runtime["Runtime foundation"]
  node_config["Configuration<br/>[config.rs]"]
  node_auth["Authentication<br/>[auth.rs]"]
  node_errors["Error taxonomy<br/>[errors.rs]"]
end

subgraph group_exchange["Exchange operations"]
  node_http["HTTP clients<br/>[client.rs]"]
  node_ws["WebSocket clients<br/>[connection.rs]"]
  node_core["API types<br/>[lib.rs]"]
  node_market["Market commands<br/>[market.rs]"]
  node_trade["Spot and futures<br/>[futures.rs]"]
end

subgraph group_research["Trading research"]
  node_paper["Paper trading<br/>[paper.rs]"]
  node_paper_account["Paper account<br/>[account.rs]"]
  node_record["Market recording<br/>[record.rs]"]
  node_tape[("Tape storage<br/>[mod.rs]")]
  node_replay["Replay playback<br/>[playback.rs]"]
  node_lab["Autoresearch lab<br/>[app.rs]"]
end

subgraph group_presentation["State and output"]
  node_session["Trading sessions<br/>[session.rs]"]
  node_workspace["Workspaces<br/>[app.rs]"]
  node_output["Output rendering<br/>[mod.rs]"]
end

node_user(("User or agent"))

node_user -->|"invokes"| node_cli
node_cli -->|"dispatches"| node_commands
node_mcp -->|"re-enters dispatch"| node_commands
node_mcp -->|"uses tools"| node_mcp_registry
node_cli -->|"resolves context"| node_config
node_cli -->|"renders results"| node_output
node_commands -->|"routes"| node_market
node_commands -->|"routes"| node_trade
node_commands -->|"routes"| node_paper
node_commands -->|"routes"| node_record
node_commands -->|"routes"| node_session
node_market -.->|"requests data"| node_http
node_trade -.->|"sends requests"| node_http
node_trade -.->|"uses WebSockets"| node_ws
node_ws -->|"uses protocol types"| node_core
node_record -.->|"records streams"| node_tape
node_replay -.->|"reads tapes"| node_tape
node_paper -.->|"runs paper trades"| node_paper_account
node_lab -.->|"researches recordings"| node_tape
node_session -.->|"scopes sessions"| node_workspace
node_commands -->|"produces command output"| node_output
node_config -.->|"resolves credentials"| node_auth
node_http -->|"normalizes failures"| node_errors

click node_cli "https://github.com/krakenfx/kraken-cli/blob/main/src/cli.rs"
click node_mcp "https://github.com/krakenfx/kraken-cli/blob/main/src/mcp/server.rs"
click node_commands "https://github.com/krakenfx/kraken-cli/blob/main/src/commands/mod.rs"
click node_config "https://github.com/krakenfx/kraken-cli/blob/main/src/config.rs"
click node_auth "https://github.com/krakenfx/kraken-cli/blob/main/src/auth.rs"
click node_errors "https://github.com/krakenfx/kraken-cli/blob/main/src/errors.rs"
click node_http "https://github.com/krakenfx/kraken-cli/blob/main/src/client.rs"
click node_ws "https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-ws/src/connection.rs"
click node_core "https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-core/src/lib.rs"
click node_market "https://github.com/krakenfx/kraken-cli/blob/main/src/commands/market.rs"
click node_trade "https://github.com/krakenfx/kraken-cli/blob/main/src/commands/futures.rs"
click node_paper "https://github.com/krakenfx/kraken-cli/blob/main/src/commands/paper.rs"
click node_paper_account "https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-paper/src/account.rs"
click node_record "https://github.com/krakenfx/kraken-cli/blob/main/src/commands/record.rs"
click node_tape "https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-recording/src/frames/mod.rs"
click node_replay "https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-replay/src/playback.rs"
click node_lab "https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-lab/src/app.rs"
click node_session "https://github.com/krakenfx/kraken-cli/blob/main/src/commands/session.rs"
click node_workspace "https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-workspace/src/app.rs"
click node_output "https://github.com/krakenfx/kraken-cli/blob/main/src/output/mod.rs"
click node_mcp_registry "https://github.com/krakenfx/kraken-cli/blob/main/src/mcp/registry.rs"

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,node_commands,node_mcp_registry,node_user toneBlue
class node_config,node_auth,node_errors toneAmber
class node_http,node_ws,node_core,node_market,node_trade toneMint
class node_paper,node_paper_account,node_record,node_tape,node_replay,node_lab toneRose
class node_session,node_workspace,node_output toneIndigo
```

## Components

### Entry surfaces

- [CLI parser](https://github.com/krakenfx/kraken-cli/blob/main/src/cli.rs): `src/cli.rs`
- [MCP server](https://github.com/krakenfx/kraken-cli/blob/main/src/mcp/server.rs): `src/mcp/server.rs`
- [Command dispatch](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/mod.rs): `src/commands/mod.rs`
- [Tool registry](https://github.com/krakenfx/kraken-cli/blob/main/src/mcp/registry.rs): `src/mcp/registry.rs`

### Runtime foundation

- [Configuration](https://github.com/krakenfx/kraken-cli/blob/main/src/config.rs): `src/config.rs`
- [Authentication](https://github.com/krakenfx/kraken-cli/blob/main/src/auth.rs): `src/auth.rs`
- [Error taxonomy](https://github.com/krakenfx/kraken-cli/blob/main/src/errors.rs): `src/errors.rs`

### Exchange operations

- [HTTP clients](https://github.com/krakenfx/kraken-cli/blob/main/src/client.rs): `src/client.rs`
- [WebSocket clients](https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-ws/src/connection.rs): `crates/kraken-ws/src/connection.rs`
- [API types](https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-core/src/lib.rs): `crates/kraken-core/src/lib.rs`
- [Market commands](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/market.rs): `src/commands/market.rs`
- [Spot and futures](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/futures.rs): `src/commands/futures.rs`

### Trading research

- [Paper trading](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/paper.rs): `src/commands/paper.rs`
- [Paper account](https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-paper/src/account.rs): `crates/kraken-paper/src/account.rs`
- [Market recording](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/record.rs): `src/commands/record.rs`
- [Tape storage](https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-recording/src/frames/mod.rs): `crates/kraken-recording/src/frames/mod.rs`
- [Replay playback](https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-replay/src/playback.rs): `crates/kraken-replay/src/playback.rs`
- [Autoresearch lab](https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-lab/src/app.rs): `crates/kraken-lab/src/app.rs`

### State and output

- [Trading sessions](https://github.com/krakenfx/kraken-cli/blob/main/src/commands/session.rs): `src/commands/session.rs`
- [Workspaces](https://github.com/krakenfx/kraken-cli/blob/main/crates/kraken-workspace/src/app.rs): `crates/kraken-workspace/src/app.rs`
- [Output rendering](https://github.com/krakenfx/kraken-cli/blob/main/src/output/mod.rs): `src/output/mod.rs`

### Other components

- **User or agent**

## Connections

- User or agent → CLI parser: invokes (evidence: `README.md`)
- CLI parser → Command dispatch: dispatches (evidence: `src/commands/mod.rs`)
- MCP server → Command dispatch: re-enters dispatch (evidence: `src/mcp/server.rs`)
- MCP server → Tool registry: uses tools (evidence: `src/mcp/server.rs`)
- CLI parser → Configuration: resolves context (evidence: `src/cli.rs`)
- CLI parser → Output rendering: renders results (evidence: `src/cli.rs`)
- Command dispatch → Market commands: routes (evidence: `src/commands/mod.rs`)
- Command dispatch → Spot and futures: routes (evidence: `src/commands/mod.rs`)
- Command dispatch → Paper trading: routes (evidence: `src/commands/mod.rs`)
- Command dispatch → Market recording: routes (evidence: `src/commands/mod.rs`)
- Command dispatch → Trading sessions: routes (evidence: `src/commands/mod.rs`)
- Market commands → HTTP clients: requests data
- Spot and futures → HTTP clients: sends requests
- Spot and futures → WebSocket clients: uses WebSockets
- WebSocket clients → API types: uses protocol types
- Market recording → Tape storage: records streams
- Replay playback → Tape storage: reads tapes
- Paper trading → Paper account: runs paper trades
- Autoresearch lab → Tape storage: researches recordings
- Trading sessions → Workspaces: scopes sessions
- Command dispatch → Output rendering: produces command output (evidence: `src/output/mod.rs`)
- Configuration → Authentication: resolves credentials
- HTTP clients → Error taxonomy: normalizes failures (evidence: `src/client.rs`)
