# commune-ai/subspace architecture

> Architecture diagram of the GitHub repository commune-ai/subspace, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/commune-ai/subspace
- Repository: https://github.com/commune-ai/subspace

## Overview

##### Main Components

a) Core Node Architecture:
- Runtime Environment (from /runtime)
- Network Layer (from node/src/service)
- Consensus Layer (referenced in README)
- RPC Interface (from node/src/rpc)

b) Pallet System:
- Subspace Pallet (core functionality)
- Governance Pallet
- Offworker Pallet
- Subnet Emission Pallet
- Faucet Pallet

c) External Interfaces:
- EVM Compatibility Layer (indicated by precompiles)
- RPC Endpoints
- P2P Network Interface

##### Component Relationships

- Data flow between pallets
- Communication paths between node components
- External interaction points

##### Specific Implementation Details

Create subsections for key features:
a) Consensus Mechanism:
- Interaction between node/src/service and pallets/subspace
- Subnet consensus components from pallets/subnet_emission

b) Network Layer:
- P2P communication
- Peer discovery
- Module advertising system

c) State Management:
- Runtime storage
- Chain state handling
- State transitions

##### Detailed Component Breakdown

For each major component, include:

a) Runtime (/runtime):
- Precompiles
- State transitions
- Block execution

b) Pallets:
- Subspace: Network management, staking, subnet handling
- Governance: DAO functionality, proposals, voting
- Offworker: Process management, profitability calculations
- Subnet Emission: Distribution, consensus, pricing

c) Node Services:
- Manual sealing
- Decryption services
- ETH compatibility layer

##### Additional Elements

Supporting components:
- Testing framework
- Benchmarking system
- Chain specification handling
- RPC interfaces

##### Notes

Annotations for:
- Key configuration points
- Scalability considerations
- Security boundaries
- Extension points

This approach will create a comprehensive yet understandable system design that accurately represents the Subspace blockchain's architecture while maintaining clarity about component relationships and data flow.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Node Architecture"]
        Runtime["Runtime Environment"]:::runtime
        Network["Network Layer"]:::network
        Consensus["Consensus Layer"]:::consensus
        RPC["RPC Interface"]:::rpc
    end

    subgraph Pallets["Custom Pallets"]
        SubspacePallet["Subspace Pallet"]:::pallet
        GovPallet["Governance Pallet"]:::pallet
        OffworkerPallet["Offworker Pallet"]:::pallet
        SubnetPallet["Subnet Emission Pallet"]:::pallet
        FaucetPallet["Faucet Pallet"]:::pallet
    end

    subgraph External["External Interfaces"]
        EVM["EVM Compatibility Layer"]:::external
        RPCEndpoints["RPC Endpoints"]:::external
        P2P["P2P Network Interface"]:::external
    end

    subgraph Implementation["Implementation Details"]
        ConsensusImpl["Consensus Implementation"]:::impl
        NetworkStaking["Network Staking"]:::impl
        GovDAO["Governance DAO"]:::impl
        SubnetPricing["Subnet Pricing"]:::impl
    end

    subgraph Services["Node Services"]
        ManualSeal["Manual Sealing"]:::service
        Decryption["Decryption Service"]:::service
        ChainSpec["Chain Specification"]:::service
        Testing["Testing Framework"]:::service
    end

    Runtime --> SubspacePallet
    Runtime --> GovPallet
    Runtime --> OffworkerPallet
    Runtime --> SubnetPallet
    Runtime --> FaucetPallet
    Runtime --> EVM

    Network --> P2P
    Network --> NetworkStaking
    
    Consensus --> ConsensusImpl
    ConsensusImpl --> SubnetPallet
    
    RPC --> RPCEndpoints
    
    SubspacePallet --> NetworkStaking
    GovPallet --> GovDAO
    SubnetPallet --> SubnetPricing
    
    ManualSeal --> Runtime
    Decryption --> Runtime
    ChainSpec --> Runtime
    Testing --> Runtime

    %% Click events for component mapping
    click Runtime "https://github.com/commune-ai/subspace/blob/main/runtime/src/lib.rs"
    click Network "https://github.com/commune-ai/subspace/tree/main/pallets/subspace/src/network/"
    click RPC "https://github.com/commune-ai/subspace/tree/main/node/src/rpc/"
    click EVM "https://github.com/commune-ai/subspace/tree/main/runtime/src/precompiles/"
    click SubspacePallet "https://github.com/commune-ai/subspace/tree/main/pallets/subspace/src/"
    click GovPallet "https://github.com/commune-ai/subspace/tree/main/pallets/governance/src/"
    click OffworkerPallet "https://github.com/commune-ai/subspace/tree/main/pallets/offworker/src/"
    click SubnetPallet "https://github.com/commune-ai/subspace/tree/main/pallets/subnet_emission/src/"
    click FaucetPallet "https://github.com/commune-ai/subspace/tree/main/pallets/faucet/src/"
    click ConsensusImpl "https://github.com/commune-ai/subspace/tree/main/pallets/subnet_emission/src/subnet_consensus/"
    click ChainSpec "https://github.com/commune-ai/subspace/tree/main/node/chain-specs/"
    click Testing "https://github.com/commune-ai/subspace/tree/main/tests/src/"
    click NetworkStaking "https://github.com/commune-ai/subspace/blob/main/pallets/subspace/src/network/staking.rs"
    click GovDAO "https://github.com/commune-ai/subspace/blob/main/pallets/governance/src/dao.rs"
    click SubnetPricing "https://github.com/commune-ai/subspace/tree/main/pallets/subnet_emission/src/subnet_pricing/"
    click ManualSeal "https://github.com/commune-ai/subspace/blob/main/node/src/service/manual_seal.rs"
    click Decryption "https://github.com/commune-ai/subspace/blob/main/node/src/service/decrypter.rs"

    classDef runtime fill:#4a90e2
    classDef network fill:#4a90e2
    classDef consensus fill:#9b59b6
    classDef rpc fill:#4a90e2
    classDef pallet fill:#2ecc71
    classDef external fill:#e67e22
    classDef impl fill:#95a5a6
    classDef service fill:#95a5a6

    %% Legend
    subgraph Legend
        L1["Core Components"]:::runtime
        L2["Custom Pallets"]:::pallet
        L3["External Interfaces"]:::external
        L4["Implementation & Services"]:::impl
    end
```
