# opentensor/bittensor architecture

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

- Interactive diagram: https://gitdiagram.com/opentensor/bittensor
- Repository: https://github.com/opentensor/bittensor

## Overview

##### Main Components

a. Core Components:
- Subtensor (Blockchain Interface)
- Axon (Network Server)
- Dendrite (Network Client)
- Metagraph (Network State)
- Synapse (Protocol Layer)

b. Supporting Systems:
- Chain Data Management
- Extrinsics Handler
- Utils & Configuration
- Registration System
- Logging System

##### Component Relationships

**┌─ Application Layer ─────────────────────────────────┐**
- Metagraph │ Configuration │ Settings │ ThreadPool   │
- Protocol Layer ──────────────────────────────────┐ │
- Axon │ Dendrite │ Synapse │ Tensor              │ │
- Blockchain Interface Layer ────────────────────┐ │ │
- Subtensor │ AsyncSubtensor │ Stream           │ │ │
- Chain Data Layer ──────────────────────────┐ │ │ │
- NeuronInfo │ StakeInfo │ SubnetInfo       │ │ │ │
- Extrinsics Layer ────────────────────────┐ │ │ │ │
- Registration │ Weights │ Transfer        │ │ │ │ │
- ┘ │ │ │ │
- ┘ │ │ │
- ┘ │

- ┘

##### Key Interactions to Highlight

a. Data Flow:
- How data flows from miners through Axon/Dendrite
- Blockchain interaction patterns
- Demonstrate weight setting and transfer mechanisms

b. Control Flow:
- Registration process flow
- Consensus mechanism interaction
- Subnet validation flow

##### Implementation Details

- Component version information
- Key dependencies (PyTorch, etc.)
- External service connections
- API endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#2374ab,color:white
    classDef protocol fill:#7209b7,color:white
    classDef blockchain fill:#4caf50,color:white
    classDef data fill:#ffd700,color:black
    classDef utils fill:#ff9800,color:white
    
    %% Application Layer
    subgraph AppLayer["Application Layer"]
        Meta["Metagraph"]
        Config["Configuration"]
        Settings["Settings"]
        ThreadPool["Thread Pool"]
    end

    %% Protocol Layer
    subgraph ProtocolLayer["Protocol Layer"]
        Axon["Axon Server"]
        Dendrite["Dendrite Client"]
        Synapse["Synapse Protocol"]
        Tensor["Tensor Processing"]
    end

    %% Blockchain Interface Layer
    subgraph BlockchainLayer["Blockchain Interface Layer"]
        Subtensor["Subtensor"]
        AsyncSub["Async Subtensor"]
        Stream["Network Stream"]
    end

    %% Chain Data Layer
    subgraph DataLayer["Chain Data Layer"]
        NeuronInfo["Neuron Info"]
        StakeInfo["Stake Info"]
        SubnetInfo["Subnet Info"]
    end

    %% Extrinsics Layer
    subgraph ExtrinsicsLayer["Extrinsics Layer"]
        Registration["Registration"]
        Weights["Weights"]
        Transfer["Transfer"]
    end

    %% Utility Components
    subgraph UtilsLayer["Utility Layer"]
        Utils["Utils"]
        Logging["Logging"]
    end

    %% Relationships
    Meta --> Subtensor
    Meta --> AsyncSub
    Axon --> Synapse
    Dendrite --> Synapse
    Subtensor --> DataLayer
    AsyncSub --> DataLayer
    ExtrinsicsLayer --> BlockchainLayer
    ProtocolLayer --> BlockchainLayer
    Config --> Utils
    Settings --> Utils
    ThreadPool --> ProtocolLayer
    Stream --> BlockchainLayer
    Logging --> Utils

    %% Click Events
    click Meta "https://github.com/opentensor/bittensor/blob/master/bittensor/core/metagraph.py"
    click Config "https://github.com/opentensor/bittensor/blob/master/bittensor/core/config.py"
    click Settings "https://github.com/opentensor/bittensor/blob/master/bittensor/core/settings.py"
    click ThreadPool "https://github.com/opentensor/bittensor/blob/master/bittensor/core/threadpool.py"
    click Axon "https://github.com/opentensor/bittensor/blob/master/bittensor/core/axon.py"
    click Dendrite "https://github.com/opentensor/bittensor/blob/master/bittensor/core/dendrite.py"
    click Synapse "https://github.com/opentensor/bittensor/blob/master/bittensor/core/synapse.py"
    click Subtensor "https://github.com/opentensor/bittensor/blob/master/bittensor/core/subtensor.py"
    click AsyncSub "https://github.com/opentensor/bittensor/blob/master/bittensor/core/async_subtensor.py"
    click Stream "https://github.com/opentensor/bittensor/blob/master/bittensor/core/stream.py"
    click Utils "https://github.com/opentensor/bittensor/tree/master/bittensor/utils/"
    click Logging "https://github.com/opentensor/bittensor/tree/master/bittensor/utils/btlogging/"
    click Registration "https://github.com/opentensor/bittensor/tree/master/bittensor/utils/registration/"
    click DataLayer "https://github.com/opentensor/bittensor/tree/master/bittensor/core/chain_data/"
    click ExtrinsicsLayer "https://github.com/opentensor/bittensor/tree/master/bittensor/core/extrinsics/"

    %% Style Applications
    class Meta,ThreadPool core
    class Axon,Dendrite,Synapse,Tensor protocol
    class Subtensor,AsyncSub,Stream blockchain
    class NeuronInfo,StakeInfo,SubnetInfo data
    class Utils,Config,Settings,Logging utils

    %% Legend
    subgraph Legend
        CoreComp["Core Components"]
        ProtocolComp["Protocol Components"]
        BlockchainComp["Blockchain Components"]
        DataComp["Data Components"]
        UtilsComp["Utility Components"]
    end
    
    class CoreComp core
    class ProtocolComp protocol
    class BlockchainComp blockchain
    class DataComp data
    class UtilsComp utils
```
