# layertwo-labs/thunder-rust architecture

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

- Interactive diagram: https://gitdiagram.com/layertwo-labs/thunder-rust
- Repository: https://github.com/layertwo-labs/thunder-rust

## Overview

Thunder is a Rust workspace organized around a core node/library, an application shell, and a separate RPC client. The architecture is centered on a shared domain library that implements the actual blockchain/node behavior, while the app layer mainly orchestrates presentation and remote control.

1. Core domain engine: `lib/`  
   This is the main backend subsystem. It contains the node logic (`lib/node`), network peer management (`lib/net/peer`), state handling and rollback (`lib/state`), mempool and mining (`lib/mempool.rs`, `lib/miner.rs`), wallet/authorization/archive logic, and shared domain types (`lib/types`). This crate is where consensus/state transitions and peer-to-peer behavior live.

2. Node runtime split into tasks  
   The `lib/node` folder suggests a task-based runtime boundary: `mainchain_task.rs` and `net_task.rs` separate mainchain/block-processing responsibilities from network I/O. That separation is important for diagramming internal data flow: peer messages feed network tasks, which then drive state updates and mainchain processing.

3. Network and peer layer  
   `lib/net` and `lib/net/peer` implement the transport-facing side of the node. The peer subsystem is decomposed into mailbox, channel pool, request queue, task, and message handling, indicating asynchronous message passing between peers and internal node logic rather than direct synchronous calls.

4. State and chain data model  
   `lib/state` holds the canonical chain/block state, rollback support, and two-way peg data. This is the persistence/consensus boundary: incoming blocks, transactions, and withdrawals are validated and applied here, with rollback support for reorgs or invalid transitions.

5. Shared protocol and type layer  
   `lib/types` and `proto/` define the shared data structures used across node, RPC, and UI boundaries: addresses, hashes, transactions, and schema/proto definitions. `lib/types/proto.rs` and `rpc-api/schema.rs` indicate schema-driven serialization across component boundaries.

6. Application shell and UI: `app/`  
   The `app` crate is the executable frontend/orchestrator. It contains the main binary entrypoint, CLI/bootstrap logic, a GUI subsystem, and an embedded RPC server. This crate does not appear to own consensus logic; it consumes the core library and exposes user-facing control surfaces.

7. GUI as a set of functional panels  
   `app/gui` is organized by task domain rather than by generic windowing: coins/transfer/tx creation/UTXO selection, block explorer, mempool explorer, miner controls, withdrawals, parent-chain info/transfer, seed management, and console logs. That implies a dashboard-style client that calls into backend services rather than directly manipulating state.

8. RPC server boundary  
   `app/rpc_server.rs` is the primary integration point between the app/UI and the backend. The README explicitly says the app can run with an embedded JSON-RPC server, so the UI and the external CLI both talk to the same RPC surface rather than accessing the node internals directly.

9. External CLI client  
   The `cli/` crate is a separate binary (`thunder_app_cli`) for interacting with the JSON-RPC server. Architecturally, this is a thin remote client that depends on the shared RPC API definitions, allowing headless control of the node/app.

10. Shared RPC contract  
   `rpc-api/` contains the schema and types used by both server and client. This crate is the contract boundary for all remote operations, and it likely prevents drift between the app’s embedded server and the external CLI.

11. Testing and lifecycle coverage  
   `integration_tests/` contains end-to-end tests such as IBD and unknown withdrawal scenarios. These tests indicate the system is validated at the protocol/state boundary, not just at unit level. The presence of an `example.env` suggests tests depend on environment-driven runtime setup.

12. Packaging and delivery  
   The repository is designed for reproducible builds via Cargo workspaces, with Docker and CI workflows in `.github/workflows`. That affects deployment architecture: the node/app can be built and run as a containerized binary, with automated lint/build checks in CI.

13. Architectural summary of data flow  
   The main flow is: peer/network messages and local actions enter the core `lib` node, which updates mempool/state/miner logic; results are exposed through the RPC server; the GUI and CLI consume the RPC API; integration tests exercise the same external interfaces. The key boundaries are between core consensus/state, RPC contract, and presentation/client layers.

