# commune-ai/communex architecture

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

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

## Overview

##### Main Components

a) CLI Layer
- As the top-level interface
- Six main command groups: balance, key, module, network, subnet, and misc

b) Core SDK Layer
- Below the CLI layer
- Main functional components:
- Key Management System
- Balance Management
- Module Management
- Network Interface
- Subnet Management
- Client Interface

c) Module System
- Modular architecture
- Both client and server components
- Rate limiters and protocol handlers

d) Compatibility Layer
- Integration with original Commune AI
- Storage and type compatibility

##### Component Relationships

- Module System → Network (external connection)
- Compatibility Layer ↔ Core SDK (bidirectional compatibility interface)

##### Specific Implementation Details

Technical elements:
**┌─────────────────────────────────────────────┐**
- CLI Layer                  │
- ┌─────┐ ┌────┐ ┌──────┐ ┌─────┐ ┌───────┐ │
- Balance│ │Key │ │Module│ │Network│ │Subnet│ │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Core SDK Layer                │
- ┌─────────────┐ ┌────────────────────────┐ │
- Key Management│ │Balance Management      │ │
- Module System │ │Network Interface       │ │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Module System                  │
- ┌──────────┐  ┌─────────┐  ┌────────────┐ │
- Client  │←→│ Server  │←→│Rate Limiter│ │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- Compatibility Layer               │
- ┌────────────┐  ┌─────────────────────┐    │
- Key Storage │  │Type Compatibility   │    │
- ┘

##### Additional Elements

Supporting components:
- External interfaces (network connections)
- Configuration management
- Testing framework integration
- Documentation generation system

##### Important Notes

- The modular nature of the system
- Clear separation between CLI and SDK functionality
- Compatibility with the original Commune AI system
- The role of the module system in extending functionality

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef cli fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef module fill:#FFA500,stroke:#333,stroke-width:2px
    classDef compat fill:#FFD700,stroke:#333,stroke-width:2px
    classDef support fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% CLI Layer
    subgraph CLI
        MainCLI["Main CLI"]
        BalanceCmd["Balance Commands"]
        KeyCmd["Key Commands"]
        ModuleCmd["Module Commands"]
        NetworkCmd["Network Commands"]
        SubnetCmd["Subnet Commands"]
        MiscCmd["Misc Commands"]
    end

    %% Core SDK Layer
    subgraph CoreSDK
        BalanceMgmt["Balance Management"]
        KeyMgmt["Key Management"]
        ClientInterface["Client Interface"]
        NetworkMisc["Network/Misc Functions"]
    end

    %% Module System
    subgraph ModuleSystem
        ProtocolHandler["Protocol Handler"]
        ClientComp["Client Component"]
        ServerComp["Server Component"]
        RateLimiter["Rate Limiters"]
        ModuleRouter["Module Router"]
    end

    %% Compatibility Layer
    subgraph Compat
        KeyStorage["Key Storage"]
        KeyCompat["Key Compatibility"]
        TypeCompat["Type Compatibility"]
        UtilFuncs["Utility Functions"]
    end

    %% Supporting Components
    subgraph Support
        ErrorHandling["Error Handling"]
        TypeDefs["Type Definitions"]
        UtilityFuncs["Utility Functions"]
        CommonFuncs["Common Functions"]
    end

    %% Relationships
    CLI --> CoreSDK
    CoreSDK <--> ModuleSystem
    ModuleSystem <--> Compat
    CoreSDK <--> Compat
    Support --> CoreSDK
    Support --> ModuleSystem
    Support --> Compat

    %% Click events
    click MainCLI "https://github.com/commune-ai/communex/blob/main/src/communex/cli/__main__.py"
    click BalanceCmd "https://github.com/commune-ai/communex/blob/main/src/communex/cli/balance.py"
    click KeyCmd "https://github.com/commune-ai/communex/blob/main/src/communex/cli/key.py"
    click ModuleCmd "https://github.com/commune-ai/communex/blob/main/src/communex/cli/module.py"
    click NetworkCmd "https://github.com/commune-ai/communex/blob/main/src/communex/cli/network.py"
    click SubnetCmd "https://github.com/commune-ai/communex/blob/main/src/communex/cli/subnet.py"
    click MiscCmd "https://github.com/commune-ai/communex/blob/main/src/communex/cli/misc.py"
    click BalanceMgmt "https://github.com/commune-ai/communex/blob/main/src/communex/balance.py"
    click KeyMgmt "https://github.com/commune-ai/communex/blob/main/src/communex/key.py"
    click ClientInterface "https://github.com/commune-ai/communex/blob/main/src/communex/client.py"
    click NetworkMisc "https://github.com/commune-ai/communex/blob/main/src/communex/misc.py"
    click ProtocolHandler "https://github.com/commune-ai/communex/blob/main/src/communex/module/_protocol.py"
    click ClientComp "https://github.com/commune-ai/communex/blob/main/src/communex/module/client.py"
    click ServerComp "https://github.com/commune-ai/communex/blob/main/src/communex/module/server.py"
    click RateLimiter "https://github.com/commune-ai/communex/blob/main/src/communex/module/_rate_limiters/limiters.py"
    click ModuleRouter "https://github.com/commune-ai/communex/blob/main/src/communex/module/routers/module_routers.py"
    click KeyStorage "https://github.com/commune-ai/communex/blob/main/src/communex/compat/storage.py"
    click KeyCompat "https://github.com/commune-ai/communex/blob/main/src/communex/compat/key.py"
    click TypeCompat "https://github.com/commune-ai/communex/blob/main/src/communex/compat/types.py"
    click UtilFuncs "https://github.com/commune-ai/communex/blob/main/src/communex/compat/_util.py"
    click ErrorHandling "https://github.com/commune-ai/communex/blob/main/src/communex/errors.py"
    click TypeDefs "https://github.com/commune-ai/communex/blob/main/src/communex/types.py"
    click UtilityFuncs "https://github.com/commune-ai/communex/blob/main/src/communex/util/__init__.py"
    click CommonFuncs "https://github.com/commune-ai/communex/blob/main/src/communex/_common.py"

    %% Style applications
    class MainCLI,BalanceCmd,KeyCmd,ModuleCmd,NetworkCmd,SubnetCmd,MiscCmd cli
    class BalanceMgmt,KeyMgmt,ClientInterface,NetworkMisc core
    class ProtocolHandler,ClientComp,ServerComp,RateLimiter,ModuleRouter module
    class KeyStorage,KeyCompat,TypeCompat,UtilFuncs compat
    class ErrorHandling,TypeDefs,UtilityFuncs,CommonFuncs support
```
