# googlecloudplatform/ml-auto-solutions architecture

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

- Interactive diagram: https://gitdiagram.com/googlecloudplatform/ml-auto-solutions
- Repository: https://github.com/googlecloudplatform/ml-auto-solutions

## Overview

##### Project Type and Purpose
- MAS is a full-stack orchestration system for end-to-end ML tests and benchmarks, built on Google Cloud.
- It uses Terraform for infra provisioning (Cloud Composer), Airflow DAGs for orchestration, Compute/GKE/TPU resources for workloads, BigQuery for metrics, and optional dashboards via Looker Studio.

##### Main Components and How to Represent Them
a. Source & CI/CD
- GitHub repo (with .github/workflows, pipeline/auto-push.cloudbuild.yml)
- Cloud Build / GitHub Actions pipelines
b. Infrastructure Provisioning
- Terraform modules under deployment/…
- Resources: Cloud Composer environment, Artifact Registry, BigQuery datasets, GCS buckets
c. Orchestration Layer
- Cloud Composer (Airflow)
- GCS “dags” bucket storing all DAG definitions (the “dags” directory in the repo)
d. DAG Definitions & Python Library
- dags/… Python packages: dag definitions, configs, utils
- xlml/… client‐library for GCP APIs (GCS, Composer, GKE, BigQuery, TPU, etc.)
e. Compute Workloads
- Tasks launch VMs/containers on GCE, GKE, TPU, GPU (via xlml/utils and dag-specific scripts)
- Example workloads: model training, inference, profiling, microbenchmarks
f. Data & Metrics
- BigQuery tables for job_history, metric_history, metadata_history (deployment/schema)
- Downstream consumption by Looker Studio or other BI tools

##### Relationships & Data Flows
- Developers push code → CI/CD pipelines run lint/tests → upon merge, Cloud Build uploads new DAG code to GCS bucket.
- Terraform applies provisioning → spins up Composer environment, BigQuery datasets, GCS buckets.
- Composer polls GCS bucket → Airflow Scheduler loads DAG definitions.
- Each DAG (e.g., in dags/inference, dags/multipod…) orchestrates tasks:
· Uses xlml library to provision compute resources
· Runs ML benchmarks/training/inference on VMs/TPUs
· Collects logs and metrics → writes to BigQuery
- Dashboards query BigQuery for monitoring.

##### Architectural Patterns & Design Principles
- Infrastructure-as-Code (Terraform) for reproducible provisioning
- Modular Airflow architecture: separate DAGs per use-case, shared utils/config packages
- Client‐library abstraction (xlml) to encapsulate GCP API calls
- Clear separation between orchestration (Airflow) and compute (GCE/GKE/TPU)
- Centralized metrics store (BigQuery) decoupled from compute