Main entry points: [`lib/lib.rs`](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/lib.rs) (lib), [`app/rpc_server.rs`](https://github.com/layertwo-labs/thunder-rust/blob/master/app/rpc_server.rs) (RPC server), [`lib/state/mod.rs`](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/state/mod.rs) (State core), [`Dockerfile`](https://github.com/layertwo-labs/thunder-rust/tree/master/Dockerfile) (CI/Docker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core engine"]
  node_lib_root["lib<br/>workspace crate<br/>[lib.rs]"]
  node_node_rt["Node runtime<br/>task runtime<br/>[mod.rs]"]
  node_mainchain_task["Mainchain task<br/>processing task<br/>[mainchain_task.rs]"]
  node_net_task["Net task<br/>io task<br/>[net_task.rs]"]
  node_net_layer["Network layer<br/>transport layer<br/>[mod.rs]"]
  node_peer_stack["Peer stack<br/>async peer subsystem<br/>[mod.rs]"]
  node_state_core[("State core<br/>chain state<br/>[mod.rs]")]
  node_mempool["Mempool<br/>transaction pool<br/>[mempool.rs]"]
  node_miner["Miner<br/>block producer<br/>[miner.rs]"]
  node_wallet["Wallet<br/>account domain<br/>[wallet.rs]"]
end

subgraph group_app["App shell"]
  node_app_root["app<br/>executable shell<br/>[app.rs]"]
  node_gui["GUI<br/>dashboard ui<br/>[mod.rs]"]
  node_rpc_server["RPC server<br/>json-rpc boundary<br/>[rpc_server.rs]"]
end

subgraph group_remote["Remote clients"]
  node_cli["CLI<br/>[main.rs]"]
end

subgraph group_contracts["Shared contracts"]
  node_types["Types<br/>[mod.rs]"]
  node_proto["Proto<br/>schema definitions"]
  node_rpc_api["RPC API<br/>rpc contract<br/>[schema.rs]"]
end

subgraph group_tests["Tests and delivery"]
  node_integration_tests["Integration tests<br/>end-to-end tests"]
  node_ci_docker["CI/Docker<br/>build and delivery"]
end

node_lib_root -->|"contains"| node_node_rt
node_lib_root -->|"contains"| node_net_layer
node_lib_root -->|"contains"| node_state_core
node_lib_root -->|"contains"| node_mempool
node_lib_root -->|"contains"| node_miner
node_lib_root -->|"contains"| node_wallet
node_node_rt -->|"splits into"| node_mainchain_task
node_node_rt -->|"splits into"| node_net_task
node_net_layer -->|"hosts"| node_peer_stack
node_peer_stack -->|"drives updates"| node_state_core
node_mainchain_task -->|"applies blocks"| node_state_core
node_mainchain_task -->|"consumes"| node_mempool
node_mempool -->|"feeds"| node_miner
node_state_core -->|"uses"| node_types
node_wallet -->|"uses"| node_types
node_proto -.->|"aligns"| node_types
node_app_root -->|"contains"| node_gui
node_app_root -->|"hosts"| node_rpc_server
node_gui -->|"controls via"| node_rpc_server
node_cli -->|"depends on"| node_rpc_api
node_rpc_server -->|"implements"| node_rpc_api
node_rpc_server -->|"calls into"| node_lib_root
node_integration_tests -.->|"exercises"| node_rpc_api
node_integration_tests -.->|"exercises"| node_lib_root
node_ci_docker -.->|"builds"| node_app_root
node_ci_docker -.->|"builds"| node_cli
node_ci_docker -.->|"runs"| node_integration_tests

click node_lib_root "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/lib.rs"
click node_node_rt "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/node/mod.rs"
click node_mainchain_task "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/node/mainchain_task.rs"
click node_net_task "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/node/net_task.rs"
click node_net_layer "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/net/mod.rs"
click node_peer_stack "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/net/peer/mod.rs"
click node_state_core "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/state/mod.rs"
click node_mempool "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/mempool.rs"
click node_miner "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/miner.rs"
click node_wallet "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/wallet.rs"
click node_types "https://github.com/layertwo-labs/thunder-rust/blob/master/lib/types/mod.rs"
click node_proto "https://github.com/layertwo-labs/thunder-rust/tree/master/proto"
click node_app_root "https://github.com/layertwo-labs/thunder-rust/blob/master/app/app.rs"
click node_gui "https://github.com/layertwo-labs/thunder-rust/blob/master/app/gui/mod.rs"
click node_rpc_server "https://github.com/layertwo-labs/thunder-rust/blob/master/app/rpc_server.rs"
click node_cli "https://github.com/layertwo-labs/thunder-rust/blob/master/cli/main.rs"
click node_rpc_api "https://github.com/layertwo-labs/thunder-rust/blob/master/rpc-api/schema.rs"
click node_integration_tests "https://github.com/layertwo-labs/thunder-rust/blob/master/integration_tests/integration_test.rs"
click node_ci_docker "https://github.com/layertwo-labs/thunder-rust/tree/master/Dockerfile"

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_lib_root,node_node_rt,node_mainchain_task,node_net_task,node_net_layer,node_peer_stack,node_state_core,node_mempool,node_miner,node_wallet toneBlue
class node_app_root,node_gui,node_rpc_server toneAmber
class node_cli toneMint
class node_types,node_proto,node_rpc_api toneRose
class node_integration_tests,node_ci_docker toneIndigo
```

## Components

### Core engine

Shared node, state, network, and domain logic.

- [lib](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/lib.rs): workspace crate · Core backend crate for node behavior and shared domain logic. · `lib/lib.rs`
- [Node runtime](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/node/mod.rs): task runtime · Orchestrates node execution as separate mainchain and network tasks. · `lib/node/mod.rs`
- [Mainchain task](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/node/mainchain_task.rs): processing task · Handles block processing, chain updates, and consensus-facing work. · `lib/node/mainchain_task.rs`
- [Net task](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/node/net_task.rs): io task · Drives network I/O and peer message flow into the node. · `lib/node/net_task.rs`
- [Network layer](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/net/mod.rs): transport layer · Network-facing module that hosts peer communication primitives. · `lib/net/mod.rs`
- [Peer stack](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/net/peer/mod.rs): async peer subsystem · Asynchronous peer messaging, queues, and mailbox coordination. · `lib/net/peer/mod.rs`
- [State core](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/state/mod.rs): chain state · Canonical block/state storage with rollback and peg data. · `lib/state/mod.rs`
- [Mempool](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/mempool.rs): transaction pool · Pending transaction pool used by node and miner logic. · `lib/mempool.rs`
- [Miner](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/miner.rs): block producer · Mining and block production logic built on shared state. · `lib/miner.rs`
- [Wallet](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/wallet.rs): account domain · Wallet and authorization-facing domain logic. · `lib/wallet.rs`

### App shell

Executable frontend, GUI, and embedded RPC server.

- [app](https://github.com/layertwo-labs/thunder-rust/blob/master/app/app.rs): executable shell · Main application crate that orchestrates UI and RPC. · `app/app.rs`
- [GUI](https://github.com/layertwo-labs/thunder-rust/blob/master/app/gui/mod.rs): dashboard ui · Panel-based user interface for node control and explorers. · `app/gui/mod.rs`
- [RPC server](https://github.com/layertwo-labs/thunder-rust/blob/master/app/rpc_server.rs): json-rpc boundary · Embedded JSON-RPC server exposing backend control and queries. · `app/rpc_server.rs`

### Remote clients

External command-line access to the RPC surface.

- [CLI](https://github.com/layertwo-labs/thunder-rust/blob/master/cli/main.rs): rpc client · Separate command-line client for remote control via RPC. · `cli/main.rs`

### Shared contracts

Schema and types shared across process boundaries.

- [Types](https://github.com/layertwo-labs/thunder-rust/blob/master/lib/types/mod.rs): shared domain types · Addresses, hashes, transactions, schemas, and proto helpers. · `lib/types/mod.rs`
- [Proto](https://github.com/layertwo-labs/thunder-rust/tree/master/proto): schema definitions · Shared protocol/schema definitions used across boundaries. · `proto`
- [RPC API](https://github.com/layertwo-labs/thunder-rust/blob/master/rpc-api/schema.rs): rpc contract · Shared RPC schema and types for client/server compatibility. · `rpc-api/schema.rs`

### Tests and delivery

Integration coverage and build/deployment tooling.

- [Integration tests](https://github.com/layertwo-labs/thunder-rust/blob/master/integration_tests/integration_test.rs): end-to-end tests · Protocol and lifecycle tests exercising public interfaces. · `integration_tests/integration_test.rs`
- [CI/Docker](https://github.com/layertwo-labs/thunder-rust/tree/master/Dockerfile): build and delivery · Workspace build, lint, and container packaging workflows. · `Dockerfile`

## Connections

- lib → Node runtime: contains · Core crate includes the node runtime boundary.
- lib → Network layer: contains · Core crate includes transport-facing networking code.
- lib → State core: contains · Core crate owns canonical state management.
- lib → Mempool: contains · Core crate includes pending transaction handling.
- lib → Miner: contains · Core crate includes block production logic.
- lib → Wallet: contains · Core crate includes wallet and authorization domain logic.
- Node runtime → Mainchain task: splits into · Node runtime separates chain processing into a dedicated task.
- Node runtime → Net task: splits into · Node runtime separates network I/O into a dedicated task.
- Network layer → Peer stack: hosts · Transport layer is implemented through peer coordination primitives.
- Peer stack → State core: drives updates · Peer messages eventually feed validated state transitions.
- Mainchain task → State core: applies blocks · Chain-processing task updates canonical state.
- Mainchain task → Mempool: consumes · Block processing interacts with pending transactions.
- Mempool → Miner: feeds · Miner draws from the transaction pool.
- State core → Types: uses · State logic relies on shared domain types.
- Wallet → Types: uses · Wallet logic uses shared addresses and transaction types.
- Proto → Types: aligns · Protocol schemas are backed by shared domain types.
- app → GUI: contains · Application crate includes the user-facing GUI.
- app → RPC server: hosts · Application crate embeds the RPC server boundary.
- GUI → RPC server: controls via · GUI invokes backend actions through RPC rather than directly.
- CLI → RPC API: depends on · CLI uses the shared RPC contract.
- RPC server → RPC API: implements · RPC server exposes the shared contract.
- RPC server → lib: calls into · Server bridges UI/client requests to core backend logic.
- Integration tests → RPC API: exercises · End-to-end tests validate public RPC-facing behavior.
- Integration tests → lib: exercises · Integration tests cover core protocol/state behavior.
- CI/Docker → app: builds · Delivery pipeline packages the application binary.
- CI/Docker → CLI: builds · Delivery pipeline packages the CLI client.
- CI/Docker → Integration tests: runs · CI validates the workspace through automated tests.
