# spacemeshos/smcli architecture

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

- Interactive diagram: https://gitdiagram.com/spacemeshos/smcli
- Repository: https://github.com/spacemeshos/smcli

## Overview

smcli is a Spacemesh CLI whose main workflow creates or reads encrypted wallet files, with a separate command for calculating genesis vesting and vault addresses. The wallet workflow covers mnemonic or Ledger key sourcing, hierarchical account derivation, encryption and file output, then decryption and account display. Source excerpts show those wallet operations and the genesis calculations; broader command behavior is represented only where documented, and no uninspected subsystem wiring is assumed.

Main entry points: [`cmd/wallet.go`](https://github.com/spacemeshos/smcli/blob/develop/cmd/wallet.go) (Wallet commands), [`wallet/bip32.go`](https://github.com/spacemeshos/smcli/blob/develop/wallet/bip32.go) (HD key derivation), [`cmd/root.go`](https://github.com/spacemeshos/smcli/blob/develop/cmd/root.go) (Command root), [`cmd/genesis.go`](https://github.com/spacemeshos/smcli/blob/develop/cmd/genesis.go) (Genesis verify)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI entrypoints"]
  node_main["Program entry<br/>[main.go]"]
  node_root["Command root<br/>[root.go]"]
end

subgraph group_wallet["Wallet management"]
  node_walletcmd["Wallet commands<br/>[wallet.go]"]
  node_walletmodel["Wallet creation<br/>[wallet.go]"]
  node_keyderivation["HD key derivation<br/>[bip32.go]"]
  node_hdpaths["HD path rules<br/>[bip44.go]"]
  node_walletcrypto["Wallet encryption<br/>[store.go]"]
  node_common["Wallet file paths<br/>[common.go]"]
end

subgraph group_genesis["Genesis verification"]
  node_genesiscmd["Genesis verify<br/>[genesis.go]"]
end

node_user(("CLI user"))
node_walletfile["Encrypted wallet"]
node_ledger(("Ledger device"))
node_bip32lib["BIP32 library"]
node_genesisprotocol["Spacemesh templates"]
node_terminal(("Terminal output"))

node_user -->|"runs CLI"| node_main
node_main -->|"calls Execute"| node_root
node_root -->|"dispatches wallet"| node_walletcmd
node_root -->|"dispatches genesis"| node_genesiscmd
node_walletcmd -->|"creates wallet"| node_walletmodel
node_walletmodel -->|"derives keys"| node_keyderivation
node_keyderivation -->|"builds paths"| node_hdpaths
node_keyderivation -->|"derives software keys"| node_bip32lib
node_keyderivation -.->|"reads public keys"| node_ledger
node_walletcmd -->|"exports or opens"| node_walletcrypto
node_walletcmd -->|"gets output path"| node_common
node_walletcmd -->|"opens or writes"| node_walletfile
node_walletcrypto -->|"reads or writes JSON"| node_walletfile
node_walletcmd -->|"prints accounts"| node_terminal
node_genesiscmd -->|"computes addresses"| node_genesisprotocol
node_genesiscmd -->|"reads inputs and prints"| node_terminal

click node_main "https://github.com/spacemeshos/smcli/blob/develop/main.go"
click node_root "https://github.com/spacemeshos/smcli/blob/develop/cmd/root.go"
click node_walletcmd "https://github.com/spacemeshos/smcli/blob/develop/cmd/wallet.go"
click node_genesiscmd "https://github.com/spacemeshos/smcli/blob/develop/cmd/genesis.go"
click node_walletmodel "https://github.com/spacemeshos/smcli/blob/develop/wallet/wallet.go"
click node_keyderivation "https://github.com/spacemeshos/smcli/blob/develop/wallet/bip32.go"
click node_hdpaths "https://github.com/spacemeshos/smcli/blob/develop/wallet/bip44.go"
click node_walletcrypto "https://github.com/spacemeshos/smcli/blob/develop/wallet/store.go"
click node_common "https://github.com/spacemeshos/smcli/blob/develop/common/common.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_main,node_root,node_user toneBlue
class node_walletcmd,node_walletmodel,node_keyderivation,node_hdpaths,node_walletcrypto,node_common toneAmber
class node_genesiscmd toneMint
class node_walletfile,node_ledger,node_bip32lib,node_genesisprotocol,node_terminal toneIndigo
```

## Components

### CLI entrypoints

- [Program entry](https://github.com/spacemeshos/smcli/blob/develop/main.go): `main.go`
- [Command root](https://github.com/spacemeshos/smcli/blob/develop/cmd/root.go): `cmd/root.go`

### Wallet management

- [Wallet commands](https://github.com/spacemeshos/smcli/blob/develop/cmd/wallet.go): `cmd/wallet.go`
- [Wallet creation](https://github.com/spacemeshos/smcli/blob/develop/wallet/wallet.go): `wallet/wallet.go`
- [HD key derivation](https://github.com/spacemeshos/smcli/blob/develop/wallet/bip32.go): `wallet/bip32.go`
- [HD path rules](https://github.com/spacemeshos/smcli/blob/develop/wallet/bip44.go): `wallet/bip44.go`
- [Wallet encryption](https://github.com/spacemeshos/smcli/blob/develop/wallet/store.go): `wallet/store.go`
- [Wallet file paths](https://github.com/spacemeshos/smcli/blob/develop/common/common.go): `common/common.go`

### Genesis verification

- [Genesis verify](https://github.com/spacemeshos/smcli/blob/develop/cmd/genesis.go): `cmd/genesis.go`

### Other components

- **CLI user**
- **Encrypted wallet**
- **Ledger device**
- **BIP32 library**
- **Spacemesh templates**
- **Terminal output**

## Connections

- CLI user → Program entry: runs CLI
- Program entry → Command root: calls Execute
- Command root → Wallet commands: dispatches wallet
- Command root → Genesis verify: dispatches genesis
- Wallet commands → Wallet creation: creates wallet
- Wallet creation → HD key derivation: derives keys
- HD key derivation → HD path rules: builds paths
- HD key derivation → BIP32 library: derives software keys
- HD key derivation → Ledger device: reads public keys
- Wallet commands → Wallet encryption: exports or opens
- Wallet commands → Wallet file paths: gets output path
- Wallet commands → Encrypted wallet: opens or writes
- Wallet encryption → Encrypted wallet: reads or writes JSON
- Wallet commands → Terminal output: prints accounts
- Genesis verify → Spacemesh templates: computes addresses
- Genesis verify → Terminal output: reads inputs and prints
