# sorellalabs/brontes architecture

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

## Overview

##### Main components
- External Data Source & Integration: Show the integration with Reth as the source of raw Ethereum data. Also note the off-chain data enrichment (metadata, CEX prices, p2p data) mentioned in the README.
- Data Ingestion & Decoding: Represent the “brontes-core” crate along with parsing/decoding modules (see crates/brontes-core/decoding) that handle raw data processing.
- Classification & Inspector Framework: Include components such as “brontes-classifier” (with multiple submodules for protocols like Uniswap, Curve, etc.) and “brontes-inspect” for applying custom analytical logic (“inspectors”). Also, display the multi-frame classification components.
- Database Interaction: Show the “brontes-database” crate that interacts with databases (with submodules managing Clickhouse and MDBX integrations). Also reference the “libmdbx-rs” crate; these are critical for storing the structured data.
- Analytics, Pricing & Metrics: Illustrate the “brontes-pricing,” “brontes-metrics,” and “brontes-tracing” crates which process analytics information (price graphs, metrics, Prometheus exporter integration, tracing, etc.) and provide external exposure.
- Shared Types & Utilities: Include “brontes-types” and “brontes-macros” as cross-cutting libraries used by all other components for consistent interfaces and helper functions.
- CLI & Runner Components: Show the command-line interface (“crates/bin” and its subcomponents) as the entry point for running the analytics pipeline.

##### Relationships and interactions
- The ingestion/decoding module parses the trace data, passing it to the classifier modules for protocol-specific handling.
- Classified and enriched data then flows to the database layer for storage (Clickhouse/MDBX integration).
- In parallel, the inspector framework and pricing modules work on the processed data—running analytical algorithms and generating metrics.
- The metrics and trace modules handle logging/monitoring, pushing data to external systems (e.g., Prometheus, Grafana).
- The CLI/runner component orchestrates these processes based on user inputs, configuration files, and deployment scripts.

##### Architectural patterns and design principles
- Modularity: The system is split into many smaller, well-defined “crates” that interact through defined interfaces.
- Separation of Concerns: Data ingestion, classification, database management, analytics, and monitoring are distinct components.
- Extensibility: The Inspector Framework shows an emphasis on making analytics pluggable and user-definable.
- Integration: There is a clear pattern for integrating off-chain data and external JSON/ABI definitions (observable in the classifier-abis).
- Leveraging Rust’s package management (Cargo) for clear dependency management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Source & Integration
    EX["Data Source & Integration (Reth + Off-chain Data)"]:::external

    %% Ingestion & Decoding
    ING["Ingestion & Decoding (brontes-core)"]:::processing

    %% Classification & Inspector Framework
    subgraph "Classifiers & Inspectors"
        CLS["brontes-classifier"]:::processing
        INS["brontes-inspect"]:::processing
    end

    %% Database Interaction
    subgraph "Database Layer"
        DB["brontes-database (Clickhouse & MDBX)"]:::processing
        MDBX["libmdbx-rs"]:::processing
    end

    %% Analytics, Pricing & Metrics
    subgraph "Analytics/Metrics"
        PRI["brontes-pricing"]:::analytics
        MET["brontes-metrics"]:::analytics
        TRA["brontes-tracing"]:::analytics
    end

    %% Shared Types & Utilities
    subgraph "Shared Libraries"
        TYP["brontes-types"]:::shared
        MAC["brontes-macros"]:::shared
    end

    %% CLI & Runner Components
    CLI["CLI/Runner"]:::orchestration

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        DOCKER["Dockerfile"]:::infra
        WORKFLOW[".github/workflows"]:::infra
        GRAFANA["Grafana (etc/grafana)"]:::infra
        PROM["Prometheus (etc/prometheus)"]:::infra
        SYSTEMD["systemd (etc/systemd)"]:::infra
    end

    %% Data Flow Connections
    EX -->|"feeds"| ING
    CLI -->|"triggers"| ING
    ING -->|"decodes"| CLS
    ING -->|"decodes"| INS
    ING -->|"stores"| DB
    DB -->|"stores"| MDBX
    CLS -->|"outputs"| PRI
    INS -->|"outputs"| MET
    DB -->|"feeds"| MET
    DB -->|"feeds"| TRA
    MET -->|"reports"| PROM
    TRA -->|"traces"| GRAFANA

    %% Click Events
    click EX "https://github.com/sorellalabs/brontes/tree/main/crates/reth-tracing-ext"
    click ING "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-core/src/decoding"
    click CLS "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-classifier"
    click INS "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-inspect"
    click DB "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-database"
    click MDBX "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-database/libmdbx-rs"
    click PRI "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-pricing"
    click MET "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-metrics"
    click TRA "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-tracing"
    click TYP "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-types"
    click MAC "https://github.com/sorellalabs/brontes/tree/main/crates/brontes-macros"
    click CLI "https://github.com/sorellalabs/brontes/tree/main/crates/bin"
    click DOCKER "https://github.com/sorellalabs/brontes/tree/main/Dockerfile"
    click WORKFLOW "https://github.com/sorellalabs/brontes/tree/main/.github/workflows"
    click GRAFANA "https://github.com/sorellalabs/brontes/tree/main/etc/grafana"
    click PROM "https://github.com/sorellalabs/brontes/tree/main/etc/prometheus"
    click SYSTEMD "https://github.com/sorellalabs/brontes/tree/main/etc/systemd"

    %% Styling Classes
    classDef external fill:#ffcccc,stroke:#d33,stroke-width:2px;
    classDef processing fill:#ccffcc,stroke:#393,stroke-width:2px;
    classDef analytics fill:#ccffff,stroke:#339,stroke-width:2px;
    classDef shared fill:#ffffcc,stroke:#933,stroke-width:2px;
    classDef orchestration fill:#ffebcc,stroke:#d96,stroke-width:2px;
    classDef infra fill:#e0e0e0,stroke:#555,stroke-width:2px;
```
