# kgateway-dev/kgateway architecture

> Architecture diagram of the GitHub repository kgateway-dev/kgateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kgateway-dev/kgateway
- Repository: https://github.com/kgateway-dev/kgateway

## Overview

kgateway is a Kubernetes Gateway API control plane that configures Envoy. Users declare Gateways, routes, backends, and policies; controllers reconcile them, query and translate configuration, and synchronize xDS resources to connected Envoy proxies. The repository also contains backend discovery and policy extensions, status reporting, certificate delivery, and control-plane diagnostics. The graph follows documented capabilities and the supplied source index; some subsystem links are omitted where the excerpts do not show their runtime wiring.

Main entry points: [`pkg/pluginsdk/ir/model.go`](https://github.com/kgateway-dev/kgateway/blob/main/pkg/pluginsdk/ir/model.go) (Gateway IR), [`pkg/kgateway/controller/gw_controller.go`](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/controller/gw_controller.go) (Gateway reconciler), [`api/v1alpha1/kgateway/backend_types.go`](https://github.com/kgateway-dev/kgateway/blob/main/api/v1alpha1/kgateway/backend_types.go) (Gateway API resources), [`pkg/kgateway/proxy_syncer/perclient.go`](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/proxy_syncer/perclient.go) (xDS synchronization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_reconcile["Kubernetes Reconciliation"]
  node_api["Gateway API resources<br/>[backend_types.go]"]
  node_gateway_controller["Gateway reconciler<br/>[gw_controller.go]"]
  node_controller_setup["Controller setup<br/>[controller.go]"]
  node_collections[("Kubernetes collections")]
  node_deployer["Proxy deployment"]
end

subgraph group_translate["Configuration Translation"]
  node_query["Route and backend queries<br/>[query.go]"]
  node_route_translator["Route translation"]
  node_translator["IR translation"]
  node_ir["Gateway IR<br/>[model.go]"]
end

subgraph group_runtime["Envoy Runtime"]
  node_proxy_syncer["xDS synchronization<br/>[perclient.go]"]
  node_envoy(("Envoy proxy"))
  node_sds["Secret discovery<br/>[server.go]"]
  node_bootstrap["OAuth secret bootstrap<br/>[controller.go]"]
  node_envoy_init["Envoy initialization<br/>[run.go]"]
end

subgraph group_extensions["Gateway Capabilities"]
  node_policy_plugins["Traffic policies"]
  node_backend_plugins["Backend discovery<br/>[plugin.go]"]
  node_service_entry["Service entries<br/>[plugin.go]"]
  node_oauth_types["OAuth policy types<br/>[oauth2.go]"]
  node_rustformation["Rust HTTP filters<br/>[lib.rs]"]
end

subgraph group_operations["Status and Operations"]
  node_status["Status reporting<br/>[status.go]"]
  node_admin["Admin diagnostics<br/>[server.go]"]
  node_validator["Configuration validation<br/>[validator.go]"]
end

node_operator(("Kubernetes user"))

node_operator -->|"declares"| node_api
node_api -.->|"reconciles"| node_gateway_controller
node_controller_setup -->|"registers"| node_gateway_controller
node_gateway_controller -->|"requests objects"| node_deployer
node_controller_setup -->|"configures"| node_collections
node_query -->|"queries"| node_collections
node_route_translator -.->|"resolves routes"| node_query
node_translator -.->|"produces"| node_ir
node_policy_plugins -.->|"contributes policies"| node_ir
node_backend_plugins -.->|"contributes backends"| node_ir
node_service_entry -.->|"contributes endpoints"| node_ir
node_deployer -.->|"deploys proxies"| node_envoy
node_proxy_syncer -->|"reads IR"| node_ir
node_proxy_syncer -->|"sends xDS"| node_envoy
node_envoy -.->|"requests secrets"| node_sds
node_bootstrap -->|"supports OAuth2"| node_api
node_envoy_init -.->|"starts Envoy"| node_envoy
node_gateway_controller -->|"reports status"| node_status
node_validator -.->|"validates"| node_api
node_oauth_types -.->|"configures OAuth2"| node_policy_plugins
node_rustformation -.->|"extends filters"| node_envoy
node_admin -.->|"exposes snapshots"| node_proxy_syncer

click node_api "https://github.com/kgateway-dev/kgateway/blob/main/api/v1alpha1/kgateway/backend_types.go"
click node_gateway_controller "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/controller/gw_controller.go"
click node_controller_setup "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/controller/controller.go"
click node_collections "https://github.com/kgateway-dev/kgateway/tree/main/pkg/krtcollections"
click node_query "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/query/query.go"
click node_route_translator "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/translator/httproute/gateway_http_route_translator.go"
click node_translator "https://github.com/kgateway-dev/kgateway/tree/main/pkg/kgateway/translator/irtranslator"
click node_ir "https://github.com/kgateway-dev/kgateway/blob/main/pkg/pluginsdk/ir/model.go"
click node_policy_plugins "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go"
click node_backend_plugins "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/extensions2/plugins/backend/plugin.go"
click node_service_entry "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/extensions2/plugins/serviceentry/plugin.go"
click node_deployer "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/deployer/deployer_factory.go"
click node_proxy_syncer "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/proxy_syncer/perclient.go"
click node_sds "https://github.com/kgateway-dev/kgateway/blob/main/pkg/sds/server/server.go"
click node_bootstrap "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/bootstrap/controller.go"
click node_envoy_init "https://github.com/kgateway-dev/kgateway/blob/main/pkg/envoyinit/run.go"
click node_status "https://github.com/kgateway-dev/kgateway/blob/main/pkg/reports/status.go"
click node_admin "https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/admin/server.go"
click node_validator "https://github.com/kgateway-dev/kgateway/blob/main/pkg/validator/validator.go"
click node_oauth_types "https://github.com/kgateway-dev/kgateway/blob/main/api/v1alpha1/kgateway/oauth2.go"
click node_rustformation "https://github.com/kgateway-dev/kgateway/blob/main/internal/envoy_modules/filters/rustformation/src/lib.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_gateway_controller,node_controller_setup,node_collections,node_deployer,node_operator toneBlue
class node_query,node_route_translator,node_translator,node_ir toneAmber
class node_proxy_syncer,node_envoy,node_sds,node_bootstrap,node_envoy_init toneMint
class node_policy_plugins,node_backend_plugins,node_service_entry,node_oauth_types,node_rustformation toneRose
class node_status,node_admin,node_validator toneIndigo
```

## Components

### Kubernetes Reconciliation

- [Gateway API resources](https://github.com/kgateway-dev/kgateway/blob/main/api/v1alpha1/kgateway/backend_types.go): `api/v1alpha1/kgateway/backend_types.go`
- [Gateway reconciler](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/controller/gw_controller.go): `pkg/kgateway/controller/gw_controller.go`
- [Controller setup](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/controller/controller.go): `pkg/kgateway/controller/controller.go`
- [Kubernetes collections](https://github.com/kgateway-dev/kgateway/tree/main/pkg/krtcollections): `pkg/krtcollections`
- [Proxy deployment](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/deployer/deployer_factory.go): `pkg/kgateway/deployer/deployer_factory.go`

### Configuration Translation

- [Route and backend queries](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/query/query.go): `pkg/kgateway/query/query.go`
- [Route translation](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/translator/httproute/gateway_http_route_translator.go): `pkg/kgateway/translator/httproute/gateway_http_route_translator.go`
- [IR translation](https://github.com/kgateway-dev/kgateway/tree/main/pkg/kgateway/translator/irtranslator): `pkg/kgateway/translator/irtranslator`
- [Gateway IR](https://github.com/kgateway-dev/kgateway/blob/main/pkg/pluginsdk/ir/model.go): `pkg/pluginsdk/ir/model.go`

### Envoy Runtime

- [xDS synchronization](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/proxy_syncer/perclient.go): `pkg/kgateway/proxy_syncer/perclient.go`
- **Envoy proxy**
- [Secret discovery](https://github.com/kgateway-dev/kgateway/blob/main/pkg/sds/server/server.go): `pkg/sds/server/server.go`
- [OAuth secret bootstrap](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/bootstrap/controller.go): `pkg/kgateway/bootstrap/controller.go`
- [Envoy initialization](https://github.com/kgateway-dev/kgateway/blob/main/pkg/envoyinit/run.go): `pkg/envoyinit/run.go`

### Gateway Capabilities

- [Traffic policies](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go): `pkg/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go`
- [Backend discovery](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/extensions2/plugins/backend/plugin.go): `pkg/kgateway/extensions2/plugins/backend/plugin.go`
- [Service entries](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/extensions2/plugins/serviceentry/plugin.go): `pkg/kgateway/extensions2/plugins/serviceentry/plugin.go`
- [OAuth policy types](https://github.com/kgateway-dev/kgateway/blob/main/api/v1alpha1/kgateway/oauth2.go): `api/v1alpha1/kgateway/oauth2.go`
- [Rust HTTP filters](https://github.com/kgateway-dev/kgateway/blob/main/internal/envoy_modules/filters/rustformation/src/lib.rs): `internal/envoy_modules/filters/rustformation/src/lib.rs`

### Status and Operations

- [Status reporting](https://github.com/kgateway-dev/kgateway/blob/main/pkg/reports/status.go): `pkg/reports/status.go`
- [Admin diagnostics](https://github.com/kgateway-dev/kgateway/blob/main/pkg/kgateway/admin/server.go): `pkg/kgateway/admin/server.go`
- [Configuration validation](https://github.com/kgateway-dev/kgateway/blob/main/pkg/validator/validator.go): `pkg/validator/validator.go`

### Other components

- **Kubernetes user**

## Connections

- Kubernetes user → Gateway API resources: declares (evidence: `README.md`)
- Gateway API resources → Gateway reconciler: reconciles
- Controller setup → Gateway reconciler: registers (evidence: `pkg/kgateway/controller/controller.go`)
- Gateway reconciler → Proxy deployment: requests objects (evidence: `pkg/kgateway/controller/gw_controller.go`)
- Controller setup → Kubernetes collections: configures (evidence: `pkg/kgateway/controller/controller.go`)
- Route and backend queries → Kubernetes collections: queries (evidence: `pkg/kgateway/query/query.go`)
- Route translation → Route and backend queries: resolves routes
- IR translation → Gateway IR: produces
- Traffic policies → Gateway IR: contributes policies
- Backend discovery → Gateway IR: contributes backends
- Service entries → Gateway IR: contributes endpoints
- Proxy deployment → Envoy proxy: deploys proxies
- xDS synchronization → Gateway IR: reads IR (evidence: `pkg/kgateway/proxy_syncer/perclient.go`)
- xDS synchronization → Envoy proxy: sends xDS (evidence: `README.md`)
- Envoy proxy → Secret discovery: requests secrets
- OAuth secret bootstrap → Gateway API resources: supports OAuth2 (evidence: `pkg/kgateway/bootstrap/controller.go`)
- Envoy initialization → Envoy proxy: starts Envoy
- Gateway reconciler → Status reporting: reports status (evidence: `pkg/kgateway/controller/gw_controller.go`)
- Configuration validation → Gateway API resources: validates
- OAuth policy types → Traffic policies: configures OAuth2
- Rust HTTP filters → Envoy proxy: extends filters
- Admin diagnostics → xDS synchronization: exposes snapshots
