# google/weather-tools architecture

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

- Interactive diagram: https://gitdiagram.com/google/weather-tools
- Repository: https://github.com/google/weather-tools

## Overview

##### Project Type and Purpose
- The README and file tree show that this project is a multi-tool command-line suite designed for weather/climate data management. It provides:
– A downloader (weather-dl) to pull data from external sources (e.g., ECMWF’s API).
– A mover (weather-mv) to ingest data into analytics engines like BigQuery.
– A splitter (weather-sp) to normalize or break up large datasets.
- Additionally, there is a newer version (weather_dl_v2) that includes a CLI as well as a FastAPI server, hinting at a move towards offering service APIs and cloud deployment (e.g., Docker, Kubernetes).

##### File Structure
- The top-level directories include configuration files (configs), documentation (docs), and several module directories named weather_dl, weather_mv, weather_sp, weather_dl_v2, and even xql.
- Specific directories highlight architectural boundaries:
- weather_dl: Contains the download pipeline with submodules for configurations, clients, fetchers, parsers, and manifests.
- weather_mv: Focuses on loading data and seems to include connector logic for BigQuery, plus a dedicated API directory (fastapi-server) with routers, database interactions, and tests.
- weather_sp: Contains the splitter pipeline logic.
- weather_dl_v2: Suggests evolution of the downloader logic with extra components such as CLI improvements, Kubernetes deployment mechanisms, and a FastAPI server.
- xql: Provides domain-specific libraries (or query-related tools) which include core logic for weather models.
- CI/CD pipeline configurations (in the .github directory), Dockerfiles for containerization, and test suites that indicate robust integration practices.

##### Incorporate README Insights
- The README explains how each tool functions and the overall workflow:
- weather-dl handles precise data descriptions and efficient requests from ECMWF.
- weather-mv ingests data into Google BigQuery – emphasizing integration with cloud services.
- weather-sp splits giant datasets into component variables.
- The tutorial in the README also gives hints about the data flow:
1. Download data via weather-dl.
2. Optionally split the data using weather-sp.
3. Load the processed data into BigQuery with weather-mv.
- Details on prerequisites and configurations which affect how the components interact with external services (such as the BigQuery API, Google Cloud Storage, and ECMWF’s API).

##### Main Components and Their Relationships
- User/Operator Interface:
- Command-line interface tools (weather-dl, weather-mv, weather-sp) that are invoked by the user.
- Data Acquisition Layer:
- weather-dl: Connects to external weather data provider APIs (e.g., ECMWF).
- Associated libraries (clients, fetchers, parsers, manifest modules) handling data download mechanics.
- Data Processing/Transformation Layer:
- weather-sp: Splits or restructures downloaded datasets.
- Modules in weather_mv (and the FastAPI server in weather_dl_v2) that validate, transform, and prepare data for ingestion.
- Data Ingestion / Output Layer:
- weather-mv: Responsible for loading data into cloud-based systems (e.g., writing to Google BigQuery).
- The mover tool might also interact with temporary storage areas (e.g., Cloud Storage buckets as staging).
- API / Service Layer (in weather_dl_v2):
- The FastAPI server and its routers, which abstract API interactions for remote control or automated triggers.
- Support/Utility Modules:
- xql module providing logic for weather language modeling or analytical transformations.
- CI/CD pipelines, Dockerfiles, and Kubernetes deployments (e.g., in downloader_kubernetes and license_deployment) that facilitate automated testing and deployment.

##### Architectural Patterns and Key Technologies
- Separation of concerns – each CLI tool is self-contained and focuses on a specific task.
- The design reflects modularity, with each tool having submodules for configuration, data processing, and error handling.
- Containerization is supported via Dockerfile(s) and Kubernetes-specific configurations; CI/CD is automated via GitHub workflows.
- Apache Beam is mentioned in the introduction; if applicable, note that some pipelines might leverage it for distributed processing.

