# nextflow-io/nf-co2footprint architecture

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

- Interactive diagram: https://gitdiagram.com/nextflow-io/nf-co2footprint
- Repository: https://github.com/nextflow-io/nf-co2footprint

## Overview

##### Project Type and Purpose
- This is a Nextflow plugin designed to estimate the CO₂ footprint of Nextflow pipeline runs.
- Its primary function is to calculate energy consumption and carbon emissions for each pipeline task. In addition, the plugin generates both detailed TXT reports and an HTML overview, leveraging data on compute resource consumption and energy carbon intensity.
- The README emphasizes key aspects such as integration into a Nextflow pipeline (via “nextflow.config”) and reliance on the methods developed in the Green Algorithms project.

##### Analysis of the File Structure
- Build and Configuration:
- The project uses Gradle as its build system (files like Makefile, gradlew, settings.gradle, and files in “gradle” and “buildSrc”).
- The “buildSrc” directory holds custom Gradle scripts (written in Groovy) that set conventions for building and packaging the code.
- Plugin Module:
- The core plugin is located in the “plugins/nf-co2footprint” directory.
- Inside this module, you have a clear separation between source code (in “src/main/nextflow/co2footprint”) and tests (in “src/test”).
- The source code consists of various Groovy classes (e.g., CO2FootprintConfig.groovy, CO2FootprintPlugin.groovy, and related utility scripts) which together implement the plugin functionality.
- The resources needed by the plugin (CSV data, HTML templates, JavaScript assets) are organized under “src/resources”.
- Documentation and CI:
- The “docs” directory along with the MkDocs configuration (mkdocs.yml) provide user documentation.
- GitHub workflows in “.github/workflows” indicate automated build and documentation generation.
- Configuration:
- The top-level Nextflow configuration file (“nextflow.config”) is central for invoking the plugin when used in a Nextflow pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Layer
    subgraph "Configuration Layer"
        NConfig["Nextflow Config"]:::config
    end

    %% Plugin Core Module
    subgraph "Plugin Core Module"
        PC["Plugin Core Module"]:::core
        %% Main Application Logic
        subgraph "Main Application Logic"
            MAL1["CO2FootprintPlugin.groovy"]:::logic
            MAL2["CO2FootprintConfig.groovy"]:::logic
            MAL3["CO2FootprintFactory.groovy"]:::logic
            MAL4["CO2FootprintReportSummary.groovy"]:::logic
            MAL5["CO2FootprintResourcesAggregator.groovy"]:::logic
        end
        %% Data Modelling & Calculation
        subgraph "Data Modelling & Calculation"
            DM1["CIDataMatrix.groovy"]:::model
            DM2["TDPDataMatrix.groovy"]:::model
            DM3["CO2Record.groovy"]:::model
        end
        %% Utilities
        subgraph "Utilities"
            UT1["DataContainers.groovy"]:::utils
            UT2["HelperFunctions.groovy"]:::utils
        end
        %% Resources & Assets
        subgraph "Resources & Assets"
            RA1["CSV & Template Data"]:::res
            RA2["Assets & META-INF"]:::res
        end
    end

    %% Build Infrastructure
    subgraph "Build Infrastructure"
        BI1["Gradle Build Scripts"]:::build
        BI2["Gradle Wrapper"]:::build
        BI3["Project Build File"]:::build
    end

    %% Testing Suite
    subgraph "Testing Suite"
        TS["Plugin Tests"]:::test
    end

    %% Documentation & CI/CD
    subgraph "Documentation & CI/CD"
        D1["Documentation (docs, mkdocs.yml)"]:::doc
        D2["CI Workflows (.github/workflows)"]:::doc
    end

    %% Relationships
    NConfig -->|"plugin_initialization"| PC
    PC -->|"triggers_build"| BI1
    PC -->|"packages_with"| BI3
    BI1 -->|"builds"| PC
    BI3 -->|"builds"| PC
    TS -->|"validates"| PC
    D2 -->|"triggers_tests"| TS
    D2 -->|"updates"| D1

    %% Internal Plugin Core Relationships
    MAL1 -->|"processes"| DM1
    MAL1 -->|"processes"| DM2
    MAL1 -->|"processes"| DM3
    MAL1 -->|"calls"| UT1
    MAL1 -->|"calls"| UT2
    MAL1 -->|"aggregates"| RA1
    MAL1 -->|"aggregates"| RA2

    %% Click Events
    click NConfig "https://github.com/nextflow-io/nf-co2footprint/blob/master/nextflow.config"
    click PC "https://github.com/nextflow-io/nf-co2footprint/tree/master/plugins/nf-co2footprint"
    click MAL1 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintPlugin.groovy"
    click MAL2 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy"
    click MAL3 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy"
    click MAL4 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintReportSummary.groovy"
    click MAL5 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintResourcesAggregator.groovy"
    click DM1 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CIDataMatrix.groovy"
    click DM2 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/TDPDataMatrix.groovy"
    click DM3 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2Record.groovy"
    click UT1 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/utils/DataContainers.groovy"
    click UT2 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/nf-co2footprint/src/main/nextflow/co2footprint/utils/HelperFunctions.groovy"
    click RA1 "https://github.com/nextflow-io/nf-co2footprint/tree/master/plugins/nf-co2footprint/src/resources"
    click RA2 "https://github.com/nextflow-io/nf-co2footprint/tree/master/plugins/nf-co2footprint/src/resources"
    click BI1 "https://github.com/nextflow-io/nf-co2footprint/tree/master/buildSrc"
    click BI2 "https://github.com/nextflow-io/nf-co2footprint/tree/master/gradle/wrapper"
    click BI3 "https://github.com/nextflow-io/nf-co2footprint/blob/master/plugins/build.gradle"
    click TS "https://github.com/nextflow-io/nf-co2footprint/tree/master/plugins/nf-co2footprint/src/test"
    click D1 "https://github.com/nextflow-io/nf-co2footprint/tree/master/docs"
    click D2 "https://github.com/nextflow-io/nf-co2footprint/tree/master/.github/workflows"

    %% Styles
    classDef config fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef logic fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef model fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef utils fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef res fill:#F08080,stroke:#333,stroke-width:2px;
    classDef build fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef test fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef doc fill:#B0E0E6,stroke:#333,stroke-width:2px;
```
