# marketcalls/openalgo-cli architecture

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

- Interactive diagram: https://gitdiagram.com/marketcalls/openalgo-cli
- Repository: https://github.com/marketcalls/openalgo-cli

## Overview

OpenAlgo CLI is a process-oriented client for a user’s self-hosted trading API. The main workflow is command-line input → Cobra command dispatch → generated operation client → authenticated HTTP request to the OpenAlgo server → JSON/CSV output. The README also documents WebSocket monitoring, profile management, strategy operations, option tools, and agent-oriented discovery and dry-run behavior. The graph reflects documented capabilities where their implementation was not sampled; those links are omitted when source wiring is uncertain.

Main entry points: [`internal/cmd/commands.gen.go`](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go) (Command handlers), [`internal/cmd/root.go`](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/root.go) (Command root), [`internal/client/client.go`](https://github.com/marketcalls/openalgo-cli/blob/main/internal/client/client.go) (HTTP transport), [`internal/output/output.go`](https://github.com/marketcalls/openalgo-cli/blob/main/internal/output/output.go) (JSON and CSV output)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI workflow"]
  node_entry["Executable entry<br/>[main.go]"]
  node_root["Command root<br/>[root.go]"]
  node_handlers["Command handlers<br/>[commands.gen.go]"]
  node_discovery["Help and schema<br/>[help_all.go]"]
end

subgraph group_trading["Trading operations"]
  node_orders["Order operations<br/>[commands.gen.go]"]
  node_account["Account and positions<br/>[commands.gen.go]"]
  node_market["Market and options<br/>[commands.gen.go]"]
  node_strategies["Strategy operations<br/>[commands.gen.go]"]
  node_notifications["Notifications<br/>[commands.gen.go]"]
  node_streamcmd["Stream commands<br/>[stream.go]"]
end

subgraph group_connectivity["API connectivity"]
  node_stream["WebSocket streaming<br/>[stream.go]"]
  node_api["Generated API client"]
  node_transport["HTTP transport<br/>[client.go]"]
end

subgraph group_support["Profiles and output"]
  node_profiles["Profile management<br/>[profile.go]"]
  node_config["Configuration resolution<br/>[config.go]"]
  node_doctor["Connectivity diagnostics<br/>[doctor.go]"]
  node_output["JSON and CSV output<br/>[output.go]"]
  node_jq["Result filtering<br/>[jq.go]"]
end

node_user(("User or agent"))
node_server["OpenAlgo server"]
node_terminal(("Terminal or pipeline"))

node_user -->|"runs CLI"| node_entry
node_entry -->|"executes"| node_root
node_root -->|"dispatches"| node_handlers
node_root -->|"offers discovery"| node_discovery
node_handlers -->|"routes order commands"| node_orders
node_handlers -->|"routes account commands"| node_account
node_handlers -->|"routes market commands"| node_market
node_handlers -->|"routes strategy commands"| node_strategies
node_handlers -->|"routes notification commands"| node_notifications
node_handlers -->|"invokes operations"| node_api
node_streamcmd -->|"starts stream"| node_stream
node_stream -->|"subscribes over WebSocket"| node_server
node_profiles -->|"stores and resolves"| node_config
node_root -->|"loads settings"| node_config
node_doctor -->|"checks connectivity"| node_transport
node_api -->|"sends API calls"| node_transport
node_transport -->|"requests HTTP API"| node_server
node_server -->|"returns response"| node_transport
node_handlers -->|"renders results"| node_output
node_output -.->|"filters when requested"| node_jq
node_output -->|"writes data"| node_terminal
node_streamcmd -->|"emits NDJSON"| node_terminal

click node_entry "https://github.com/marketcalls/openalgo-cli/blob/main/cmd/openalgo/main.go"
click node_root "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/root.go"
click node_handlers "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go"
click node_discovery "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/help_all.go"
click node_orders "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go"
click node_account "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go"
click node_market "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go"
click node_strategies "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go"
click node_notifications "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go"
click node_streamcmd "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/stream.go"
click node_stream "https://github.com/marketcalls/openalgo-cli/blob/main/internal/stream/stream.go"
click node_api "https://github.com/marketcalls/openalgo-cli/blob/main/internal/api/openalgo_client.gen.go"
click node_transport "https://github.com/marketcalls/openalgo-cli/blob/main/internal/client/client.go"
click node_profiles "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/profile.go"
click node_config "https://github.com/marketcalls/openalgo-cli/blob/main/internal/config/config.go"
click node_doctor "https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/doctor.go"
click node_output "https://github.com/marketcalls/openalgo-cli/blob/main/internal/output/output.go"
click node_jq "https://github.com/marketcalls/openalgo-cli/blob/main/internal/output/jq.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_entry,node_root,node_handlers,node_discovery,node_user toneBlue
class node_orders,node_account,node_market,node_strategies,node_notifications,node_streamcmd toneAmber
class node_stream,node_api,node_transport,node_server toneMint
class node_profiles,node_config,node_doctor,node_output,node_jq toneRose
class node_terminal toneIndigo
```

## Components

### CLI workflow

- [Executable entry](https://github.com/marketcalls/openalgo-cli/blob/main/cmd/openalgo/main.go): `cmd/openalgo/main.go`
- [Command root](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/root.go): `internal/cmd/root.go`
- [Command handlers](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go): `internal/cmd/commands.gen.go`
- [Help and schema](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/help_all.go): `internal/cmd/help_all.go`

### Trading operations

- [Order operations](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go): `internal/cmd/commands.gen.go`
- [Account and positions](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go): `internal/cmd/commands.gen.go`
- [Market and options](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go): `internal/cmd/commands.gen.go`
- [Strategy operations](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go): `internal/cmd/commands.gen.go`
- [Notifications](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/commands.gen.go): `internal/cmd/commands.gen.go`
- [Stream commands](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/stream.go): `internal/cmd/stream.go`

### API connectivity

- [WebSocket streaming](https://github.com/marketcalls/openalgo-cli/blob/main/internal/stream/stream.go): `internal/stream/stream.go`
- [Generated API client](https://github.com/marketcalls/openalgo-cli/blob/main/internal/api/openalgo_client.gen.go): `internal/api/openalgo_client.gen.go`
- [HTTP transport](https://github.com/marketcalls/openalgo-cli/blob/main/internal/client/client.go): `internal/client/client.go`

### Profiles and output

- [Profile management](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/profile.go): `internal/cmd/profile.go`
- [Configuration resolution](https://github.com/marketcalls/openalgo-cli/blob/main/internal/config/config.go): `internal/config/config.go`
- [Connectivity diagnostics](https://github.com/marketcalls/openalgo-cli/blob/main/internal/cmd/doctor.go): `internal/cmd/doctor.go`
- [JSON and CSV output](https://github.com/marketcalls/openalgo-cli/blob/main/internal/output/output.go): `internal/output/output.go`
- [Result filtering](https://github.com/marketcalls/openalgo-cli/blob/main/internal/output/jq.go): `internal/output/jq.go`

### Other components

- **User or agent**
- **OpenAlgo server**
- **Terminal or pipeline**

## Connections

- User or agent → Executable entry: runs CLI
- Executable entry → Command root: executes
- Command root → Command handlers: dispatches
- Command root → Help and schema: offers discovery
- Command handlers → Order operations: routes order commands
- Command handlers → Account and positions: routes account commands
- Command handlers → Market and options: routes market commands
- Command handlers → Strategy operations: routes strategy commands
- Command handlers → Notifications: routes notification commands
- Command handlers → Generated API client: invokes operations
- Stream commands → WebSocket streaming: starts stream
- WebSocket streaming → OpenAlgo server: subscribes over WebSocket
- Profile management → Configuration resolution: stores and resolves
- Command root → Configuration resolution: loads settings
- Connectivity diagnostics → HTTP transport: checks connectivity
- Generated API client → HTTP transport: sends API calls
- HTTP transport → OpenAlgo server: requests HTTP API
- OpenAlgo server → HTTP transport: returns response
- Command handlers → JSON and CSV output: renders results
- JSON and CSV output → Result filtering: filters when requested
- JSON and CSV output → Terminal or pipeline: writes data
- Stream commands → Terminal or pipeline: emits NDJSON
