# berachain/beacon-kit architecture

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

- Interactive diagram: https://gitdiagram.com/berachain/beacon-kit
- Repository: https://github.com/berachain/beacon-kit

## Overview

##### Main Components

- Core Consensus & Beacon Logic:
– Directories: “beacon”, “consensus” (including “consensus-types” and “cometbft”), “node-core”, and “state-transition”.
– These contain logic for initializing chains, processing proposals, handling deposit operations, validator operations, and all consensus-related state transitions.

- Execution Integration:
– Directories: “execution” and “geth-primitives” (with alternative execution clients integration).
– This layer implements the Ethereum Engine API for interacting with external execution clients.

- Command-Line & Configuration Interfaces:
– Directories: “cli”, “cmd”, “config”.
– These modules handle user inputs, start-up routines, build configurations, and serve as an entry point for the node (e.g., “cmd/beacond”).

- API and Service Handlers:
– Directories: “node-api”, “node-core/components”, “observability”.
– These modules expose HTTP handlers, JSON-RPC endpoints, management interfaces, and metrics reporting endpoints.

- Data Availability, Storage & Primitives:
– Directories: “da”, “storage”, “primitives”, “engine-primitives”, “payload”.
– They handle encoding, crypto primitives, state and storage layers, as well as providing low-level utilities for digital signatures, merkle trees, and BLS cryptography.

- Testing and Network Orchestration:
– Directories: “testing” and “kurtosis”.
– They focus on local devnet setups, end-to-end tests, simulation environments, and multi-node network scripts.

- Smart Contracts:
– Directory: “contracts”.
– These are used for deposit operations and staking contracts, integrating on-chain aspects within the ecosystem.

##### Establish Relationships and Data Flows

- CLI layer as the entry point that interacts with both configuration and service spawning modules (node-api and node-core).
- Out the internal flow from payload construction/processing (found in “payload” and “chain”) through state transitions (“state-transition”) up to storage.
- Testing and network orchestration as separate yet connected components that allow simulation and real testing environments.

##### Architectural Patterns and Design Principles

- Modularization: Emphasize how the project cleanly separates concerns (e.g., consensus, execution, CLI, network orchestration) into individual modules.
- Interface-based design: Illustrate the use of interfaces (note the “interfaces.go” files in multiple directories) that allow for dependency inversion and interchangeable implementations (such as for deposit handling or state processing).
- Extensibility: Mark areas where extensible plug-ins exist (e.g., support for multiple execution clients, diverse consensus layers such as CometBFT integration).
- Layering: The architecture can be rendered in layers – the lower-level primitives and crypto utilities, a core engine layer (consensus/state transition), an integration layer (execution, API), and finally the service/CLI layer.

##### Relevant Technologies, Frameworks, and Libraries

- GoLang as the programming language – shown by the “.go” files and “go.mod”.
- Docker & Dockerfile for containerization.
- Kurtosis for orchestrating multi-node devnets.
- Ethereum Engine API for execution client integration.
- Standard paradigms for state management, configuration (viper-based parsing in “config/viper”), and testing (e.g., the “testing” directories with benchmarks and E2E tests).

##### Final Advice

