# hyle-org/hyle architecture

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

- Interactive diagram: https://gitdiagram.com/hyle-org/hyle
- Repository: https://github.com/hyle-org/hyle

## Overview

##### Main Components

a) Core Node Components:
- Consensus Module (/src/consensus)
- Data Availability Layer (/src/data_availability)
- Mempool (/src/mempool)
- Node State Management (/src/node_state)
- P2P Network Layer (/src/p2p)
- REST API Interface (/src/rest.rs)
- TCP Server (/src/tcp_server.rs)

b) Smart Contract Infrastructure:
- Contract SDK (/crates/contract-sdk)
- Contract Runner (/crates/bonsai-runner)
- Built-in Contracts (/crates/contracts/*)

c) Client Components:
- Client SDK (/crates/client-sdk)
- Transaction Builder
- REST/TCP Clients

d) Supporting Services:
- Indexer Service (/src/indexer)
- PostgreSQL Database
- Monitoring Stack (Prometheus & Grafana)

**[External Clients/dApps Layer]**
- ↕
**[Client SDK Layer]**
- ↕
**[Node Interface Layer (REST/TCP)]**
- ↕
**[Core Node Layer]**
- ↕
**[Infrastructure Layer]**

##### Specific Implementation Details

a) Node Architecture:
**[P2P Network] ←→ [Consensus] ←→ [Node State]**
- ↕             ↕              ↕
**[Mempool] ←→ [Data Availability] ←→ [Contract Execution]**

b) Smart Contract Flow:
**[Contract SDK] → [Contract Runner] → [Node State]**
- ↓
- [Data Availability]

c) Client Interaction Flow:
**[Client SDK] → [Transaction Builder]**
- ↓
**[REST/TCP Client] → [Node Interface]**

##### Additional Elements

- Configuration management (/src/utils/conf.rs)
- Cryptographic utilities (/src/utils/crypto.rs)
- Monitoring endpoints
- Database connections

##### Important Notes

- Distinction between single-node devnet and full consensus mode
- Modular nature of the system (using the crates structure)
- Integration points with external systems
- Monitoring and observability touchpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef client fill:#4CAF50,stroke:#2E7D32,color:white
    classDef contract fill:#FFC107,stroke:#FFA000,color:black
    classDef infra fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef interface fill:#00BCD4,stroke:#0097A7,color:white
    classDef utils fill:#FF5722,stroke:#E64A19,color:white

    %% External Layer
    subgraph ExternalLayer["External Applications Layer"]
        dApps["dApps & External Applications"]
    end

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        ClientSDK["Client SDK"]:::client
        TxBuilder["Transaction Builder"]:::client
        RestClient["REST Client"]:::client
        TCPClient["TCP Client"]:::client
    end

    %% Interface Layer
    subgraph InterfaceLayer["Node Interface Layer"]
        REST["REST API"]:::interface
        TCP["TCP Server"]:::interface
    end

    %% Core Layer
    subgraph CoreLayer["Core Node Layer"]
        P2P["P2P Network"]:::core
        Consensus["Consensus Module"]:::core
        NodeState["Node State"]:::core
        Mempool["Mempool"]:::core
        DataAvail["Data Availability"]:::core
    end

    %% Contract Layer
    subgraph ContractLayer["Smart Contract Layer"]
        ContractSDK["Contract SDK"]:::contract
        ContractRunner["Contract Runner"]:::contract
        BuiltInContracts["Built-in Contracts"]:::contract
        subgraph Contracts["Contract Types"]
            AMM["AMM Contract"]:::contract
            Staking["Staking Contract"]:::contract
            Identity["Identity Contract"]:::contract
            Hyllar["Hyllar Contract"]:::contract
        end
    end

    %% Infrastructure Layer
    subgraph InfraLayer["Infrastructure Layer"]
        Indexer["Indexer Service"]:::infra
        Monitoring["Monitoring Stack"]:::infra
        PostgreSQL["PostgreSQL Database"]:::infra
        Utils["Utilities"]:::utils
    end

    %% Connections
    dApps --> ClientSDK
    ClientSDK --> TxBuilder
    ClientSDK --> RestClient
    ClientSDK --> TCPClient
    RestClient --> REST
    TCPClient --> TCP
    REST --> NodeState
    TCP --> NodeState
    P2P <--> Consensus
    Consensus <--> NodeState
    NodeState <--> DataAvail
    Mempool <--> DataAvail
    P2P <--> Mempool
    NodeState <--> ContractRunner
    ContractSDK --> ContractRunner
    ContractRunner --> DataAvail
    NodeState --> Indexer
    Indexer --> PostgreSQL
    Utils --> CoreLayer

    %% Click Events
    click ClientSDK "https://github.com/Hyle-org/hyle/tree/main//crates/client-sdk/"
    click TxBuilder "https://github.com/Hyle-org/hyle/blob/main//crates/client-sdk/src/transaction_builder.rs"
    click RestClient "https://github.com/Hyle-org/hyle/blob/main//crates/client-sdk/src/rest_client.rs"
    click TCPClient "https://github.com/Hyle-org/hyle/blob/main//crates/client-sdk/src/tcp_client.rs"
    click REST "https://github.com/Hyle-org/hyle/blob/main//src/rest.rs"
    click TCP "https://github.com/Hyle-org/hyle/blob/main//src/tcp_server.rs"
    click P2P "https://github.com/Hyle-org/hyle/tree/main//src/p2p/"
    click Consensus "https://github.com/Hyle-org/hyle/tree/main//src/consensus/"
    click NodeState "https://github.com/Hyle-org/hyle/tree/main//src/node_state/"
    click Mempool "https://github.com/Hyle-org/hyle/tree/main//src/mempool/"
    click DataAvail "https://github.com/Hyle-org/hyle/tree/main//src/data_availability/"
    click ContractSDK "https://github.com/Hyle-org/hyle/tree/main//crates/contract-sdk/"
    click ContractRunner "https://github.com/Hyle-org/hyle/tree/main//crates/bonsai-runner/"
    click BuiltInContracts "https://github.com/Hyle-org/hyle/tree/main//crates/contracts/"
    click AMM "https://github.com/Hyle-org/hyle/tree/main//crates/contracts/amm/"
    click Staking "https://github.com/Hyle-org/hyle/tree/main//crates/contracts/staking/"
    click Identity "https://github.com/Hyle-org/hyle/tree/main//crates/contracts/hydentity/"
    click Hyllar "https://github.com/Hyle-org/hyle/tree/main//crates/contracts/hyllar/"
    click Indexer "https://github.com/Hyle-org/hyle/tree/main//src/indexer/"
    click Monitoring "https://github.com/Hyle-org/hyle/tree/main//tools/observability/"
    click Utils "https://github.com/Hyle-org/hyle/tree/main//src/utils/"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Client Components"]:::client
        L3["Contract Components"]:::contract
        L4["Infrastructure"]:::infra
        L5["Interfaces"]:::interface
        L6["Utilities"]:::utils
    end
```
