# polca/premise architecture

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

- Interactive diagram: https://gitdiagram.com/polca/premise
- Repository: https://github.com/polca/premise

## Overview

##### Main Components and Architecture

a) Core Processing Layer:
- Database Transformation Engine
- IAM Scenario Processor
- Sector-specific Modules (electricity, transport, fuels, etc.)
- Data Validation System

b) Data Layer:
- IAM Output Files Storage
- Configuration Data
- Mapping Files Repository
- Additional Inventories Storage

c) Integration Layer:
- Brightway2/2.5 Interface
- Export Systems (SimaPro, OpenLCA)
- Custom Scenario Handler

##### Component Relationships

**[Input Sources] → [Core Processing] → [Output Formats]**
- ↑               ↑    ↓              ↓
**[Data Storage] → [Validation] → [Export Handlers]**

##### Specific Implementation Details

a) Data Flow Architecture:
**[ecoinvent DB] → [Transformation Engine] → [Modified LCI DB]**
**[IAM Scenarios] ↗     ↑**
**[Custom Scenarios] → [Scenario Processor]**

b) Module Integration:
**[Core Engine] ← [Sector Modules]**
- ↓
**[Validation Layer]**
- ↓
**[Export System]**

##### Key Features to Highlight

- Modular architecture (separate modules for different sectors)
- Flexible scenario handling (IAM and custom)
- Multiple export format support
- Validation system integration
- Data transformation pipeline

##### Technical Details

Elements:
- Python 3.10+ requirement
- Brightway2/2.5 compatibility
- Database support (ecoinvent 3.x)
- IAM model integration (REMIND, IMAGE, TIAM-UCL)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        IAM[IAM Output Files]
        CS[Custom Scenarios]
        EDB[ecoinvent DB]
        CFG[Configuration Data]:::config
    end

    subgraph Core
        TE[Database Transformation Engine]:::core
        SP[IAM Scenario Processor]:::core
        VS[Data Validation System]:::validation
        
        subgraph "Sector Modules"
            EL[Electricity]:::module
            TR[Transport]:::module
            FU[Fuels]:::module
            BA[Battery]:::module
            BI[Biomass]:::module
            CE[Cement]:::module
            ST[Steel]:::module
        end
    end

    subgraph Storage
        IAMF[IAM Files Storage]:::storage
        MFR[Mapping Files Repository]:::storage
        AIS[Additional Inventories]:::storage
    end

    subgraph Integration
        BW[Brightway2/2.5 Interface]:::integration
        EX[Export Systems]:::integration
        CH[Custom Scenario Handler]:::integration
    end

    subgraph Output
        MLCI[Modified LCI DB]
        SP_OUT[SimaPro Export]
        OL_OUT[OpenLCA Export]
    end

    IAM --> SP
    CS --> CH
    EDB --> TE
    CFG --> TE
    
    SP --> TE
    CH --> TE
    
    TE --> VS
    VS --> BW
    VS --> EX
    
    EL & TR & FU & BA & BI & CE & ST --> TE
    
    IAMF --> SP
    MFR --> SP
    AIS --> TE
    
    BW --> MLCI
    EX --> SP_OUT
    EX --> OL_OUT

    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef storage fill:#4CAF50,stroke:#2E7D32,color:white
    classDef integration fill:#FF9800,stroke:#EF6C00,color:white
    classDef validation fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef module fill:#90CAF9,stroke:#1565C0,color:white
    classDef config fill:#E0E0E0,stroke:#757575,color:black

    click TE "https://github.com/polca/premise/blob/master/premise/transformation.py"
    click VS "https://github.com/polca/premise/blob/master/premise/validation.py"
    click IAMF "https://github.com/polca/premise/tree/master/premise/data/iam_output_files/"
    click AIS "https://github.com/polca/premise/tree/master/premise/data/additional_inventories/"
    click MFR "https://github.com/polca/premise/tree/master/premise/iam_variables_mapping/"
    click BW "https://github.com/polca/premise/blob/master/premise/brightway2.py"
    click EX "https://github.com/polca/premise/blob/master/premise/export.py"
    click EL "https://github.com/polca/premise/blob/master/premise/electricity.py"
    click TR "https://github.com/polca/premise/blob/master/premise/transport.py"
    click FU "https://github.com/polca/premise/blob/master/premise/fuels.py"
    click BA "https://github.com/polca/premise/blob/master/premise/battery.py"
    click BI "https://github.com/polca/premise/blob/master/premise/biomass.py"
    click CE "https://github.com/polca/premise/blob/master/premise/cement.py"
    click ST "https://github.com/polca/premise/blob/master/premise/steel.py"
    click CFG "https://github.com/polca/premise/tree/master/premise/data/utils/"
    click EX "https://github.com/polca/premise/tree/master/premise/data/utils/export/"
    click VS "https://github.com/polca/premise/tree/master/premise/data/utils/validation/"
```
