Skip to content

Commit 3e9f834

Browse files
committed
Add architecture overview section to CLAUDE.md
Document the project architecture including core components, module organization, key design patterns, lifecycle management, and important type aliases. This provides context for AI assistants working with the codebase. Generated with Claude Code (AI-assisted) Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent c99e964 commit 3e9f834

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

CLAUDE.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,59 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
99
- Never add new dependencies unless explicitly requested
1010
- Please always disclose the use of any AI tools in commit messages and PR descriptions
1111
- When adding new `.rs` files, please ensure to always add the licensing header as found in all other files.
12+
13+
## Architecture Overview
14+
15+
LDK-Node is a self-custodial Lightning Network node library built on top of **LDK** (Lightning Development Kit) for Lightning functionality and **BDK** (Bitcoin Development Kit) for on-chain wallet operations. It provides a simple, ready-to-go interface for building Lightning applications with language bindings for Swift, Kotlin, and Python via UniFFI.
16+
17+
### Core Components
18+
19+
| Component | Location | Responsibility |
20+
|-----------|----------|----------------|
21+
| `Node` | `src/lib.rs` | Central abstraction containing all subsystems; entry point for API |
22+
| `Builder` | `src/builder.rs` | Fluent configuration interface for constructing `Node` instances |
23+
| `Wallet` | `src/wallet/` | BDK-based on-chain wallet with SQLite persistence |
24+
| `ChainSource` | `src/chain/` | Chain data abstraction (Esplora, Electrum, Bitcoin Core) |
25+
| `EventHandler` | `src/event.rs` | Translates LDK events to user-facing `Node` events |
26+
| `PaymentStore` | `src/payment/store.rs` | Persistent payment tracking with status and metadata |
27+
28+
### Module Organization
29+
30+
| Module | Purpose |
31+
|--------|---------|
32+
| `payment/` | Payment processing (BOLT11, BOLT12, on-chain, spontaneous, unified) |
33+
| `wallet/` | On-chain wallet abstraction, serialization, persistence |
34+
| `chain/` | Chain data sources, wallet syncing, transaction broadcasting |
35+
| `io/` | Persistence layer (`SQLiteStore`, `VssStore`, KV-store utilities) |
36+
| `liquidity.rs` | Liquidity provider integration (LSPS1/LSPS2) |
37+
| `connection.rs` | Peer connection management and reconnection logic |
38+
| `gossip.rs` | Gossip data source management (RGS, P2P) |
39+
| `graph.rs` | Network graph querying and channel/node information |
40+
| `types.rs` | Type aliases for LDK components (`ChannelManager`, `PeerManager`, etc.) |
41+
| `ffi/` | UniFFI bindings for cross-language support |
42+
43+
### Key Design Patterns
44+
45+
- **Arc-based Shared Ownership**: Extensive use of `Arc` for thread-safe shared components enabling background task spawning
46+
- **Event-Driven Architecture**: Events flow from LDK → `EventHandler``EventQueue` → User application
47+
- **Trait-based Abstraction**: `KVStore`/`KVStoreSync` for storage, `ChainSource` for chain backends, `StorableObject` for persistence
48+
- **Builder Pattern**: Fluent configuration with sensible defaults and validation during build phase
49+
- **Background Tasks**: Multiple categories (wallet sync, gossip updates, peer reconnection, fee updates, event processing)
50+
51+
### Lifecycle
52+
53+
**Startup (`node.start()`)**: Acquires lock → starts chain source → updates fee rates → spawns background sync tasks → sets up gossip/listeners/peer reconnection → starts event processor → marks running
54+
55+
**Shutdown (`node.stop()`)**: Acquires lock → signals stop → aborts cancellable tasks → waits for background tasks → disconnects peers → persists final state
56+
57+
### Type Aliases (from `types.rs`)
58+
59+
Key LDK type aliases used throughout the codebase:
60+
- `ChannelManager` - LDK channel management
61+
- `ChainMonitor` - LDK chain monitoring
62+
- `PeerManager` - LDK peer connections
63+
- `OnionMessenger` - LDK onion messaging
64+
- `Router` - LDK pathfinding (`DefaultRouter`)
65+
- `Scorer` - Combined probabilistic + external scoring
66+
- `Graph` - `NetworkGraph`
67+
- `Sweeper` - `OutputSweeper`

0 commit comments

Comments
 (0)