# kubernetes-sigs/gateway-api architecture

> Architecture diagram of the GitHub repository kubernetes-sigs/gateway-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kubernetes-sigs/gateway-api
- Repository: https://github.com/kubernetes-sigs/gateway-api

## Overview

##### Project type and purpose
- This is an open-source Kubernetes API specification repository. It defines Custom Resource Definitions (CRDs) and Go types for the Gateway API, provides code-generation pipelines, client libraries, a CLI (gwctl), a conformance test suite, examples, and documentation. Its purpose is to define the schema, tooling, tests, and docs that implementers and users of the Kubernetes Gateway API rely on.

##### Main components
- apis/…: Go type definitions for each API version (v1, v1alpha2, v1beta1, apisx, etc.)
- config/crd/: YAML manifests for CRDs (standard and experimental)
- applyconfiguration/: Builder-pattern code for server-side apply API objects
- pkg/client/: Generated clientset, informers, and listers for controllers and tools
- gwctl/: A standalone CLI that interacts with Gateway CRs via the client libraries
- hack/: Shell and Go scripts orchestrating codegen, CRD generation, docs build, tests, and deployments
- conformance/: End-to-end test suite (Go tests, example echo servers, YAML definitions) to validate Gateway API implementations
- examples/: Sample YAML definitions demonstrating API usage across versions and features
- site-src/ & mkdocs.yml: Documentation and website source for the project site
- pkg/generator, pkg/test, pkg/utils: Internal tools for code/docs generation and API validation

##### Relationships and interactions
- Source code in apis/ → hack/codegen scripts → generate deepcopy, registration, OpenAPI, clientset, applyconfiguration, and CRD YAML.
- Generated CRDs ↑ applied to a Kubernetes API server (cluster).
- External Gateway controllers (e.g., Envoy Gateway, Istio, Traefik) use pkg/client informers/listers to watch and reconcile CRs in the cluster.
- gwctl CLI uses the same generated clientset to read and manipulate CRs in the cluster.
- conformance suite deploys the CRDs and a test controller (echo servers), then runs Go and YAML tests to validate that controllers honor the spec.
- examples/ and docs/ guide users through creating CRs and running controllers.

##### Architectural patterns and design principles
- Schema-first approach: API definitions drive CRD and client code generation.
- Code generation: DeepCopy, registration, OpenAPI, clientset, informers, applyconfiguration.
- Builder pattern: applyconfiguration package for declarative object creation.
- Informer pattern: Generated shared informers and listers for event-driven controllers.
- Modular versioning: apis/v1, v1alpha2, v1beta1, and apisx for extension points.

