# broxus/tycho architecture

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

- Interactive diagram: https://gitdiagram.com/broxus/tycho
- Repository: https://github.com/broxus/tycho

## Overview

##### Core Protocol Layer
- DAG implementation with its subcomponents:
- Anchor stage
- Commit mechanism
- Verifier
- Producer
- TVM execution environment

##### Network Layer (from /network directory)
- DHT (Distributed Hash Table) component
- Overlay network implementation
- Public overlay
- Private overlay
- Connection management
- Peer-to-peer communication

##### Storage Layer (from /storage directory)
- Block storage
- State storage
- Internal queue storage
- Mempool storage
- Connections to RocksDB

##### Collator Component (from /collator directory)
- Execution manager
- Internal queue management
- Mempool handling
- Validator implementation

##### Core Services (from /core directory)
- Block strider
- Blockchain RPC
- Overlay client

##### Layer Organization
- In vertical layers: Network → Consensus → Execution → Storage
- Cross-cutting concerns like RPC and CLI interfaces on the sides

##### Specific details
- DAG consensus flow
- Block processing pipeline
- Validator interaction patterns
- Storage hierarchy

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef network fill:#4CAF50,stroke:#2E7D32,color:white
    classDef storage fill:#FFC107,stroke:#FFA000,color:black
    classDef execution fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef external fill:#757575,stroke:#424242,color:white

    %% Legend
    subgraph Legend
        L1[Core Protocol]:::core
        L2[Network Layer]:::network
        L3[Storage Layer]:::storage
        L4[Execution Layer]:::execution
        L5[External]:::external
    end

    %% Network Layer
    subgraph NetworkLayer
        DHT["DHT Component"]:::network
        PubOverlay["Public Overlay"]:::network
        PrivOverlay["Private Overlay"]:::network
        ConnMgr["Connection Manager"]:::network
        P2P["P2P Communication"]:::network
    end

    %% Core Protocol Layer
    subgraph CoreProtocol
        DAG["DAG Implementation"]:::core
        Anchor["Anchor Stage"]:::core
        Commit["Commit Mechanism"]:::core
        Verifier["Verifier"]:::core
        Producer["Producer"]:::core
        TVM["TVM Environment"]:::core
    end

    %% Storage Layer
    subgraph StorageLayer
        BlockStore["Block Storage"]:::storage
        StateStore["State Storage"]:::storage
        QueueStore["Internal Queue Storage"]:::storage
        MempoolStore["Mempool Storage"]:::storage
        RocksDB[(RocksDB)]:::external
    end

    %% Collator Layer
    subgraph CollatorLayer
        ExecMgr["Execution Manager"]:::execution
        QueueMgr["Internal Queue Management"]:::execution
        MempoolHandler["Mempool Handler"]:::execution
        Validator["Validator"]:::execution
    end

    %% Core Services
    subgraph CoreServices
        BlockStrider["Block Strider"]:::core
        BlockchainRPC["Blockchain RPC"]:::core
        OverlayClient["Overlay Client"]:::core
    end

    %% Relationships
    DHT --> PubOverlay & PrivOverlay
    PubOverlay & PrivOverlay --> ConnMgr
    ConnMgr --> P2P

    DAG --> Anchor
    Anchor --> Commit
    Commit --> Verifier
    Verifier --> Producer
    Producer --> TVM

    BlockStore & StateStore & QueueStore & MempoolStore --> RocksDB

    ExecMgr --> TVM
    QueueMgr --> QueueStore
    MempoolHandler --> MempoolStore
    Validator --> Verifier

    BlockStrider --> BlockStore
    BlockchainRPC --> StateStore
    OverlayClient --> PubOverlay

    %% Click events
    click DAG "https://github.com/broxus/tycho/blob/master/consensus/src/dag/mod.rs"
    click Anchor "https://github.com/broxus/tycho/blob/master/consensus/src/dag/anchor_stage.rs"
    click Commit "https://github.com/broxus/tycho/blob/master/consensus/src/dag/commit/mod.rs"
    click Verifier "https://github.com/broxus/tycho/blob/master/consensus/src/dag/verifier.rs"
    click Producer "https://github.com/broxus/tycho/blob/master/consensus/src/dag/producer.rs"
    click DHT "https://github.com/broxus/tycho/blob/master/network/src/dht/mod.rs"
    click PubOverlay "https://github.com/broxus/tycho/blob/master/network/src/overlay/public_overlay.rs"
    click PrivOverlay "https://github.com/broxus/tycho/blob/master/network/src/overlay/private_overlay.rs"
    click ConnMgr "https://github.com/broxus/tycho/blob/master/network/src/network/connection_manager.rs"
    click P2P "https://github.com/broxus/tycho/blob/master/network/src/network/peer.rs"
    click BlockStore "https://github.com/broxus/tycho/blob/master/storage/src/store/block/mod.rs"
    click StateStore "https://github.com/broxus/tycho/blob/master/storage/src/store/shard_state/mod.rs"
    click QueueStore "https://github.com/broxus/tycho/blob/master/storage/src/store/internal_queue/mod.rs"
    click MempoolStore "https://github.com/broxus/tycho/blob/master/storage/src/store/mempool/mod.rs"
    click ExecMgr "https://github.com/broxus/tycho/blob/master/collator/src/collator/execution_manager.rs"
    click QueueMgr "https://github.com/broxus/tycho/blob/master/collator/src/internal_queue/mod.rs"
    click MempoolHandler "https://github.com/broxus/tycho/blob/master/collator/src/mempool/mod.rs"
    click Validator "https://github.com/broxus/tycho/blob/master/collator/src/validator/mod.rs"
    click BlockStrider "https://github.com/broxus/tycho/blob/master/core/src/block_strider/mod.rs"
    click BlockchainRPC "https://github.com/broxus/tycho/blob/master/core/src/blockchain_rpc/mod.rs"
    click OverlayClient "https://github.com/broxus/tycho/blob/master/core/src/overlay_client/mod.rs"
```
