# leisuremeta/leisuremeta-chain architecture

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

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

## Overview

##### High-Level Components

a. Core Blockchain Components:
- Node Module (modules/node)
- API Layer (modules/api)
- Library Components (modules/lib)
- Node Proxy (modules/node-proxy)

b. Gateway Components:
- ETH Gateway System (modules/eth-gateway-*)

c. Explorer Components:
- LMScan Backend (modules/lmscan-backend)
- LMScan Frontend (modules/lmscan-frontend)

##### Core Architecture Details
Within the Node component, show these subcomponents:

a. DApp Layer:
- PlayNommDApp
- Submodules (Account, Agenda, CreatorDao, Group, Reward, Token, Voting)

b. Services Layer:
- BlockService
- TransactionService
- StateReadService
- RewardService
- LocalStatusService

c. Repository Layer:
- BlockRepository
- StateRepository
- TransactionRepository

d. Storage Layer:
- HashStore
- KeyValueStore
- Store Interpreters (Redis, Sway, Multi)

##### Data Flow Connections
- Transaction flow from API through Node Proxy to Nodes
- State updates from Node to Storage
- Data flow to Explorer components
- ETH Gateway interaction with main chain

##### Special Architectural Elements
Unique features:

a. Merkle-Patricia Trie Structure:
- How it combines UTXO and account data
- State snapshot storage

b. Consensus Mechanism:
- Interaction between nodes
- Validation process

##### Component Interactions
Specific interactions:
- API endpoints connecting to Node Proxy
- Node Proxy load balancing to Nodes
- ETH Gateway deposit/withdraw flow
- Explorer data collection path

##### Technical Stack Indicators
Technology labels:
- Scala/ScalaJS
- Redis
- Ethereum compatibility layer
- Frontend technologies

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core ["Core Blockchain Components"]
        direction TB
        API["API Layer"]
        NP["Node Proxy"]
        Node["Node Module"]
        Lib["Library Components"]
    end

    subgraph Gateway ["Gateway Components"]
        direction TB
        ETHGateway["ETH Gateway System"]
        GatewayCommon["Gateway Common"]
        GatewayDeposit["Gateway Deposit"]
        GatewayWithdraw["Gateway Withdraw"]
    end

    subgraph Explorer ["Explorer Components"]
        direction TB
        LMScanBE["LMScan Backend"]
        LMScanFE["LMScan Frontend"]
    end

    subgraph NodeInternals ["Node Module Internals"]
        direction TB
        subgraph DApp ["DApp Layer"]
            PlayNomm["PlayNommDApp"]
            DAppModules["Submodules"]
        end

        subgraph Services ["Services Layer"]
            BlockSvc["BlockService"]
            TxSvc["TransactionService"]
            StateSvc["StateReadService"]
            RewardSvc["RewardService"]
            LocalSvc["LocalStatusService"]
        end

        subgraph Repos ["Repository Layer"]
            BlockRepo["BlockRepository"]
            StateRepo["StateRepository"]
            TxRepo["TransactionRepository"]
        end

        subgraph Storage ["Storage Layer"]
            HashStr["HashStore"]
            KVStore["KeyValueStore"]
            StoreInt["Store Interpreters"]
        end

        MerkleTrie["Merkle-Patricia Trie"]
    end

    %% Connections
    API --> NP
    NP --> Node
    Node --> NodeInternals
    ETHGateway --> Node
    Node --> LMScanBE
    LMScanBE --> LMScanFE

    %% Internal Connections
    DApp --> Services
    Services --> Repos
    Repos --> Storage
    MerkleTrie --> Storage

    %% Gateway Connections
    GatewayCommon --- GatewayDeposit
    GatewayCommon --- GatewayWithdraw
    
    %% Click Events
    click API "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/api/"
    click NP "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/node-proxy/"
    click Node "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/node/"
    click Lib "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/lib/"
    click ETHGateway "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/eth-gateway/"
    click GatewayCommon "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/eth-gateway-common/"
    click GatewayDeposit "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/eth-gateway-deposit/"
    click GatewayWithdraw "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/eth-gateway-withdraw/"
    click LMScanBE "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/lmscan-backend/"
    click LMScanFE "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/lmscan-frontend/"
    click PlayNomm "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/dapp/PlayNommDApp.scala"
    click DAppModules "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/node/src/main/scala/io/leisuremeta/chain/node/dapp/submodule/"
    click BlockSvc "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/service/BlockService.scala"
    click TxSvc "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/service/TransactionService.scala"
    click StateSvc "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/service/StateReadService.scala"
    click RewardSvc "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/service/RewardService.scala"
    click LocalSvc "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/service/LocalStatusService.scala"
    click BlockRepo "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/repository/BlockRepository.scala"
    click StateRepo "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/repository/StateRepository.scala"
    click TxRepo "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/repository/TransactionRepository.scala"
    click HashStr "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/store/HashStore.scala"
    click KVStore "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/node/src/main/scala/io/leisuremeta/chain/node/store/KeyValueStore.scala"
    click StoreInt "https://github.com/leisuremeta/leisuremeta-chain/tree/main/modules/node/src/main/scala/io/leisuremeta/chain/node/store/interpreter/"
    click MerkleTrie "https://github.com/leisuremeta/leisuremeta-chain/blob/main/modules/lib/shared/src/main/scala/io/leisuremeta/chain/lib/merkle/MerkleTrie.scala"

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef core fill:#e1f5fe,stroke:#333
    classDef gateway fill:#e8f5e9,stroke:#333
    classDef explorer fill:#fff3e0,stroke:#333
    classDef service fill:#f3e5f5,stroke:#333
    classDef storage fill:#ede7f6,stroke:#333

    class API,NP,Node,Lib core
    class ETHGateway,GatewayCommon,GatewayDeposit,GatewayWithdraw gateway
    class LMScanBE,LMScanFE explorer
    class BlockSvc,TxSvc,StateSvc,RewardSvc,LocalSvc service
    class HashStr,KVStore,StoreInt,MerkleTrie storage
```
