# haproxytech/haproxy-unified-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/haproxytech/haproxy-unified-gateway
- Repository: https://github.com/haproxytech/haproxy-unified-gateway

## Overview

HUG is a Kubernetes gateway controller that translates Gateway API resources (and also has Ingress-related code) into HAProxy configuration and runtime updates. The principal flow is Kubernetes events through reconciliation and route modeling, into HAProxy configuration and map updates, then through the HAProxy client. The README documents Gateway API integration; Ingress support is visible in the source tree, though the README describes it as forthcoming. Edges are limited to relationships shown in excerpts or SOURCE INDEX references; unsampled subsystem links are omitted.

Main entry points: [`k8s/gate/controller.go`](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/controller.go) (Controller), [`cmd/controller/main.go`](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/cmd/controller/main.go) (Controller entrypoint), [`k8s/gate/tree`](https://github.com/haproxytech/haproxy-unified-gateway/tree/dev/k8s/gate/tree) (Gateway and route tree), [`hug/haproxy/main.go`](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/haproxy/main.go) (HAProxy app manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Controller runtime"]
  node_controller["Controller<br/>[controller.go]"]
  node_status["Resource status"]
  node_entrypoint["Controller entrypoint<br/>[main.go]"]
end

subgraph group_model["Kubernetes model"]
  node_resources["Gateway resources"]
  node_ingress["Ingress resources<br/>[ingress_builder.go]"]
  node_tree["Gateway and route tree"]
  node_references["Reference grants"]
end

subgraph group_routing["HAProxy routing"]
  node_routeconfig["Route configuration<br/>[routes.go]"]
  node_route_maps["Route maps<br/>[routes-maps.go]"]
  node_map_storage[("Map state and files<br/>[mapsmanager.go]")]
  node_configuration["HAProxy configuration<br/>[configuration.go]"]
end

subgraph group_runtime["HAProxy runtime"]
  node_app_manager["HAProxy app manager<br/>[main.go]"]
  node_api_client["HAProxy API client<br/>[client.go]"]
  node_process["HAProxy process control<br/>[interface.go]"]
  node_startup["Startup configuration<br/>[startup.go]"]
end

node_operator(("Kubernetes user"))
node_haproxy(("HAProxy"))

node_operator -->|"creates"| node_resources
node_resources -->|"watched by"| node_controller
node_ingress -.->|"watched by"| node_controller
node_controller -.->|"reconciles"| node_tree
node_tree -.->|"checks grants"| node_references
node_controller -.->|"updates status"| node_status
node_tree -->|"provides routes"| node_routeconfig
node_routeconfig -->|"fills maps"| node_route_maps
node_route_maps -->|"updates map state"| node_map_storage
node_controller -.->|"configures routing"| node_routeconfig
node_entrypoint -->|"starts"| node_controller
node_entrypoint -->|"starts"| node_app_manager
node_entrypoint -->|"creates"| node_api_client
node_entrypoint -->|"creates"| node_process
node_app_manager -->|"calls"| node_api_client
node_app_manager -->|"controls"| node_process
node_api_client -.->|"applies configuration"| node_haproxy
node_startup -->|"loads initial config"| node_configuration

click node_resources "https://github.com/haproxytech/haproxy-unified-gateway/tree/dev/api/gate/v3"
click node_ingress "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/tree/ingress_builder.go"
click node_controller "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/controller.go"
click node_tree "https://github.com/haproxytech/haproxy-unified-gateway/tree/dev/k8s/gate/tree"
click node_references "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/tree/reference_grant_manager.go"
click node_status "https://github.com/haproxytech/haproxy-unified-gateway/tree/dev/k8s/gate/status"
click node_routeconfig "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/routes.go"
click node_route_maps "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/routes-maps.go"
click node_map_storage "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/storage/maps/mapsmanager.go"
click node_configuration "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/configuration.go"
click node_app_manager "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/haproxy/main.go"
click node_api_client "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/haproxy/api/client.go"
click node_process "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/haproxy/process/interface.go"
click node_startup "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/startup/startup.go"
click node_entrypoint "https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/cmd/controller/main.go"

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_controller,node_status,node_entrypoint,node_operator toneBlue
class node_resources,node_ingress,node_tree,node_references toneAmber
class node_routeconfig,node_route_maps,node_map_storage,node_configuration toneMint
class node_app_manager,node_api_client,node_process,node_startup toneRose
class node_haproxy toneIndigo
```

## Components

### Controller runtime

- [Controller](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/controller.go): `k8s/gate/controller.go`
- [Resource status](https://github.com/haproxytech/haproxy-unified-gateway/tree/dev/k8s/gate/status): `k8s/gate/status`
- [Controller entrypoint](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/cmd/controller/main.go): `cmd/controller/main.go`

### Kubernetes model

- [Gateway resources](https://github.com/haproxytech/haproxy-unified-gateway/tree/dev/api/gate/v3): `api/gate/v3`
- [Ingress resources](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/tree/ingress_builder.go): `k8s/gate/tree/ingress_builder.go`
- [Gateway and route tree](https://github.com/haproxytech/haproxy-unified-gateway/tree/dev/k8s/gate/tree): `k8s/gate/tree`
- [Reference grants](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/tree/reference_grant_manager.go): `k8s/gate/tree/reference_grant_manager.go`

### HAProxy routing

- [Route configuration](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/routes.go): `k8s/gate/haproxy/routes.go`
- [Route maps](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/routes-maps.go): `k8s/gate/haproxy/routes-maps.go`
- [Map state and files](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/storage/maps/mapsmanager.go): `k8s/gate/haproxy/storage/maps/mapsmanager.go`
- [HAProxy configuration](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/k8s/gate/haproxy/configuration.go): `k8s/gate/haproxy/configuration.go`

### HAProxy runtime

- [HAProxy app manager](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/haproxy/main.go): `hug/haproxy/main.go`
- [HAProxy API client](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/haproxy/api/client.go): `hug/haproxy/api/client.go`
- [HAProxy process control](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/haproxy/process/interface.go): `hug/haproxy/process/interface.go`
- [Startup configuration](https://github.com/haproxytech/haproxy-unified-gateway/blob/dev/hug/startup/startup.go): `hug/startup/startup.go`

### Other components

- **Kubernetes user**
- **HAProxy**

## Connections

- Kubernetes user → Gateway resources: creates
- Gateway resources → Controller: watched by (evidence: `k8s/gate/controller.go`)
- Ingress resources → Controller: watched by
- Controller → Gateway and route tree: reconciles
- Gateway and route tree → Reference grants: checks grants
- Controller → Resource status: updates status
- Gateway and route tree → Route configuration: provides routes (evidence: `k8s/gate/haproxy/routes.go`)
- Route configuration → Route maps: fills maps (evidence: `k8s/gate/haproxy/routes.go`)
- Route maps → Map state and files: updates map state (evidence: `k8s/gate/haproxy/routes-maps.go`)
- Controller → Route configuration: configures routing
- Controller entrypoint → Controller: starts (evidence: `cmd/controller/main.go`)
- Controller entrypoint → HAProxy app manager: starts (evidence: `cmd/controller/main.go`)
- Controller entrypoint → HAProxy API client: creates (evidence: `cmd/controller/main.go`)
- Controller entrypoint → HAProxy process control: creates (evidence: `cmd/controller/main.go`)
- HAProxy app manager → HAProxy API client: calls (evidence: `hug/haproxy/main.go`)
- HAProxy app manager → HAProxy process control: controls (evidence: `hug/haproxy/main.go`)
- HAProxy API client → HAProxy: applies configuration
- Startup configuration → HAProxy configuration: loads initial config (evidence: `hug/startup/startup.go`)
