# esmvalgroup/esmvaltool architecture

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

- Interactive diagram: https://gitdiagram.com/esmvalgroup/esmvaltool
- Repository: https://github.com/esmvalgroup/esmvaltool

## Overview

##### Main Components
- Recipe Engine & Interface – Representing the “driver” of the tool. This is where users provide recipe files that specify input data, preprocessing steps, and the diagnostic routines.
- Preprocessing/Core Module – The integration with ESMValCore (used for CMORization, regridding, masking, and other scientific preprocessing operations). This module reads configuration files, environment settings (via YAML/conda/environment files), and handles data input.
- CMORizers & Data Downloaders – Under the esmvaltool/cmorizers directory you see modules that convert raw input data (CMIP3, CMIP5, CMIP6, re-analysis, obs datasets, etc.) into a common format along with downloaders and formatters.
- External Interfaces & Deployment – Indicate components like Dockerfiles, CI/CD pipelines (.github/workflows, .circleci), conda environment files, and configuration scripts that facilitate deployment, continuous testing (with tests/integration and tests/unit), and packaging (setup.py, pyproject.toml).

##### Relationships and Data Flow
- The Recipe Engine parses the recipe and triggers the preprocessor module (ESMValCore integration via esmvaltool/core functionality) to prepare the input data (using CMORizers and formatters).
- Once preprocessing is complete, the Control Flow branches into various Diagnostic Modules based on directives in the recipe. These modules may invoke code written in various languages.
- The output of each diagnostic is then aggregated and post-processed, with results being passed back to the recipe engine for final output.
- Testing/Continuous Integration runs (represented separately via the tests directory and CI configuration in .github/workflows and .circleci) ensure that the modules work as intended. These pipelines ensure compliance with style and proper functioning.
- Deployment components (docker, conda files, etc.) create an environment that bundles this modular structure together.

##### Architectural Patterns and Key Design Principles
- Modularity and Extensibility: The separation of concerns is explicit (input handling, preprocessing, diagnostics execution, and output postprocessing).
- Configuration-driven Execution: Recipes and configuration reference files drive the framework, decoupling the user’s inputs from the underlying mechanics.
- CI/CD & Reproducibility: The presence of Dockerfiles, conda environment configuration files, and several testing directories (integration and unit tests) emphasize a strong focus on continuous integration and reproducibility.

##### Technologies and Frameworks
- Python is the core language, serving as the “glue” for many of the modules.
- ESMValCore is integrated as the preprocessing engine.
- NCL and R are used for specific diagnostics and plotting scripts.
- Docker, conda and CI pipelines (GitHub Actions, CircleCI) are used to ensure a reproducible deployment environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    user("User"):::external

    subgraph "Input & Configuration"
        recipeEngine("Recipe Engine / User Interface"):::interface
        recipeFiles("Recipe Files"):::interface
        configFiles("Config References"):::interface
        interfaceScripts("Interface Scripts"):::interface
    end

    subgraph "Preprocessing Module"
        preprocessing("Preprocessing (ESMValCore & CMORizers)"):::processing
        cmorizers("CMORizers & Data Downloaders"):::processing
        cmorizerScript("CMORizer Script"):::processing
        downloaders("Data Downloaders"):::processing
    end

    subgraph "Diagnostic Modules"
        diagPython("Python Diagnostics"):::diagnostic
        diagNCL("NCL Diagnostics"):::diagnostic
        diagR("R Diagnostics"):::diagnostic
        diagJulia("Julia Diagnostics"):::diagnostic
    end

    subgraph "Testing & Deployment Infrastructure"
        docker("Docker Config"):::deployment
        githubCI("GitHub Actions CI"):::deployment
        circleCI("CircleCI CI"):::deployment
        condaEnv("Conda Environment Files"):::deployment
        packaging("Packaging Scripts"):::deployment
        tests("Testing (Unit & Integration)"):::deployment
    end

    %% Data Flow Connections
    user -->|"provides"| recipeFiles
    recipeFiles --> recipeEngine
    configFiles --> recipeEngine
    interfaceScripts --> recipeEngine

    recipeEngine -->|"triggers"| preprocessing

    preprocessing --> cmorizers
    cmorizers --> downloaders
    cmorizers --> cmorizerScript

    preprocessing -->|"data_preprocessed"| diagPython
    preprocessing -->|"data_preprocessed"| diagNCL
    preprocessing -->|"data_preprocessed"| diagR
    preprocessing -->|"data_preprocessed"| diagJulia

    diagPython -->|"aggregates_results"| recipeEngine
    diagNCL -->|"aggregates_results"| recipeEngine
    diagR -->|"aggregates_results"| recipeEngine
    diagJulia -->|"aggregates_results"| recipeEngine

    %% Testing & Deployment interactions
    recipeEngine --- tests
    preprocessing --- tests
    diagPython --- tests
    diagNCL --- tests
    diagR --- tests
    diagJulia --- tests

    recipeEngine --- githubCI
    preprocessing --- githubCI
    diagPython --- githubCI
    diagNCL --- githubCI
    diagR --- githubCI
    diagJulia --- githubCI

    recipeEngine --- circleCI
    preprocessing --- circleCI
    diagPython --- circleCI
    diagNCL --- circleCI
    diagR --- circleCI
    diagJulia --- circleCI

    docker --- condaEnv
    packaging --- condaEnv

    %% Click Events
    click recipeFiles "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/recipes"
    click configFiles "https://github.com/esmvalgroup/esmvaltool/blob/main/esmvaltool/config-references.yml"
    click interfaceScripts "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/interface_scripts"

    click cmorizers "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/cmorizers"
    click cmorizerScript "https://github.com/esmvalgroup/esmvaltool/blob/main/esmvaltool/cmorizers/data/cmorizer.py"
    click downloaders "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/cmorizers/data/downloaders"

    click diagPython "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/diag_scripts"
    click diagNCL "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/diag_scripts"
    click diagR "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/diag_scripts"
    click diagJulia "https://github.com/esmvalgroup/esmvaltool/tree/main/esmvaltool/diag_scripts"

    click docker "https://github.com/esmvalgroup/esmvaltool/tree/main/docker"
    click githubCI "https://github.com/esmvalgroup/esmvaltool/tree/main/.github/workflows"
    click circleCI "https://github.com/esmvalgroup/esmvaltool/blob/main/.circleci"
    click condaEnv "https://github.com/esmvalgroup/esmvaltool/blob/main/environment.yml"
    click packaging "https://github.com/esmvalgroup/esmvaltool/blob/main/setup.py"
    click tests "https://github.com/esmvalgroup/esmvaltool/tree/main/tests"

    %% Styles
    classDef external fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef interface fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef processing fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef diagnostic fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef deployment fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
