# dagger/dagger-php-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/dagger/dagger-php-sdk
- Repository: https://github.com/dagger/dagger-php-sdk

## Overview

##### Main Components

a) Core SDK Components:
- Client Layer (src/Client/*)
- Connection Layer (src/Connection/*)
- Code Generation System (src/Codegen/*)
- GraphQL Interface (src/GraphQL/*)
- Service Layer (src/Service/*)

b) Supporting Components:
- Runtime Environment
- Generated Code
- Dagger Engine Integration
- Test Infrastructure

**┌─ Application Layer (User Code) ─────────────────┐**

- Dagger PHP SDK Interface             │
- ┤

- Client Layer                     │
- (AbstractClient, QueryBuilder, Objects)       │
- ┤

- Connection Layer                    │
- (ProcessSession, EnvSession, CLI Downloader)  │
- ┤

- Code Generation System               │
- (Introspection, Schema Generation)            │
- ┤

- Dagger Engine                     │

- ┘

##### Key Elements to Highlight

a) Data Flow:

b) Component Relationships:
- How the Client layer interfaces with the Connection layer
- Code generation pipeline
- Demonstrate how GraphQL queries are built and executed

**┌─ Introspection ─┐    ┌─ Schema Gen ─┐    ┌─ Code Gen ─┐**
- GraphQL Schema │ -> │ PHP Classes  │ -> │  Generated │
- Parsing        │    │ Definition   │    │  Types     │
- ┘    └─────────────┘    └────────────┘

**┌─ Client ─┐    ┌─ Connection ─┐    ┌─ Dagger Engine ─┐**
- Request  │ -> │ Session      │ -> │ Execution       │
- Building │    │ Management   │    │                 │
- ┘    └─────────────┘    └─────────────────┘

##### Implementation Details

- Relationship between attributes (src/Attribute/*) and code generation
- How serialization services handle data transformation
- Demonstrate the test infrastructure's relationship to core components

##### Notes for Implementation

- Use UML-style notation for class relationships where appropriate
- Version information for Dagger Engine compatibility
- Clear boundaries between generated and hand-written code
- Extension points for future functionality

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        UserCode["User Application Code"]
        SDKInterface["Dagger PHP SDK Interface"]:::interface
    end

    subgraph "Client Layer"
        AbstractClient["Abstract Client"]:::client
        QueryBuilder["Query Builder"]:::client
        AbstractObject["Abstract Object"]:::client
    end

    subgraph "Connection Layer"
        ProcessSession["Process Session"]:::connection
        EnvSession["Environment Session"]:::connection
        CliDownloader["CLI Downloader"]:::connection
    end

    subgraph "Code Generation System"
        Codegen["Code Generator"]:::codegen
        SchemaGen["Schema Generator"]:::codegen
        Introspection["Introspection"]:::codegen
    end

    subgraph "Service Layer"
        DecodesValue["Value Decoder"]:::service
        FindsObjects["Object Finder"]:::service
        Serialiser["Serialisation Service"]:::service
    end

    subgraph "GraphQL Interface"
        QueryBuilderChain["Query Builder Chain"]:::graphql
        IntrospectionSchema["Introspection Schema"]:::graphql
    end

    subgraph "Attributes System"
        DaggerFunction["Dagger Function"]:::attribute
        DaggerObject["Dagger Object"]:::attribute
        Argument["Argument"]:::attribute
    end

    subgraph "Infrastructure"
        TestInfra["Test Infrastructure"]:::test
        GeneratedCode["Generated Code"]:::generated
        Runtime["Runtime Environment"]:::runtime
        DaggerEngine["Dagger Engine"]:::engine
    end

    %% Relationships
    UserCode --> SDKInterface
    SDKInterface --> AbstractClient
    AbstractClient --> QueryBuilder
    AbstractClient --> AbstractObject
    QueryBuilder --> ProcessSession
    QueryBuilder --> EnvSession
    ProcessSession --> DaggerEngine
    EnvSession --> DaggerEngine
    CliDownloader --> DaggerEngine
    
    Codegen --> SchemaGen
    SchemaGen --> Introspection
    Introspection --> IntrospectionSchema
    
    QueryBuilder --> QueryBuilderChain
    QueryBuilderChain --> IntrospectionSchema
    
    AbstractObject --> DecodesValue
    AbstractObject --> FindsObjects
    AbstractObject --> Serialiser
    
    DaggerFunction --> Codegen
    DaggerObject --> Codegen
    Argument --> Codegen
    
    Codegen --> GeneratedCode
    GeneratedCode --> Runtime
    
    TestInfra -.-> AbstractClient
    TestInfra -.-> ProcessSession
    TestInfra -.-> Codegen

    %% Click Events
    click AbstractClient "https://github.com/dagger/dagger-php-sdk/blob/main/src/Client/AbstractClient.php"
    click QueryBuilder "https://github.com/dagger/dagger-php-sdk/blob/main/src/Client/QueryBuilder.php"
    click AbstractObject "https://github.com/dagger/dagger-php-sdk/blob/main/src/Client/AbstractObject.php"
    click ProcessSession "https://github.com/dagger/dagger-php-sdk/blob/main/src/Connection/ProcessSessionConnection.php"
    click EnvSession "https://github.com/dagger/dagger-php-sdk/blob/main/src/Connection/EnvSessionConnection.php"
    click CliDownloader "https://github.com/dagger/dagger-php-sdk/blob/main/src/Connection/CliDownloader.php"
    click Codegen "https://github.com/dagger/dagger-php-sdk/blob/main/src/Codegen/Codegen.php"
    click SchemaGen "https://github.com/dagger/dagger-php-sdk/blob/main/src/Codegen/SchemaGenerator.php"
    click Introspection "https://github.com/dagger/dagger-php-sdk/tree/main/src/Codegen/Introspection"
    click QueryBuilderChain "https://github.com/dagger/dagger-php-sdk/blob/main/src/GraphQL/QueryBuilderChain.php"
    click IntrospectionSchema "https://github.com/dagger/dagger-php-sdk/blob/main/src/Codegen/Resources/introspection.graphql"
    click DecodesValue "https://github.com/dagger/dagger-php-sdk/blob/main/src/Service/DecodesValue.php"
    click FindsObjects "https://github.com/dagger/dagger-php-sdk/blob/main/src/Service/FindsDaggerObjects.php"
    click Serialiser "https://github.com/dagger/dagger-php-sdk/blob/main/src/Service/Serialisation/Serialiser.php"
    click DaggerFunction "https://github.com/dagger/dagger-php-sdk/blob/main/src/Attribute/DaggerFunction.php"
    click DaggerObject "https://github.com/dagger/dagger-php-sdk/blob/main/src/Attribute/DaggerObject.php"
    click Argument "https://github.com/dagger/dagger-php-sdk/blob/main/src/Attribute/Argument.php"
    click TestInfra "https://github.com/dagger/dagger-php-sdk/tree/main/tests"
    click GeneratedCode "https://github.com/dagger/dagger-php-sdk/tree/main/generated"
    click Runtime "https://github.com/dagger/dagger-php-sdk/tree/main/runtime"

    %% Styles
    classDef interface fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef client fill:#3498db,stroke:#333,stroke-width:2px
    classDef connection fill:#2ecc71,stroke:#333,stroke-width:2px
    classDef codegen fill:#9b59b6,stroke:#333,stroke-width:2px
    classDef service fill:#e74c3c,stroke:#333,stroke-width:2px
    classDef graphql fill:#f1c40f,stroke:#333,stroke-width:2px
    classDef attribute fill:#1abc9c,stroke:#333,stroke-width:2px
    classDef test fill:#95a5a6,stroke:#333,stroke-width:2px
    classDef generated fill:#34495e,stroke:#333,stroke-width:2px,color:#fff
    classDef runtime fill:#e67e22,stroke:#333,stroke-width:2px
    classDef engine fill:#7f8c8d,stroke:#333,stroke-width:2px
```
