# beefyfinance/beefy-cowllector-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/beefyfinance/beefy-cowllector-v2
- Repository: https://github.com/beefyfinance/beefy-cowllector-v2

## Overview

##### Main Components

a) Core Services:
- Harvester Service (Main Bot)
- Analytics Service (Grafana)
- API Service
- Database Layer
- Smart Contracts Layer

b) External Integrations:
- Multiple Blockchain Networks
- Discord Integration (for notifications)
- Beefy Vaults & Strategies
- Revenue Bridge

**┌─ Infrastructure Layer ─────────────────────┐**
- Docker Containers                        │
- Database                                 │
- Grafana Analytics                        │
- Application Layer ──────────────────────┐ │
- API Service                           │ │
- Harvester Core                        │ │
- Balance Checker                       │ │
- RPC Client                           │ │
- Smart Contract Layer ──────────────────┤ │
- Harvest Lens Contract                │ │
- Strategy Contracts                   │ │
- Revenue Bridge                       │ │
- ┘

##### Key Relationships to Highlight

a) Data Flow:
- How the harvester interacts with multiple chains
- Harvest report flow to Discord
- Analytics data collection path
- API endpoints interaction

b) Component Interactions:
- RPC communication with blockchain networks
- Database interactions for storing harvest reports
- Analytics dashboard data collection
- Smart contract interactions

##### Technical Details

- Node.js runtime environment (>=20.5)
- Docker containerization
- Foundry for contract deployment
- TypeScript implementation
- Database migrations system
- RPC client architecture

a) Harvest Flow:
**Vault Discovery → Balance Check → Harvest Execution → Report Generation → Discord Notification**

b) Monitoring Flow:
**Data Collection → Metrics Storage → Dashboard Display → Alert Generation**

##### Component Details

a) API Service (/api):
- REST endpoints
- Database connectivity
- Report management

b) Analytics (/analytics):
- Grafana dashboards
- Alert configurations
- Data source management

c) Core Logic (/src):
- Harvest actions
- Chain interactions
- Report generation
- RPC management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Infrastructure
        Docker[Docker Containers]:::infra
        Database[(Database)]:::infra
        click Database "https://github.com/beefyfinance/beefy-cowllector-v2/tree/main/src/lib/db"
        Grafana[Grafana Analytics]:::analytics
        click Grafana "https://github.com/beefyfinance/beefy-cowllector-v2/tree/main/analytics"
    end

    subgraph Application
        API[API Service]:::core
        click API "https://github.com/beefyfinance/beefy-cowllector-v2/tree/main/api"
        Harvester[Harvester Core]:::core
        click Harvester "https://github.com/beefyfinance/beefy-cowllector-v2/tree/main/src/lib/harvest-actions"
        BalanceChecker[Balance Checker]:::core
        click BalanceChecker "https://github.com/beefyfinance/beefy-cowllector-v2/blob/main/src/lib/collector-balance.ts"
        RPCClient[RPC Client]:::core
        click RPCClient "https://github.com/beefyfinance/beefy-cowllector-v2/blob/main/src/lib/rpc-client.ts"
    end

    subgraph "Smart Contracts"
        HarvestLens[Harvest Lens Contract]:::contract
        click HarvestLens "https://github.com/beefyfinance/beefy-cowllector-v2/tree/main/contracts"
        Strategies[Strategy Contracts]:::contract
        RevenueBridge[Revenue Bridge]:::contract
        click RevenueBridge "https://github.com/beefyfinance/beefy-cowllector-v2/blob/main/src/lib/revenue-bridge-harvest-chain.ts"
    end

    subgraph "External Services"
        Discord[Discord Notifications]:::external
        click Discord "https://github.com/beefyfinance/beefy-cowllector-v2/blob/main/src/lib/discord-message.ts"
        BeefyVaults[Beefy Vaults]:::external
    end

    subgraph "Blockchain Networks"
        Chain1[Chain 1]:::blockchain
        Chain2[Chain 2]:::blockchain
        ChainN[Chain N]:::blockchain
    end

    %% Relationships
    Harvester --> RPCClient
    RPCClient --> Chain1
    RPCClient --> Chain2
    RPCClient --> ChainN
    
    Harvester --> HarvestLens
    Harvester --> Strategies
    Harvester --> RevenueBridge
    
    Harvester --> Database
    API --> Database
    
    BalanceChecker --> RPCClient
    Harvester --> BalanceChecker
    
    Harvester --> Discord
    Harvester --> BeefyVaults
    
    Database --> Grafana
    
    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef infra fill:#2ecc71,stroke:#27ae60,color:white
    classDef contract fill:#e67e22,stroke:#d35400,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef blockchain fill:#e74c3c,stroke:#c0392b,color:white
    classDef analytics fill:#1abc9c,stroke:#16a085,color:white

    %% Legend
    subgraph Legend
        L1[Core Services]:::core
        L2[Infrastructure]:::infra
        L3[Smart Contracts]:::contract
        L4[External Services]:::external
        L5[Blockchain]:::blockchain
        L6[Analytics]:::analytics
    end
```