##### Instructing the Principal Software Engineer
1. External interfaces (ECMWF API, Google Cloud services)
2. Data acquisition (weather-dl, including its submodules like clients, fetchers, parsers)
3. Data processing (weather-sp and parts of weather_mv, including transformation pipelines)
4. Delivery/ingestion systems (BigQuery ingestion via weather-mv and staging areas using cloud storage)
5. Ancillary services (weather_dl_v2’s fast API server, xql functionalities, and CI/CD integration)
- Clearly denote dependencies:
- For example, weather-dl must successfully output data that may then be fed into weather-sp or directly into weather-mv.
- Optional flows (e.g., one might bypass weather-sp if splitting is not required).
- To include configuration flows:
- How configuration files (from the configs directory) influence the behavior of each tool.
- That version-controlled configurations and license files (e.g., $HOME/.cdsapirc setup) are integral to running the pipelines.
- CI/CD workflows triggering Docker builds or Kubernetes deployments as outlined by the Dockerfiles and related Kubernetes scripts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        U("Operator"):::cli
    end

    %% Data Acquisition Layer: Weather Downloader (weather-dl)
    subgraph "Data Acquisition (Weather Downloader)"
        WD1("weather-dl CLI"):::cli
        WD2("Download Pipeline"):::cli
        WD1 -->|"triggers"| WD2
    end

    %% Data Processing Layer: Data Splitter (weather-sp)
    subgraph "Data Processing (Data Splitter)"
        WS1("weather-sp CLI"):::cli
        WS2("Splitter Pipeline"):::cli
        WS1 -->|"initiates"| WS2
    end

    %% Data Ingestion Layer: Data Mover (weather-mv)
    subgraph "Data Ingestion (Data Mover)"
        WM1("weather-mv Executable"):::cli
        WM2("Loader Pipeline"):::cli
        WM2 -->|"assembles into"| WM1
    end

    %% Next-Gen Components: weather_dl_v2
    subgraph "Next-Gen Downloader & API (weather_dl_v2)"
        V2C("weather_dl_v2 CLI"):::cli
        V2API("FastAPI Server"):::api
        V2K("Kubernetes Deployment"):::deployment
        V2LD("License Deployment"):::deployment
        V2C -->|"activates"| V2API
        V2K -->|"manages"| V2C
        V2LD -->|"activates"| V2C
    end

    %% Support & Domain Utilities
    subgraph "Support & Domain"
        XQL("xql Utilities"):::system
    end

    %% CI/CD & Deployment Infrastructure
    subgraph "CI/CD & Deployment"
        CICD("CI/CD Pipeline"):::deployment
        Docker("Dockerfiles"):::deployment
    end

    %% Configuration Files
    subgraph "Configuration"
        Config("Configuration Files"):::config
    end

    %% External Services
    subgraph "External Services"
        ECMWF("ECMWF API"):::external
        BQ("BigQuery"):::external
        CS("Cloud Storage"):::external
    end

    %% Relationships - Data Flow
    U -->|"invokes"| WD1
    U -->|"invokes"| V2C

    WD2 -->|"download_request"| ECMWF

    %% Flow from downloader to processor and ingestion
    WD2 -->|"optional_split"| WS2
    WD2 -->|"direct_feed"| WM2
    WS2 -->|"transformed_data"| WM2

    WM1 -->|"ingestion_stream"| BQ

    %% Next-Gen API interactions
    V2API -->|"fetch_request"| ECMWF
    V2API -->|"triggers_ingestion"| WM2

    %% CI/CD Deployment influencing tools
    CICD -->|"build_deploy"| WD1
    CICD -->|"build_deploy"| WS1
    CICD -->|"build_deploy"| WM1
    CICD -->|"build_deploy"| V2C
    CICD -->|"build_deploy"| V2API
    CICD -->|"deploy"| V2K
    CICD -->|"deploy"| V2LD
    CICD -->|"build_images"| Docker

    %% Configuration influence
    Config -->|"runtime_config"| WD1
    Config -->|"runtime_config"| WS1
    Config -->|"runtime_config"| WM1
    Config -->|"runtime_config"| V2C

    %% Support utilities enhancing processing and ingestion
    XQL -->|"supports"| WS2
    XQL -->|"enhances"| WM2

    %% Class Definitions for styling
    classDef cli fill:#f9f,stroke:#333,stroke-width:2px;
    classDef api fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;
    classDef system fill:#ccf,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ffc,stroke:#333,stroke-width:2px;
    classDef config fill:#fcf,stroke:#333,stroke-width:2px;

    %% Click Events
    click WD1 "https://github.com/google/weather-tools/tree/main/weather_dl/weather-dl"
    click WD2 "https://github.com/google/weather-tools/tree/main/weather_dl/download_pipeline"
    click WS1 "https://github.com/google/weather-tools/tree/main/weather_sp/weather-sp"
    click WS2 "https://github.com/google/weather-tools/tree/main/weather_sp/splitter_pipeline"
    click WM1 "https://github.com/google/weather-tools/tree/main/weather_mv/weather-mv"
    click WM2 "https://github.com/google/weather-tools/tree/main/weather_mv/loader_pipeline"
    click V2C "https://github.com/google/weather-tools/tree/main/weather_dl_v2/cli"
    click V2API "https://github.com/google/weather-tools/tree/main/weather_dl_v2/fastapi-server"
    click V2K "https://github.com/google/weather-tools/tree/main/weather_dl_v2/downloader_kubernetes"
    click V2LD "https://github.com/google/weather-tools/tree/main/weather_dl_v2/license_deployment"
    click XQL "https://github.com/google/weather-tools/tree/main/xql"
    click CICD "https://github.com/google/weather-tools/tree/main/.github/workflows"
    click Docker "https://github.com/google/weather-tools/tree/main/weather_dl_v2/cli/Dockerfile"
    click Config "https://github.com/google/weather-tools/tree/main/configs"
```
