# gridtools/gt4py architecture

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

- Interactive diagram: https://gitdiagram.com/gridtools/gt4py
- Repository: https://github.com/gridtools/gt4py

## Overview

##### High-Level Components

a. Frontend Layer
- GTScript DSL Interface
- Python Function Definitions
- Type System (`src/gt4py/next/type_system`)
- Field Operators (`src/gt4py/next/ffront`)

b. Core Processing Layer
- Iterator IR (`src/gt4py/next/iterator`)
- Program Processors (`src/gt4py/next/program_processors`)
- Transformation Pipeline
- Eve Framework (`src/gt4py/eve`) - Core utilities

c. Backend Layer
- Multiple Backend Implementations:
- NumPy Backend
- GridTools C++ Backend (CPU)
- CUDA Backend
- DaCe Backend
- Storage Management (`src/gt4py/storage`)

d. Build & Runtime Layer
- On-The-Fly (OTF) Compilation (`src/gt4py/next/otf`)
- Cache Management
- Runtime Support

##### Connection Flows
- Data flow from GTScript → IR → Backend implementations
- Control flow for compilation and execution
- Storage management interactions
- Build system integration points

##### Special Elements
- Configuration management
- Cache handling
- External dependencies (Boost, GridTools)
- Testing infrastructure

##### Component Interactions
Highlight:
- IR transformation stages
- Backend selection logic
- Storage layout management
- Compilation pipeline steps

Key Considerations:
##### Testing and validation flows

- High-level architecture visibility
- Detailed component relationships
- Clear execution/compilation flows
- System integration points

- Component type indicators
- Version/compatibility markers

This will provide a comprehensive view of GT4Py's architecture while maintaining clarity and usefulness for technical discussions.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#b3d1ff,stroke:#333
    classDef core fill:#b3ffb3,stroke:#333
    classDef backend fill:#ffd9b3,stroke:#333
    classDef runtime fill:#e6b3ff,stroke:#333

    %% Frontend Layer
    subgraph Frontend
        GTScript["GTScript DSL Interface"]
        PythonDef["Python Function Definitions"]
        TypeSystem["Type System"]:::frontend
        FieldOps["Field Operators"]:::frontend
    end

    %% Core Processing Layer
    subgraph Core
        IteratorIR["Iterator IR"]:::core
        ProgramProc["Program Processors"]:::core
        TransPipe["Transformation Pipeline"]:::core
        EveFrame["Eve Framework"]:::core
    end

    %% Backend Layer
    subgraph Backends
        NumPyBE["NumPy Backend"]:::backend
        GridToolsBE["GridTools C++ Backend"]:::backend
        CUDABE["CUDA Backend"]:::backend
        DaCeBE["DaCe Backend"]:::backend
        Storage["Storage Management"]:::backend
    end

    %% Build & Runtime Layer
    subgraph Runtime
        OTFComp["On-The-Fly Compilation"]:::runtime
        CacheMgmt["Cache Management"]:::runtime
        RuntimeSupp["Runtime Support"]:::runtime
    end

    %% Connections
    GTScript --> TypeSystem
    PythonDef --> FieldOps
    TypeSystem --> IteratorIR
    FieldOps --> IteratorIR
    IteratorIR --> TransPipe
    TransPipe --> ProgramProc
    EveFrame --> ProgramProc

    ProgramProc --> NumPyBE
    ProgramProc --> GridToolsBE
    ProgramProc --> CUDABE
    ProgramProc --> DaCeBE

    NumPyBE --> Storage
    GridToolsBE --> Storage
    CUDABE --> Storage
    DaCeBE --> Storage

    Storage --> OTFComp
    OTFComp --> CacheMgmt
    CacheMgmt --> RuntimeSupp

    %% Click Events
    click TypeSystem "https://github.com/GridTools/gt4py/tree/main/src/gt4py/next/type_system/"
    click FieldOps "https://github.com/GridTools/gt4py/tree/main/src/gt4py/next/ffront/"
    click IteratorIR "https://github.com/GridTools/gt4py/tree/main/src/gt4py/next/iterator/"
    click ProgramProc "https://github.com/GridTools/gt4py/tree/main/src/gt4py/next/program_processors/"
    click EveFrame "https://github.com/GridTools/gt4py/tree/main/src/gt4py/eve/"
    click DaCeBE "https://github.com/GridTools/gt4py/tree/main/src/gt4py/next/program_processors/runners/dace/"
    click Storage "https://github.com/GridTools/gt4py/tree/main/src/gt4py/storage/"
    click OTFComp "https://github.com/GridTools/gt4py/tree/main/src/gt4py/next/otf/"
    click CacheMgmt "https://github.com/GridTools/gt4py/blob/main/src/gt4py/cartesian/caching.py"
    click RuntimeSupp "https://github.com/GridTools/gt4py/blob/main/src/gt4py/next/iterator/runtime.py"
    click TransPipe "https://github.com/GridTools/gt4py/tree/main/src/gt4py/next/iterator/transforms/"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend Component"]:::frontend
        Core_L["Core Component"]:::core
        Backend_L["Backend Component"]:::backend
        Runtime_L["Runtime Component"]:::runtime
    end
```