##### Essential elements to capture
- Source→Generator→Artifact pipeline
- Generated clients/informers powering controllers and CLI
- CRD YAML and API server
- Conformance suite validating external implementations
- Documentation and examples feeding back into the developer/user workflow

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Code
    subgraph "Source Code"
        direction TB
        API["API Go Types (Core & Versions)"] 
        V1["apis/v1 Go Types"] 
        V1A2["apis/v1alpha2 Go Types"] 
        V1A3["apis/v1alpha3 Go Types"] 
        V1B1["apis/v1beta1 Go Types"] 
        APISX["apisx (Extension API Types)"] 
        APPLYCFG["ApplyConfiguration Builders"] 
        GENMAIN["pkg/generator/main.go"] 
        FEATURES["pkg/features Definitions"] 
        CEL["pkg/test/cel Test Harness"] 
        UTILS["pkg/utils Functions"] 
        MODELSCHEMA["cmd/modelschema/main.go"]
    end

    %% Codegen Pipeline
    subgraph "Code-Generation Pipeline"
        direction TB
        HACK["hack (Codegen & Tooling Scripts)"] 
        MAKE["Makefile / Build Orchestration"]
    end

    %% Generated Artifacts
    subgraph "Generated Artifacts"
        direction TB
        CLIENT["Generated Client Libraries"] 
        INFORMERS["Generated Informers"] 
        LISTERS["Generated Listers"] 
        OPENAPI["Generated OpenAPI Specs"] 
        CRDSTD["CRD Manifests (Standard)"] 
        CRDEXP["CRD Manifests (Experimental)"]
    end

    %% Kubernetes Runtime
    subgraph "Kubernetes Cluster"
        direction TB
        K8S["K8s API Server with CRDs"] 
        CONTROLLERS["Gateway Controllers (Envoy, Istio, Traefik)"] 
    end

    %% CLI
    GWCTL["gwctl CLI"]

    %% Conformance Suite
    subgraph "Conformance Test Suite"
        direction TB
        CONFORM["Conformance Suite"] 
        ECHO["Conformance Echo Server (basic)"] 
        MESH["Conformance Mesh Tests"] 
        TESTDEF["Conformance Test Definitions"] 
        CONFUTIL["Conformance Utilities"]
    end

    %% Documentation & Examples
    subgraph "Docs & Examples"
        direction TB
        EXSTD["Examples (Standard)"] 
        EXEXP["Examples (Experimental)"] 
        SITESRC["Documentation Site Source"] 
        MKDOCS["mkdocs.yml"]
    end

    %% Relationships
    API -->|codegen| HACK
    V1 -->|codegen| HACK
    V1A2 -->|codegen| HACK
    V1A3 -->|codegen| HACK
    V1B1 -->|codegen| HACK
    APISX -->|codegen| HACK
    APPLYCFG -->|codegen| HACK
    GENMAIN -->|used by| HACK
    FEATURES -->|used by| HACK
    CEL -->|used by| HACK
    UTILS -->|used by| HACK
    MODELSCHEMA -->|used by| HACK

    MAKE -->|invokes| HACK
    HACK -->|generate| CLIENT
    HACK -->|generate| INFORMERS
    HACK -->|generate| LISTERS
    HACK -->|generate| OPENAPI
    HACK -->|generate| CRDSTD
    HACK -->|generate| CRDEXP

    CRDSTD -->|apply CRDs| K8S
    CRDEXP -->|apply CRDs| K8S

    CLIENT -->|watch & reconcile| CONTROLLERS
    INFORMERS -->|watch & reconcile| CONTROLLERS
    LISTERS -->|watch & reconcile| CONTROLLERS

    CLIENT -->|used by| GWCTL
    GWCTL -->|watch & mutate| K8S

    CONFORM -->|deploy CRDs & tests| K8S
    CONFORM -->|use echo| ECHO
    CONFORM -->|run mesh tests| MESH
    CONFORM -->|use definitions| TESTDEF
    CONFORM -->|use utils| CONFUTIL

    EXSTD -->|apply examples| K8S
    EXEXP -->|apply examples| K8S

    SITESRC -->|build site| MKDOCS
    MKDOCS -->|publish site| SITESRC

    %% Click events
    click API "https://github.com/kubernetes-sigs/gateway-api/tree/main/apis/"
    click V1 "https://github.com/kubernetes-sigs/gateway-api/tree/main/apis/v1/"
    click V1A2 "https://github.com/kubernetes-sigs/gateway-api/tree/main/apis/v1alpha2/"
    click V1A3 "https://github.com/kubernetes-sigs/gateway-api/tree/main/apis/v1alpha3/"
    click V1B1 "https://github.com/kubernetes-sigs/gateway-api/tree/main/apis/v1beta1/"
    click APISX "https://github.com/kubernetes-sigs/gateway-api/tree/main/apisx/"
    click CRDSTD "https://github.com/kubernetes-sigs/gateway-api/tree/main/config/crd/standard/"
    click CRDEXP "https://github.com/kubernetes-sigs/gateway-api/tree/main/config/crd/experimental/"
    click APPLYCFG "https://github.com/kubernetes-sigs/gateway-api/tree/main/applyconfiguration/"
    click CLIENT "https://github.com/kubernetes-sigs/gateway-api/tree/main/pkg/client/"
    click INFORMERS "https://github.com/kubernetes-sigs/gateway-api/tree/main/pkg/client/informers/"
    click LISTERS "https://github.com/kubernetes-sigs/gateway-api/tree/main/pkg/client/listers/"
    click GWCTL "https://github.com/kubernetes-sigs/gateway-api/tree/main/gwctl/"
    click HACK "https://github.com/kubernetes-sigs/gateway-api/tree/main/hack/"
    click CONFORM "https://github.com/kubernetes-sigs/gateway-api/tree/main/conformance/"
    click ECHO "https://github.com/kubernetes-sigs/gateway-api/tree/main/conformance/echo-basic/"
    click MESH "https://github.com/kubernetes-sigs/gateway-api/tree/main/conformance/mesh/"
    click TESTDEF "https://github.com/kubernetes-sigs/gateway-api/tree/main/conformance/tests/"
    click CONFUTIL "https://github.com/kubernetes-sigs/gateway-api/tree/main/conformance/utils/"
    click EXSTD "https://github.com/kubernetes-sigs/gateway-api/tree/main/examples/standard/"
    click EXEXP "https://github.com/kubernetes-sigs/gateway-api/tree/main/examples/experimental/"
    click SITESRC "https://github.com/kubernetes-sigs/gateway-api/tree/main/site-src/"
    click MKDOCS "https://github.com/kubernetes-sigs/gateway-api/blob/main/mkdocs.yml"
    click MAKE "https://github.com/kubernetes-sigs/gateway-api/tree/main/Makefile"
    click GENMAIN "https://github.com/kubernetes-sigs/gateway-api/blob/main/pkg/generator/main.go"
    click CEL "https://github.com/kubernetes-sigs/gateway-api/tree/main/pkg/test/cel/"
    click UTILS "https://github.com/kubernetes-sigs/gateway-api/tree/main/pkg/utils/"
    click FEATURES "https://github.com/kubernetes-sigs/gateway-api/tree/main/pkg/features/"
    click MODELSCHEMA "https://github.com/kubernetes-sigs/gateway-api/blob/main/cmd/modelschema/main.go"

    %% Styles
    classDef code fill:#E3F2FD,stroke:#0D47A1,color:#0D47A1
    classDef runtime fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef tooling fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef docs fill:#ECEFF1,stroke:#37474F,color:#37474F

    class API,V1,V1A2,V1A3,V1B1,APISX,APPLYCFG,GENMAIN,FEATURES,CEL,UTILS,MODELSCHEMA code
    class HACK,MAKE,CONFORM tooling
    class CLIENT,INFORMERS,LISTERS,OPENAPI,CRDSTD,CRDEXP code
    class K8S,CONTROLLERS runtime
    class GWCTL tooling
    class ECHO,MESH,TESTDEF,CONFUTIL tooling
    class EXSTD,EXEXP,SITESRC,MKDOCS docs
```
