# axieinfinity/ronin architecture

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

- Interactive diagram: https://gitdiagram.com/axieinfinity/ronin
- Repository: https://github.com/axieinfinity/ronin

## Overview

##### Main Components
- Node & Networking: The “node” component (node/, p2p/, enode/, dnsdisc/) is responsible for managing peer-to-peer communication, discovery, and network interactions. Represent a “P2P Networking” block which includes discovery protocols, node communication, and transport management.
- Consensus Engine: Inside folders like consensus/ (with sub-folders for clique, ethash, consortium, etc.), the project implements multiple consensus algorithms. Include a “Consensus” module that shows how blocks are validated and finalized using mechanisms like Delegated Proof of Stake (as described in the README) and other protocols.
- Blockchain & State Management: The core blockchain logic is found in folders such as core/ (blockchain, state, rawdb, trie, rlp) and common/. This module manages the chain of blocks, state transitions, and the storage layer (both the state trie and raw data stored in databases). Label these modules accordingly – e.g. “Blockchain Core”, “State Database & Trie Storage”, and “RLP (data encoding).”
- Virtual Machine Execution: The EVM and its associated virtual machine logic are encapsulated in core/vm/ and cmd/evm. Indicate an “EVM Execution Engine” which processes smart contract bytecode and opcode instructions.
- Cryptographic & Account Management: There are dedicated folders for cryptography (crypto/, accounts/, keystore, bls, bn256, secp256k1, etc.) and account management (including wallet and signature utilities). Represent a “Cryptography & Account Services” component.
- Auxiliary tools & Utilities: Other modules, including debugging tools, metrics (metrics/), logging (log/), and additional utilities, form supporting infrastructure. Represent these as peripheral components which support monitoring, diagnostics, and build operations.

##### Relationships and Data Flows
- The CLI (ronin executable) serves as the orchestrator: it starts the node, sets up RPC servers, and integrates with the consensus and state layers.
- Data flow from the “P2P Networking” module feeds into the “Consensus” layer where incoming blocks are validated.
- The “Blockchain Core” uses data provided by consensus, and updates the "State Database" when new blocks are applied.
- The “EVM Execution Engine” interacts with the blockchain core to process transactions and smart contracts.
- The “RPC API” layer sits on top and provides programmatic access to the core components (node, blockchain, state, and EVM).
- Cryptographic modules support account management, signing via “clef” and the transaction signing processes needed by other components.

##### Architectural Patterns and Design Principles
- Layered Architecture: Show how the lower-level components (network, consensus, storage) feed upward into higher-level services (EVM, APIs, command interfaces).

##### Technologies and Frameworks
- Golang is the primary language.
- JSON-RPC interfaces (HTTP, WS, IPC).
- Standard crypto libraries and specialized crypto (BLS, secp256k1, BN256).
- RLP encoding for data serialization.
- The consensus mechanisms include both Ethash (for PoW experiments) and Delegated Proof of Stake (for Ronin’s production).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Top Layer: API & CLI"
        CLI["CLI/Entry Point"]:::cli
        RPC["RPC API Layer"]:::rpc
    end

    subgraph "Middle Layer: Blockchain, State & Execution"
        BLOCKCHAIN["Blockchain Core & State Management"]:::blockchain
        EVM["EVM Execution Engine"]:::evm
        CRYPTO["Crypto & Account Services"]:::crypto
    end

    subgraph "Bottom Layer: Networking & Consensus"
        NETWORK["P2P Networking & Discovery"]:::networking
        CONSENSUS["Consensus Engine"]:::consensus
    end

    subgraph "Auxiliary Tools & Utilities"
        AUX["Auxiliary Tools, Utilities & Logging"]:::aux
    end

    CLI -->|"starts"| NETWORK
    CLI -->|"initiates"| RPC
    NETWORK -->|"feedsInto"| CONSENSUS
    CONSENSUS -->|"updatesChain"| BLOCKCHAIN
    EVM -->|"executes"| BLOCKCHAIN
    BLOCKCHAIN -->|"feedback"| EVM
    RPC -->|"queries"| BLOCKCHAIN
    RPC -->|"queries"| EVM
    CLI -->|"uses"| CRYPTO
    RPC -->|"uses"| CRYPTO
    AUX -->|"supports"| CLI
    AUX -->|"supports"| RPC

    click CLI "https://github.com/axieinfinity/ronin/tree/master/cmd/ronin"
    click RPC "https://github.com/axieinfinity/ronin/tree/master/rpc/"
    click NETWORK "https://github.com/axieinfinity/ronin/tree/master/p2p/"
    click CONSENSUS "https://github.com/axieinfinity/ronin/tree/master/consensus/"
    click BLOCKCHAIN "https://github.com/axieinfinity/ronin/tree/master/core/"
    click EVM "https://github.com/axieinfinity/ronin/tree/master/core/vm/"
    click CRYPTO "https://github.com/axieinfinity/ronin/tree/master/crypto/"
    click AUX "https://github.com/axieinfinity/ronin/tree/master/metrics/"

    classDef cli fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef rpc fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef evm fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef crypto fill:#ff99cc,stroke:#333,stroke-width:2px;
    classDef networking fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef consensus fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef aux fill:#e8daef,stroke:#333,stroke-width:2px;
```
