# e3modelling/postprom architecture

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

- Interactive diagram: https://gitdiagram.com/e3modelling/postprom
- Repository: https://github.com/e3modelling/postprom

## Overview

##### Project type and purpose
- This is an R package (“postprom”) whose primary purpose is to convert OPEN-PROM model outputs (GDX files) into a Model Inter-comparison Format (MIF), link them to the magpie data structure, run a suite of comparative analyses (activity, GDP, emissions, etc.), and generate PDF reports.
- It is a command-line/library tool rather than a web app. It exposes R functions (in R/*.R) and ships with helper scripts (Python and RMarkdown/LaTeX templates) under inst/.

##### File structure
- Top level:
- DESCRIPTION, NAMESPACE: standard R package metadata
- R/: core R functions for data conversion (convertGDXtoMIF, readData, getMetadata), data linking (linkPromToMagpie), report modules (reportACTV, reportEmissions, …), plotting & orchestration (plotReport.R, batchPlotReport.R)
- inst/extdata/: static CSVs for plot‐mapping and styling
- inst/templates/: PDF report templates in RMarkdown (.Rmd) and Sweave (.Rnw)
- inst/scripts/reporting.py: Python wrapper for batch runs or cross-platform orchestration
- man/: auto‐generated Rd documentation for each R function
- There are no “frontend/backend” directories; instead the “backend” is the R code and the “presentation layer” is the PDF templates.

##### README
- It confirms the tool is for comparative analysis of OPEN-PROM data.

##### Final advice
- Be exhaustive: represent every stage and resource folder (extdata, templates).
- Dependencies (e.g., R → knitr → LaTeX).
- Don’t clutter with every man/ folder file—focus on functional components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Sources
    subgraph "Data Sources"
        GDX["OPEN-PROM GDX files"]:::datastore
        CSV1["plot_mapping.csv"]:::datastore
        CSV2["plotstyle.csv"]:::datastore
    end
    click CSV1 "https://github.com/e3modelling/postprom/blob/main/inst/extdata/plot_mapping.csv"
    click CSV2 "https://github.com/e3modelling/postprom/blob/main/inst/extdata/plotstyle.csv"

    %% Data Conversion & Ingestion
    subgraph "Data Conversion & Ingestion"
        Conv["convertGDXtoMIF.R"]:::rmodule
        Read["readData.R"]:::rmodule
        Meta["getMetadata.R"]:::rmodule
    end
    click Conv "https://github.com/e3modelling/postprom/blob/main/R/convertGDXtoMIF.R"
    click Read "https://github.com/e3modelling/postprom/blob/main/R/readData.R"
    click Meta "https://github.com/e3modelling/postprom/blob/main/R/getMetadata.R"

    %% Data Linking
    Link["linkPromToMagpie.R"]:::rmodule
    click Link "https://github.com/e3modelling/postprom/blob/main/R/linkPromToMagpie.R"

    %% Magpie Object
    MIF["Magpie Object"]:::datastore

    %% Analysis Modules
    subgraph "Analysis Modules"
        ACTV["reportACTV.R"]:::rmodule
        CAPADD["reportCapacityAdditions.R"]:::rmodule
        CAPELC["reportCapacityElectricity.R"]:::rmodule
        Emis["reportEmissions.R"]:::rmodule
        FE["reportFinalEnergy.R"]:::rmodule
        FCT["reportFuelConsTargets.R"]:::rmodule
        GDP["reportGDP.R"]:::rmodule
        PE["reportPE.R"]:::rmodule
        POP["reportPOP.R"]:::rmodule
        Price["reportPrice.R"]:::rmodule
        PriceC["reportPriceCarbon.R"]:::rmodule
        SE["reportSE.R"]:::rmodule
    end
    click ACTV "https://github.com/e3modelling/postprom/blob/main/R/reportACTV.R"
    click CAPADD "https://github.com/e3modelling/postprom/blob/main/R/reportCapacityAdditions.R"
    click CAPELC "https://github.com/e3modelling/postprom/blob/main/R/reportCapacityElectricity.R"
    click Emis "https://github.com/e3modelling/postprom/blob/main/R/reportEmissions.R"
    click FE "https://github.com/e3modelling/postprom/blob/main/R/reportFinalEnergy.R"
    click FCT "https://github.com/e3modelling/postprom/blob/main/R/reportFuelConsTargets.R"
    click GDP "https://github.com/e3modelling/postprom/blob/main/R/reportGDP.R"
    click PE "https://github.com/e3modelling/postprom/blob/main/R/reportPE.R"
    click POP "https://github.com/e3modelling/postprom/blob/main/R/reportPOP.R"
    click Price "https://github.com/e3modelling/postprom/blob/main/R/reportPrice.R"
    click PriceC "https://github.com/e3modelling/postprom/blob/main/R/reportPriceCarbon.R"
    click SE "https://github.com/e3modelling/postprom/blob/main/R/reportSE.R"

    %% Plotting & Reporting Engine
    Plot1["plotReport.R"]:::rmodule
    Plot2["batchPlotReport.R"]:::rmodule
    click Plot1 "https://github.com/e3modelling/postprom/blob/main/R/plotReport.R"
    click Plot2 "https://github.com/e3modelling/postprom/blob/main/R/batchPlotReport.R"

    %% Templates
    subgraph "Report Templates"
        T1["pdf.Rmd"]:::template
        T2["pdf.Rnw"]:::template
    end
    click T1 "https://github.com/e3modelling/postprom/blob/main/inst/templates/pdf.Rmd"
    click T2 "https://github.com/e3modelling/postprom/blob/main/inst/templates/pdf.Rnw"

    %% Orchestration Script
    Py["reporting.py"]:::script
    click Py "https://github.com/e3modelling/postprom/blob/main/inst/scripts/reporting.py"

    %% Output
    PDF["PDF Reports"]:::output

    %% Metadata & Documentation
    subgraph "Package Metadata & Docs"
        Desc["DESCRIPTION"]:::metadata
        NS["NAMESPACE"]:::metadata
        Man["man/*.Rd"]:::metadata
    end
    click Man "https://github.com/e3modelling/postprom/tree/main/man/"

    %% Data Flow
    GDX --> Conv
    Conv --> Read
    Conv --> Meta
    Read --> Link
    Meta --> Link
    Link --> MIF

    MIF --> ACTV
    MIF --> CAPADD
    MIF --> CAPELC
    MIF --> Emis
    MIF --> FE
    MIF --> FCT
    MIF --> GDP
    MIF --> PE
    MIF --> POP
    MIF --> Price
    MIF --> PriceC
    MIF --> SE

    %% Plotting flow
    ACTV --> Plot1
    CAPADD --> Plot1
    CAPELC --> Plot1
    Emis --> Plot1
    FE --> Plot1
    FCT --> Plot1
    GDP --> Plot1
    PE --> Plot1
    POP --> Plot1
    Price --> Plot1
    PriceC --> Plot1
    SE --> Plot1

    CSV1 --> Plot1
    CSV2 --> Plot1

    Plot1 --> T1
    Plot1 --> T2
    T1 --> PDF
    T2 --> PDF

    %% Batch plotting path
    MIF --> Plot2
    Plot2 --> T1
    Plot2 --> T2

    %% Orchestration control
    Py -.-> Conv
    Py -.-> Plot2

    %% Styles
    classDef rmodule fill:#ADD8E6,stroke:#000;
    classDef datastore fill:#90EE90,stroke:#000;
    classDef template fill:#FFD700,stroke:#000;
    classDef script fill:#FFA500,stroke:#000;
    classDef output fill:#D3D3D3,stroke:#000;
    classDef metadata fill:#D3D3D3,stroke:#000;
```
