# elshadhu/blockchain-go architecture

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

- Interactive diagram: https://gitdiagram.com/elshadhu/blockchain-go
- Repository: https://github.com/elshadhu/blockchain-go

## Overview

This is a command-line Bitcoin-style blockchain: users create wallets and a genesis chain, send signed UTXO payments, and inspect balances or blocks. Nodes relay transactions, mine blocks, synchronize chains, and rebuild cached UTXO state. The graph distinguishes wallet/address handling, transaction validation, block mining, persistence, and peer networking. Edges cite shown calls or README-described behavior; several CLI command implementations and iterator details were not excerpted, so their internal links are omitted.

Main entry points: [`blockchain.go`](https://github.com/elshadhu/blockchain-go/blob/main/blockchain.go) (Blockchain), [`transaction.go`](https://github.com/elshadhu/blockchain-go/blob/main/transaction.go) (Transactions), [`server.go`](https://github.com/elshadhu/blockchain-go/blob/main/server.go) (TCP node server), [`utxo_set.go`](https://github.com/elshadhu/blockchain-go/blob/main/utxo_set.go) (UTXO cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI workflows"]
  node_cli["Command router<br/>[cli.go]"]
  node_commands["CLI commands"]
end

subgraph group_wallet["Wallets and payments"]
  node_wallets["Wallet collection<br/>[wallets.go]"]
  node_wallet["Keys and addresses<br/>[wallet.go]"]
  node_address["Base58 encoding<br/>[base58.go]"]
  node_transaction["Transactions<br/>[transaction.go]"]
  node_txinput["Transaction inputs"]
  node_txoutput["Transaction outputs"]
end

subgraph group_chain["Chain and mining"]
  node_blockchain["Blockchain<br/>[blockchain.go]"]
  node_block["Blocks and Merkle roots<br/>[block.go]"]
  node_pow["Proof of work<br/>[proofofwork.go]"]
  node_iterator["Chain iterator"]
  node_merkle["Merkle tree<br/>[merkle_tree.go]"]
end

subgraph group_state["Persistence and UTXOs"]
  node_utxo["UTXO cache<br/>[utxo_set.go]"]
  node_boltdb[("BoltDB")]
end

subgraph group_network["Peer networking"]
  node_server["TCP node server<br/>[server.go]"]
  node_peers(("Peer nodes"))
end

node_user(("Operator"))

node_user -->|"runs commands"| node_cli
node_cli -->|"dispatches to"| node_commands
node_commands -->|"manages wallets"| node_wallets
node_wallets -->|"creates and loads"| node_wallet
node_wallet -->|"encodes address"| node_address
node_commands -->|"builds payments"| node_transaction
node_transaction -->|"selects spendable outputs"| node_utxo
node_transaction -->|"signs inputs via"| node_blockchain
node_transaction -->|"uses inputs"| node_txinput
node_transaction -->|"creates outputs"| node_txoutput
node_txoutput -->|"decodes address"| node_address
node_blockchain -->|"stores blocks"| node_boltdb
node_blockchain -->|"iterates chain"| node_iterator
node_blockchain -->|"verifies transactions"| node_transaction
node_blockchain -->|"mines and appends"| node_block
node_block -->|"runs proof of work"| node_pow
node_block -->|"builds transaction root"| node_merkle
node_utxo -->|"reads and writes cache"| node_boltdb
node_utxo -->|"rebuilds from chain"| node_blockchain
node_commands -->|"creates and inspects chain"| node_blockchain
node_commands -->|"queries or reindexes"| node_utxo
node_commands -->|"starts node"| node_server
node_server -->|"loads and updates chain"| node_blockchain
node_server -->|"reindexes after blocks"| node_utxo
node_server -->|"relays and verifies"| node_transaction
node_server -->|"exchanges TCP messages"| node_peers
node_peers -.->|"sends node messages"| node_server

click node_cli "https://github.com/elshadhu/blockchain-go/blob/main/cli.go"
click node_wallets "https://github.com/elshadhu/blockchain-go/blob/main/wallets.go"
click node_wallet "https://github.com/elshadhu/blockchain-go/blob/main/wallet.go"
click node_address "https://github.com/elshadhu/blockchain-go/blob/main/base58.go"
click node_transaction "https://github.com/elshadhu/blockchain-go/blob/main/transaction.go"
click node_txinput "https://github.com/elshadhu/blockchain-go/blob/main/transaction_input.go"
click node_txoutput "https://github.com/elshadhu/blockchain-go/blob/main/transaction_output.go"
click node_blockchain "https://github.com/elshadhu/blockchain-go/blob/main/blockchain.go"
click node_block "https://github.com/elshadhu/blockchain-go/blob/main/block.go"
click node_pow "https://github.com/elshadhu/blockchain-go/blob/main/proofofwork.go"
click node_iterator "https://github.com/elshadhu/blockchain-go/blob/main/blockchain_iterator.go"
click node_utxo "https://github.com/elshadhu/blockchain-go/blob/main/utxo_set.go"
click node_server "https://github.com/elshadhu/blockchain-go/blob/main/server.go"
click node_merkle "https://github.com/elshadhu/blockchain-go/blob/main/merkle_tree.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_cli,node_commands toneBlue
class node_wallets,node_wallet,node_address,node_transaction,node_txinput,node_txoutput toneAmber
class node_blockchain,node_block,node_pow,node_iterator,node_merkle toneMint
class node_utxo,node_boltdb toneRose
class node_server,node_peers,node_user toneIndigo
```

## Components

### CLI workflows

- [Command router](https://github.com/elshadhu/blockchain-go/blob/main/cli.go): `cli.go`
- **CLI commands**

### Wallets and payments

- [Wallet collection](https://github.com/elshadhu/blockchain-go/blob/main/wallets.go): `wallets.go`
- [Keys and addresses](https://github.com/elshadhu/blockchain-go/blob/main/wallet.go): `wallet.go`
- [Base58 encoding](https://github.com/elshadhu/blockchain-go/blob/main/base58.go): `base58.go`
- [Transactions](https://github.com/elshadhu/blockchain-go/blob/main/transaction.go): `transaction.go`
- [Transaction inputs](https://github.com/elshadhu/blockchain-go/blob/main/transaction_input.go): `transaction_input.go`
- [Transaction outputs](https://github.com/elshadhu/blockchain-go/blob/main/transaction_output.go): `transaction_output.go`

### Chain and mining

- [Blockchain](https://github.com/elshadhu/blockchain-go/blob/main/blockchain.go): `blockchain.go`
- [Blocks and Merkle roots](https://github.com/elshadhu/blockchain-go/blob/main/block.go): `block.go`
- [Proof of work](https://github.com/elshadhu/blockchain-go/blob/main/proofofwork.go): `proofofwork.go`
- [Chain iterator](https://github.com/elshadhu/blockchain-go/blob/main/blockchain_iterator.go): `blockchain_iterator.go`
- [Merkle tree](https://github.com/elshadhu/blockchain-go/blob/main/merkle_tree.go): `merkle_tree.go`

### Persistence and UTXOs

- [UTXO cache](https://github.com/elshadhu/blockchain-go/blob/main/utxo_set.go): `utxo_set.go`
- **BoltDB**

### Peer networking

- [TCP node server](https://github.com/elshadhu/blockchain-go/blob/main/server.go): `server.go`
- **Peer nodes**

### Other components

- **Operator**

## Connections

- Operator → Command router: runs commands (evidence: `README.md`)
- Command router → CLI commands: dispatches to (evidence: `cli.go`)
- CLI commands → Wallet collection: manages wallets (evidence: `README.md`)
- Wallet collection → Keys and addresses: creates and loads (evidence: `wallets.go`)
- Keys and addresses → Base58 encoding: encodes address (evidence: `wallet.go`)
- CLI commands → Transactions: builds payments (evidence: `README.md`)
- Transactions → UTXO cache: selects spendable outputs (evidence: `transaction.go`)
- Transactions → Blockchain: signs inputs via (evidence: `transaction.go`)
- Transactions → Transaction inputs: uses inputs (evidence: `transaction.go`)
- Transactions → Transaction outputs: creates outputs (evidence: `transaction.go`)
- Transaction outputs → Base58 encoding: decodes address (evidence: `transaction_output.go`)
- Blockchain → BoltDB: stores blocks (evidence: `blockchain.go`)
- Blockchain → Chain iterator: iterates chain (evidence: `blockchain.go`)
- Blockchain → Transactions: verifies transactions (evidence: `blockchain.go`)
- Blockchain → Blocks and Merkle roots: mines and appends (evidence: `blockchain.go`)
- Blocks and Merkle roots → Proof of work: runs proof of work (evidence: `block.go`)
- Blocks and Merkle roots → Merkle tree: builds transaction root (evidence: `block.go`)
- UTXO cache → BoltDB: reads and writes cache (evidence: `utxo_set.go`)
- UTXO cache → Blockchain: rebuilds from chain (evidence: `utxo_set.go`)
- CLI commands → Blockchain: creates and inspects chain (evidence: `README.md`)
- CLI commands → UTXO cache: queries or reindexes (evidence: `README.md`)
- CLI commands → TCP node server: starts node (evidence: `README.md`)
- TCP node server → Blockchain: loads and updates chain (evidence: `server.go`)
- TCP node server → UTXO cache: reindexes after blocks (evidence: `server.go`)
- TCP node server → Transactions: relays and verifies (evidence: `server.go`)
- TCP node server → Peer nodes: exchanges TCP messages (evidence: `server.go`)
- Peer nodes → TCP node server: sends node messages (evidence: `README.md`)