- Be very detailed: Aim to capture every essential architectural block. Taking the time to break down the major directories and grouping them logically will help expose critical design patterns, dependencies, and integration points.
- Don’t overcomplicate: While the structure is extensive, start with broad strokes (main layers) and then drill down into sub-components (like within node-core or the consensus and execution modules).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core Consensus & Beacon Logic
    subgraph "Core Consensus & Beacon Logic"
        A1["Beacon (beacon)"]:::consensus
        A2["Consensus (consensus)"]:::consensus
        A3["CometBFT Integration (consensus/cometbft)"]:::consensus
        A4["Node Core (node-core)"]:::consensus
        A5["State Transition (state-transition)"]:::consensus
    end

    %% Execution Integration
    subgraph "Execution Integration"
        B1["Execution (execution)"]:::execution
        B2["Geth Primitives (geth-primitives)"]:::execution
    end

    %% Command-Line & Configuration Interfaces
    subgraph "Command-Line & Configuration Interfaces"
        C1["CLI Interface (cli)"]:::cli
        C2["CMD Entry Point (cmd/beacond)"]:::cli
        C3["Configuration (config)"]:::cli
    end

    %% API and Service Handlers
    subgraph "API and Service Handlers"
        D1["Node API Services (node-api)"]:::api
        D2["Node Core Components (node-core/components)"]:::api
        D3["Observability (observability)"]:::api
    end

    %% Data Availability, Storage & Primitives
    subgraph "Data Availability, Storage & Primitives"
        E1["Data Availability (da)"]:::data
        E2["Storage (storage)"]:::data
        E3["Primitives (primitives)"]:::data
        E4["Engine Primitives (engine-primitives)"]:::data
        E5["Payload Building (payload)"]:::data
    end

    %% Testing and Network Orchestration
    subgraph "Testing and Network Orchestration"
        F1["Testing (testing)"]:::testing
        F2["Network Orchestration (kurtosis)"]:::testing
    end

    %% Smart Contracts
    subgraph "Smart Contracts"
        G1["Smart Contracts (contracts)"]:::contracts
    end

    %% Relationships
    %% CLI & Config interactions
    C1 --> C2
    C1 --> C3
    C1 -->|"init"| D1
    C1 -->|"spawns"| A4

    %% Consensus to Execution Integration via Engine API
    A2 -->|"EngineAPI"| B1
    A2 -->|"EngineAPI"| B2

    %% Payload flow: Payload -> State Transition -> Storage
    E5 -->|"process"| A5
    A5 -->|"update"| E2

    %% Lower-level libraries feeding into Consensus & Node Core
    E3 -->|"support"| A1
    E4 -->|"support"| A1
    E1 -->|"feed"| A1
    E3 -->|"support"| A4
    E4 -->|"support"| A4
    E1 -->|"feed"| A4

    %% Observability monitoring
    A4 -->|"report"| D3
    D1 -->|"monitor"| D3

    %% Testing & Orchestration relationships
    F1 -->|"validate"| A4
    F2 -->|"orchestrate"| A4

    %% Smart Contracts interacting with Consensus operations
    G1 -->|"interact"| A2

    %% API Services binding with Node Core Components
    D2 -->|"bind"| A4

    %% Internal Consensus component interactions
    A1 -->|"sync"| A2
    A2 -->|"delegate"| A3

    %% Click Events
    click A1 "https://github.com/berachain/beacon-kit/tree/main//beacon"
    click A2 "https://github.com/berachain/beacon-kit/tree/main//consensus"
    click A3 "https://github.com/berachain/beacon-kit/tree/main//consensus/cometbft"
    click A4 "https://github.com/berachain/beacon-kit/tree/main//node-core"
    click A5 "https://github.com/berachain/beacon-kit/tree/main//state-transition"

    click B1 "https://github.com/berachain/beacon-kit/tree/main//execution"
    click B2 "https://github.com/berachain/beacon-kit/tree/main//geth-primitives"

    click C1 "https://github.com/berachain/beacon-kit/tree/main//cli"
    click C2 "https://github.com/berachain/beacon-kit/tree/main//cmd/beacond"
    click C3 "https://github.com/berachain/beacon-kit/tree/main//config"

    click D1 "https://github.com/berachain/beacon-kit/tree/main//node-api"
    click D2 "https://github.com/berachain/beacon-kit/tree/main//node-core/components"
    click D3 "https://github.com/berachain/beacon-kit/tree/main//observability"

    click E1 "https://github.com/berachain/beacon-kit/tree/main//da"
    click E2 "https://github.com/berachain/beacon-kit/tree/main//storage"
    click E3 "https://github.com/berachain/beacon-kit/tree/main//primitives"
    click E4 "https://github.com/berachain/beacon-kit/tree/main//engine-primitives"
    click E5 "https://github.com/berachain/beacon-kit/tree/main//payload"

    click F1 "https://github.com/berachain/beacon-kit/tree/main//testing"
    click F2 "https://github.com/berachain/beacon-kit/tree/main//kurtosis"

    click G1 "https://github.com/berachain/beacon-kit/tree/main//contracts"

    %% Styles
    classDef consensus fill:#ffcccc,stroke:#ff0000,stroke-width:2px;
    classDef execution fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef cli fill:#ccccff,stroke:#0000ff,stroke-width:2px;
    classDef api fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef data fill:#e0ffff,stroke:#008080,stroke-width:2px;
    classDef testing fill:#ffe0cc,stroke:#cc6600,stroke-width:2px;
    classDef contracts fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
```