##### Essential Elements
- Clear labels for each service (e.g., “Cloud Composer (Airflow)”) and code module (e.g., “dags/inference”).
· Blue for control-plane services (Terraform, Cloud Build)
· Green for orchestration (Composer, Airflow)
· Orange for compute (GCE, GKE, TPU)
· Yellow for data stores (GCS, BigQuery)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Local Development & CI/CD
    subgraph "Local Dev & CI/CD"
        direction TB
        GHRepo["GitHub Repo"]:::controlPlane
        GHActions["GitHub Actions Workflows"]:::controlPlane
        CloudBuild["Cloud Build Pipeline"]:::controlPlane
        PreCommit["Pre-commit & Pylint"]:::scripts
        DAGCheck["DAG Lint/Checks"]:::scripts
        LocalAirflow["Local Airflow Setup"]:::scripts
    end

    %% Cloud Provisioning
    subgraph "Cloud Provisioning"
        direction TB
        TerraformRoot["Terraform Root Configs"]:::controlPlane
        ComposerModule["Composer Module"]:::controlPlane
        ComposerEnvTF["Composer Env Deployment"]:::controlPlane
        SchemaJob["job_history.json"]:::storage
        SchemaMetric["metric_history.json"]:::storage
        SchemaMeta["metadata_history.json"]:::storage
    end

    %% Orchestration Layer
    subgraph "Orchestration (Cloud Composer / Airflow)"
        direction TB
        Composer["Cloud Composer (Airflow)"]:::orchestration
        GCSBucket["GCS DAGs Bucket"]:::storage
        UploadScript["DAG Upload Script"]:::scripts
        ComposerConfig["composer_env.py"]:::orchestration
        GCSUtil["gcs_bucket.py"]:::orchestration
        subgraph "DAG Definitions"
            direction TB
            AllDAGs["All DAGs (dags/)"]:::orchestration
            CommonUtils["Shared DAG Utils & Configs"]:::orchestration
            CleanUpDAG["Infra Cleanup DAG"]:::orchestration
        end
    end

    %% Compute Resources
    subgraph "Compute Resources"
        direction TB
        subgraph "xlml Library"
            direction TB
            XLMLAPIs["GCP Client APIs"]:::utils
            XLMLGKE["gke.py"]:::utils
            XLMLGPU["gpu.py"]:::utils
            XMLTPU["tpu.py"]:::utils
            XLMLComposer["composer.py"]:::utils
            XLMLBQ["bigquery.py"]:::utils
        end
        GCE["GCE VMs"]:::compute
        GKE["GKE Clusters"]:::compute
        TPU["TPU Nodes"]:::compute
    end

    %% Data Storage & Visualization
    subgraph "Data Storage & Visualization"
        direction TB
        BigQuery["BigQuery"]:::storage
        Looker["Looker Studio Dashboards"]:::storage
    end

    %% Flow Connections
    GHRepo -->|"push code"| GHActions
    GHRepo -->|".github/workflows"| DAGCheck
    GHActions -->|run CI/CD| CloudBuild
    CloudBuild -->|build & test| TerraformRoot
    CloudBuild -->|upload DAGs| UploadScript
    TerraformRoot -->|provisions| Composer
    TerraformRoot -->|creates| SchemaJob & SchemaMetric & SchemaMeta
    TerraformRoot -->|creates| GCSBucket
    UploadScript -->|uploads| GCSBucket
    Composer -->|polls| GCSBucket
    GCSBucket -->|provides DAGs| ComposerConfig & GCSUtil & AllDAGs
    AllDAGs -->|includes| CommonUtils & CleanUpDAG
    Composer -->|schedules tasks| XLMLComposer
    XLMLAPIs -->|used by| XLMLComposer & XLMLGKE & XLMLGPU & XMLTPU & XLMLBQ
    XLMLGKE -->|provisions| GKE
    XLMLGPU -->|provisions| GPU["GPU Instances"]:::compute
    XMLTPU -->|provisions| TPU
    XLMLComposer -->|launches| GCE
    Composer -->|executes| GCE & GKE & TPU
    GCE & GKE & TPU -->|write logs/metrics| BigQuery
    BigQuery -->|queried by| Looker

    %% Click Events
    click GHActions "https://github.com/googlecloudplatform/ml-auto-solutions/tree/master/.github/workflows/"
    click CloudBuild "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/pipeline/auto-push.cloudbuild.yml"
    click TerraformRoot "https://github.com/googlecloudplatform/ml-auto-solutions/tree/master/deployment/"
    click ComposerModule "https://github.com/googlecloudplatform/ml-auto-solutions/tree/master/deployment/modules/composer_env/"
    click ComposerEnvTF "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/deployment/deployment_composer_env/composer_env.tf"
    click SchemaJob "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/deployment/schema/job_history.json"
    click SchemaMetric "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/deployment/schema/metric_history.json"
    click SchemaMeta "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/deployment/schema/metadata_history.json"
    click ComposerConfig "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/dags/composer_env.py"
    click GCSUtil "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/dags/gcs_bucket.py"
    click UploadScript "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/scripts/upload-tests.sh"
    click AllDAGs "https://github.com/googlecloudplatform/ml-auto-solutions/tree/master/dags/"
    click CommonUtils "https://github.com/googlecloudplatform/ml-auto-solutions/tree/master/dags/common/"
    click CleanUpDAG "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/dags/infra/clean_up.py"
    click XLMLAPIs "https://github.com/googlecloudplatform/ml-auto-solutions/tree/master/xlml/apis/"
    click XLMLGKE "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/xlml/utils/gke.py"
    click XLMLGPU "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/xlml/utils/gpu.py"
    click XMLTPU "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/xlml/utils/tpu.py"
    click XLMLComposer "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/xlml/utils/composer.py"
    click XLMLBQ "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/xlml/utils/bigquery.py"
    click LocalAirflow "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/scripts/local-airflow.sh"
    click DAGCheck "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/scripts/dag-check.sh"
    click PreCommit "https://github.com/googlecloudplatform/ml-auto-solutions/blob/master/.pre-commit-config.yaml"

    %% Styles
    classDef controlPlane fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef orchestration fill:#D5F5E3,stroke:#186A3B,color:#145A32
    classDef compute fill:#FAD7A0,stroke:#A04000,color:#61210B
    classDef storage fill:#FCF3CF,stroke:#7E5109,color:#4E2A04
    classDef utils fill:#E8DAEF,stroke:#6C3483,color:#4A235A
    classDef scripts fill:#F5B7B1,stroke:#922B21,color:#641E16
```
