# genai-impact/ecologits architecture

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

- Interactive diagram: https://gitdiagram.com/genai-impact/ecologits
- Repository: https://github.com/genai-impact/ecologits

## Overview

##### Main Components

a. Core Components:
- Impact Tracking Engine (ecologits/_ecologits.py)
- Model Repository System (ecologits/model_repository.py)
- Electricity Mix Repository (ecologits/electricity_mix_repository.py)
- Impact Calculation System (ecologits/impacts/)

b. Provider Integration Layer:
- API Tracers for different providers (ecologits/tracers/)
- Provider-specific implementations
- OpenAI
- Anthropic
- Cohere
- Google
- HuggingFace Hub
- MistralAI
- LiteLLM

c. Data Storage:
- Model specifications (ecologits/data/models.json)
- Electricity mix data (ecologits/data/electricity_mixes.csv)

**[Client Applications]**
- ↓
**[EcoLogits Main Interface]**
- ↓
**[Provider Integration Layer] ←→ [External AI Providers]**
- ↓
**[Impact Calculation Engine]**
- ↓
**[Data Repositories] ←→ [Static Data Files]**

##### Key Relationships to Highlight

- How the main EcoLogits interface connects to various provider tracers
- Data flow from API calls through the impact calculation system
- Demonstrate how the model and electricity mix repositories feed into the impact calculations

##### Implementation Details

- The modular architecture allowing for easy provider additions
- The separation between tracing logic and impact calculations
- The data flow for both streaming and non-streaming API calls
- The relationship between model specifications and impact calculations

##### Technical Elements

- Python package dependencies
- API integration points
- Data storage formats (JSON, CSV)
- Configuration options
- Monitoring and logging components

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Applications"]
        APP[Client Code]
    end

    subgraph Core["EcoLogits Core"]
        ITE["Impact Tracking Engine"]:::core
        LOG["Logging System"]:::core
        EXC["Exception Handler"]:::core
    end

    subgraph Providers["Provider Integration Layer"]
        direction TB
        OPENAI["OpenAI Tracer"]:::provider
        ANTHROPIC["Anthropic Tracer"]:::provider
        COHERE["Cohere Tracer"]:::provider
        GOOGLE["Google Tracer"]:::provider
        HF["HuggingFace Tracer"]:::provider
        MISTRAL["MistralAI Tracer"]:::provider
        LITELLM["LiteLLM Tracer"]:::provider
    end

    subgraph External["External AI Services"]
        direction TB
        EXT_OPENAI["OpenAI API"]:::external
        EXT_ANTHROPIC["Anthropic API"]:::external
        EXT_COHERE["Cohere API"]:::external
        EXT_GOOGLE["Google API"]:::external
        EXT_HF["HuggingFace API"]:::external
        EXT_MISTRAL["MistralAI API"]:::external
    end

    subgraph Impact["Impact Calculation System"]
        direction TB
        DAG["Impact Calculation DAG"]:::impact
        LLM["LLM Impact Calculator"]:::impact
        MODEL["Modeling Impact Calculator"]:::impact
    end

    subgraph Data["Data Repositories"]
        direction TB
        MR["Model Repository"]:::data
        EMR["Electricity Mix Repository"]:::data
        MD["Model Specifications"]:::data
        EMD["Electricity Mix Data"]:::data
    end

    %% Relationships
    APP --> ITE
    ITE --> LOG
    ITE --> EXC
    ITE --> Providers

    OPENAI <--> EXT_OPENAI
    ANTHROPIC <--> EXT_ANTHROPIC
    COHERE <--> EXT_COHERE
    GOOGLE <--> EXT_GOOGLE
    HF <--> EXT_HF
    MISTRAL <--> EXT_MISTRAL

    Providers --> Impact
    DAG --> LLM
    DAG --> MODEL
    Impact --> MR
    Impact --> EMR
    MR --> MD
    EMR --> EMD

    %% Click Events
    click ITE "https://github.com/genai-impact/ecologits/blob/main/ecologits/_ecologits.py"
    click LOG "https://github.com/genai-impact/ecologits/blob/main/ecologits/log.py"
    click EXC "https://github.com/genai-impact/ecologits/blob/main/ecologits/exceptions.py"
    click OPENAI "https://github.com/genai-impact/ecologits/blob/main/ecologits/tracers/openai_tracer.py"
    click ANTHROPIC "https://github.com/genai-impact/ecologits/blob/main/ecologits/tracers/anthropic_tracer.py"
    click COHERE "https://github.com/genai-impact/ecologits/blob/main/ecologits/tracers/cohere_tracer.py"
    click GOOGLE "https://github.com/genai-impact/ecologits/blob/main/ecologits/tracers/google_tracer.py"
    click HF "https://github.com/genai-impact/ecologits/blob/main/ecologits/tracers/huggingface_tracer.py"
    click MISTRAL "https://github.com/genai-impact/ecologits/blob/main/ecologits/tracers/mistralai_tracer_v1.py"
    click LITELLM "https://github.com/genai-impact/ecologits/blob/main/ecologits/tracers/litellm_tracer.py"
    click DAG "https://github.com/genai-impact/ecologits/blob/main/ecologits/impacts/dag.py"
    click LLM "https://github.com/genai-impact/ecologits/blob/main/ecologits/impacts/llm.py"
    click MODEL "https://github.com/genai-impact/ecologits/blob/main/ecologits/impacts/modeling.py"
    click MR "https://github.com/genai-impact/ecologits/blob/main/ecologits/model_repository.py"
    click EMR "https://github.com/genai-impact/ecologits/blob/main/ecologits/electricity_mix_repository.py"
    click MD "https://github.com/genai-impact/ecologits/blob/main/ecologits/data/models.json"
    click EMD "https://github.com/genai-impact/ecologits/blob/main/ecologits/data/electricity_mixes.csv"

    %% Styling
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef provider fill:#e67e22,stroke:#d35400,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef impact fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black

    %% Legend
    subgraph Legend
        L_CORE["Core Components"]:::core
        L_PROVIDER["Provider Integration"]:::provider
        L_EXTERNAL["External Services"]:::external
        L_IMPACT["Impact Calculation"]:::impact
        L_DATA["Data Storage"]:::data
    end
```
