# spacesprotocol/spaces architecture

> Architecture diagram of the GitHub repository spacesprotocol/spaces, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spacesprotocol/spaces
- Repository: https://github.com/spacesprotocol/spaces

## Overview

##### Project Type Identification
This is a Bitcoin protocol extension project consisting of multiple Rust packages that interact with Bitcoin Core. The system is primarily composed of a daemon service and a wallet implementation.

##### Main Components

a) External Components:
- Bitcoin Core Node (external dependency)
- Bitcoin Network (Testnet4/Mainnet)

b) Core System Components:
- Spaced Daemon (node package)
- Space CLI Wallet (node package)
- Protocol Library (protocol package)
- Wallet Library (wallet package)

##### Component Relationships

**User -> Space CLI -> Spaced Daemon -> Bitcoin Core -> Bitcoin Network**

- > Wallet Library -> Protocol Library

##### Specific Component Details

For the Spaced Daemon, include these subcomponents (based on src files):
- Config Manager (config.rs)
- Node Service (node.rs)
- RPC Handler (rpc.rs)
- Store Manager (store.rs)
- Sync Service (sync.rs)
- Wallet Manager (wallets.rs)

For the Protocol Library, show:
- Validation Layer (validate.rs)
- Script Handler (script.rs)
- Preparation Logic (prepare.rs)
- Hashing Services (hasher.rs)

##### Additional Elements

Include:
- Storage interactions
- Security boundaries
- Version compatibility notes (Bitcoin Core 28+)
- Network connection points

##### Important Notes

- Non-invasive nature of the protocol (no Bitcoin modifications required)
- Clear separation between the daemon and wallet functionalities
- Test coverage points (based on the test directories)
- Configuration dependencies
- Error handling paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph User["User Interface Layer"]
        CLI["Space CLI Wallet"]:::cli
    end

    subgraph Core["Core Services Layer"]
        SPACED["Spaced Daemon"]:::daemon
        
        subgraph DaemonComponents["Daemon Components"]
            direction TB
            CONFIG["Config Manager"]:::component
            NODE["Node Service"]:::component
            RPC["RPC Handler"]:::component
            STORE["Store Manager"]:::component
            SYNC["Sync Service"]:::component
            WALLET_MGR["Wallet Manager"]:::component
        end

        subgraph WalletLib["Wallet Library"]
            direction TB
            WLIB["Core Wallet Lib"]:::library
            BUILDER["Transaction Builder"]:::library
            ADDR["Address Handler"]:::library
            EXPORT["Export Service"]:::library
        end
    end

    subgraph Protocol["Protocol Layer"]
        direction TB
        VALIDATE["Validation Layer"]:::protocol
        SCRIPT["Script Handler"]:::protocol
        PREPARE["Preparation Logic"]:::protocol
        HASH["Hashing Services"]:::protocol
    end

    subgraph External["External Layer"]
        direction TB
        BITCOIN["Bitcoin Core"]:::external
        NETWORK["Bitcoin Network"]:::external
    end

    %% Connections
    CLI --> SPACED
    CLI --> WalletLib
    SPACED --> BITCOIN
    BITCOIN --> NETWORK
    WalletLib --> Protocol
    
    %% Daemon Component Connections
    SPACED --> CONFIG
    SPACED --> NODE
    SPACED --> RPC
    SPACED --> STORE
    SPACED --> SYNC
    SPACED --> WALLET_MGR

    %% Style Definitions
    classDef cli fill:#2196F3,stroke:#1565C0,color:white
    classDef daemon fill:#4CAF50,stroke:#2E7D32,color:white
    classDef component fill:#81C784,stroke:#4CAF50,color:white
    classDef library fill:#FFB74D,stroke:#F57C00,color:white
    classDef protocol fill:#FFF176,stroke:#FBC02D,color:black
    classDef external fill:#90A4AE,stroke:#546E7A,color:white

    %% Click Events
    click CLI "https://github.com/spacesprotocol/spaces/blob/main/node/src/bin/space-cli.rs"
    click SPACED "https://github.com/spacesprotocol/spaces/blob/main/node/src/bin/spaced.rs"
    click CONFIG "https://github.com/spacesprotocol/spaces/blob/main/node/src/config.rs"
    click NODE "https://github.com/spacesprotocol/spaces/blob/main/node/src/node.rs"
    click RPC "https://github.com/spacesprotocol/spaces/blob/main/node/src/rpc.rs"
    click STORE "https://github.com/spacesprotocol/spaces/blob/main/node/src/store.rs"
    click SYNC "https://github.com/spacesprotocol/spaces/blob/main/node/src/sync.rs"
    click WALLET_MGR "https://github.com/spacesprotocol/spaces/blob/main/node/src/wallets.rs"
    click VALIDATE "https://github.com/spacesprotocol/spaces/blob/main/protocol/src/validate.rs"
    click SCRIPT "https://github.com/spacesprotocol/spaces/blob/main/protocol/src/script.rs"
    click PREPARE "https://github.com/spacesprotocol/spaces/blob/main/protocol/src/prepare.rs"
    click HASH "https://github.com/spacesprotocol/spaces/blob/main/protocol/src/hasher.rs"
    click WLIB "https://github.com/spacesprotocol/spaces/blob/main/wallet/src/lib.rs"
    click BUILDER "https://github.com/spacesprotocol/spaces/blob/main/wallet/src/builder.rs"
    click ADDR "https://github.com/spacesprotocol/spaces/blob/main/wallet/src/address.rs"
    click EXPORT "https://github.com/spacesprotocol/spaces/blob/main/wallet/src/export.rs"
```
