# sei-protocol/sei-chain architecture

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

- Interactive diagram: https://gitdiagram.com/sei-protocol/sei-chain
- Repository: https://github.com/sei-protocol/sei-chain

## Overview

##### High-Level Architecture Components

a. Core Components:
- Twin Turbo Consensus Engine
- Parallel EVM Runtime
- SeiDB (Custom State Database)
- CosmWasm Runtime
- Interoperability Layer

b. Module Layer (from /x directory):
- Oracle Module
- EVM Module
- Token Factory Module
- Mint Module
- Epoch Module

##### Key Relationships and Interactions

a. Data Flow:
- Transaction flow from client → consensus → parallel execution → state storage
- Interaction between EVM and CosmWasm environments
- Demonstrate how SeiDB interfaces with both execution environments

b. Cross-Module Communication:
- How the Oracle module feeds data to other modules
- Token Factory interactions with EVM contracts
- Epoch-based state transitions

##### Specific Implementation Details

a. Execution Layer:
- Optimistic execution components
- State verification mechanisms

b. Storage Layer:
- SeiDB architecture with read/write paths
- State versioning system
- Snapshot management

##### External Interfaces

a. Client APIs:
- EVM RPC endpoints (from /evmrpc)
- Cosmos SDK endpoints
- WebSocket connections
- Price oracle feeds

##### Component Details

a. Twin Turbo Consensus:
- 400ms block time optimization
- Validator set management
- Block propagation paths

b. Parallel EVM:
- Transaction dependency resolution
- Parallel execution paths
- State merkleization

c. SeiDB:
- Optimized storage structure
- Caching layers
- State pruning mechanisms

##### Integration Points

- IBC (Inter-Blockchain Communication) connections
- EVM bridge components
- Oracle data feeds
- External chain integrations

##### Deployment View

How components are distributed across:
- Validator nodes
- RPC nodes
- Oracle nodes
- Archive nodes

##### The seamless interoperability between EVM and CosmWasm

- Consensus layer
- Execution layer
- State management layer
- Application layer
- Network layer

Remember to include version control and upgrade paths, as evidenced by the upgrade handlers in the codebase (/app/upgrades directory).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Core Layer"
        TTC[Twin Turbo Consensus Engine]
        PEV[Parallel EVM Runtime]:::pevm
        SDB[SeiDB]:::seidb
        CWR[CosmWasm Runtime]:::cosmwasm
        IOL[Interoperability Layer]:::interop
    end

    subgraph "Module Layer"
        ORM[Oracle Module]:::oracle
        EVM[EVM Module]:::evm
        TFM[Token Factory Module]:::tokenfactory
        MNT[Mint Module]:::mint
        EPM[Epoch Module]:::epoch
    end

    subgraph "External Interfaces"
        EVMRPC[EVM RPC Endpoints]
        CSDK[Cosmos SDK Endpoints]
        WS[WebSocket Connections]
        POF[Price Oracle Feeds]
    end

    subgraph "Integration Points"
        IBC[IBC Connections]
        EVMB[EVM Bridge]
        ODF[Oracle Data Feeds]
        ECI[External Chain Integration]
    end

    subgraph "Deployment Nodes"
        VN[Validator Nodes]
        RN[RPC Nodes]
        ON[Oracle Nodes]
        AN[Archive Nodes]
    end

    %% Core Layer Relationships
    TTC --> PEV
    TTC --> SDB
    PEV --> SDB
    CWR --> SDB
    IOL --> PEV
    IOL --> CWR

    %% Module Layer Relationships
    ORM --> SDB
    EVM --> SDB
    TFM --> SDB
    MNT --> SDB
    EPM --> SDB

    %% External Interface Connections
    EVMRPC --> PEV
    CSDK --> IOL
    WS --> TTC
    POF --> ORM

    %% Integration Points Connections
    IBC --> IOL
    EVMB --> PEV
    ODF --> ORM
    ECI --> IOL

    %% Deployment Node Connections
    VN --> TTC
    RN --> EVMRPC
    ON --> ORM
    AN --> SDB

    %% Click Events
    click SDB "https://github.com/sei-protocol/sei-chain/blob/main/app/seidb.go"
    click EVM "https://github.com/sei-protocol/sei-chain/tree/main/x/evm/"
    click ORM "https://github.com/sei-protocol/sei-chain/tree/main/x/oracle/"
    click TFM "https://github.com/sei-protocol/sei-chain/tree/main/x/tokenfactory/"
    click MNT "https://github.com/sei-protocol/sei-chain/tree/main/x/mint/"
    click EPM "https://github.com/sei-protocol/sei-chain/tree/main/x/epoch/"
    click CWR "https://github.com/sei-protocol/sei-chain/tree/main/wasmbinding/"
    click PEV "https://github.com/sei-protocol/sei-chain/tree/main/x/evm/state/"
    click IOL "https://github.com/sei-protocol/sei-chain/tree/main/precompiles/"

    %% Styling
    classDef core fill:#2374ab
    classDef seidb fill:#ffb703,color:#000
    classDef pevm fill:#52b788
    classDef cosmwasm fill:#52b788
    classDef interop fill:#9d4edd
    classDef oracle fill:#ff6b6b
    classDef evm fill:#52b788
    classDef tokenfactory fill:#ff9e00
    classDef mint fill:#38b000
    classDef epoch fill:#9381ff

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[State Management]:::seidb
        L3[Execution Environments]:::pevm
        L4[Integration Layer]:::interop
        L5[Oracle Systems]:::oracle
    end
```
