# lavanet/lava architecture

> Architecture diagram of the GitHub repository lavanet/lava, 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/lavanet/lava
- Repository: https://github.com/lavanet/lava

## Overview

##### Main Components

a. Core Protocol Layer:
- Tendermint Core (consensus engine)
- Cosmos SDK Base
- Custom Lava Modules (x/ directory):
- Pairing Module (provider-consumer matching)
- Subscription Module
- Rewards Module
- Conflict Resolution Module
- Protocol Module
- Projects Module
- Plans Module

b. Client Applications:
- Lavad (daemon/node)
- Lavap (provider client)
- Lavavisor (upgrade manager)

c. Network Components:
- Provider Network
- Consumer Network
- Relay System
- Quality of Service (QoS) Monitoring

##### Architecture Patterns to Highlight

a. Module Organization:
- Clear boundaries between core protocol and extension modules
- Cross-module dependencies

b. Data Flow:
- Provider-Consumer pairing mechanism
- Stake-weighted pseudorandom pairing
- Relay payment system
- Conflict resolution flow

##### Specific Implementation Details

a. Protocol Features:
- Backfilling mechanism
- Lazy settlement process
- QoS monitoring system

b. Integration Points:
- IBC (Inter-Blockchain Communication) connections
- External API interfaces
- Chain specification handling

**Application Layer (Clients)**
**↓**
**Protocol Layer (Custom Modules)**
**↓**
**Core Layer (Cosmos SDK + Tendermint)**
**↓**
**Network Layer (P2P Communication)**

##### Technical Elements

a. Specific technical components:
- Chain specification system
- Badge generation system
- Provider optimization system
- State tracking system
- Reward distribution mechanism

b. Integration with:
- External blockchain networks
- API providers
- Consumer applications

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        LA["Lavad"]:::client
        LP["Lavap"]:::client
        LV["Lavavisor"]:::client
    end

    subgraph "Protocol Layer"
        subgraph "Custom Modules"
            PM["Pairing Module"]:::module
            SM["Subscription Module"]:::module
            RM["Rewards Module"]:::module
            CM["Conflict Resolution"]:::module
            PRM["Protocol Module"]:::module
            PROJ["Projects Module"]:::module
            PLM["Plans Module"]:::module
            ES["Epoch Storage"]:::module
        end

        subgraph "Protocol Components"
            PC["Provider/Consumer Network"]:::component
            RS["Relay System"]:::component
            QM["QoS Monitoring"]:::component
            ST["State Tracking"]:::component
            BG["Badge Generation"]:::component
            PO["Provider Optimization"]:::component
        end
    end

    subgraph "Core Layer"
        TC["Tendermint Core"]:::core
        SDK["Cosmos SDK Base"]:::core
    end

    subgraph "Network Layer"
        PN["Provider Network"]:::network
        CN["Consumer Network"]:::network
        IBC["IBC Communication"]:::network
    end

    subgraph "SDK Integration"
        LSDK["Lava SDK"]:::sdk
        JSDK["JavaScript SDK"]:::sdk
    end

    %% Relationships
    LA --> SDK
    LP --> SDK
    LV --> SDK

    SDK --> TC
    SDK --> PM
    SDK --> SM
    SDK --> RM
    SDK --> CM
    SDK --> PRM
    SDK --> PROJ
    SDK --> PLM
    SDK --> ES

    PM --> PC
    SM --> PC
    PRM --> RS
    PRM --> QM
    RM --> ST
    CM --> BG
    PROJ --> PO

    PC --> PN
    PC --> CN
    PC --> IBC

    LSDK --> PC
    JSDK --> PC

    %% Click events
    click LA "https://github.com/lavanet/lava/tree/main/cmd/lavad/"
    click LP "https://github.com/lavanet/lava/tree/main/cmd/lavap/"
    click LV "https://github.com/lavanet/lava/tree/main/cmd/lavavisor/"
    click PM "https://github.com/lavanet/lava/tree/main/x/pairing/"
    click SM "https://github.com/lavanet/lava/tree/main/x/subscription/"
    click RM "https://github.com/lavanet/lava/tree/main/x/rewards/"
    click CM "https://github.com/lavanet/lava/tree/main/x/conflict/"
    click PRM "https://github.com/lavanet/lava/tree/main/x/protocol/"
    click PROJ "https://github.com/lavanet/lava/tree/main/x/projects/"
    click PLM "https://github.com/lavanet/lava/tree/main/x/plans/"
    click ES "https://github.com/lavanet/lava/tree/main/x/epochstorage/"
    click PC "https://github.com/lavanet/lava/tree/main/protocol/chainlib/"
    click RS "https://github.com/lavanet/lava/tree/main/protocol/rpcconsumer/"
    click QM "https://github.com/lavanet/lava/tree/main/protocol/monitoring/"
    click ST "https://github.com/lavanet/lava/tree/main/protocol/statetracker/"
    click BG "https://github.com/lavanet/lava/tree/main/protocol/badgegenerator/"
    click PO "https://github.com/lavanet/lava/tree/main/protocol/provideroptimizer/"
    click SDK "https://github.com/lavanet/lava/blob/main/app/app.go"
    click LSDK "https://github.com/lavanet/lava/tree/main/ecosystem/lava-sdk/"
    click JSDK "https://github.com/lavanet/lava/tree/main/ecosystem/lavajs/"

    %% Styling
    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef module fill:#bbf,stroke:#333,stroke-width:2px
    classDef component fill:#dfd,stroke:#333,stroke-width:2px
    classDef core fill:#fdd,stroke:#333,stroke-width:2px
    classDef network fill:#ddd,stroke:#333,stroke-width:2px
    classDef sdk fill:#ffd,stroke:#333,stroke-width:2px
```
