# caapim/layer7-operator architecture

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

- Interactive diagram: https://gitdiagram.com/caapim/layer7-operator
- Repository: https://github.com/caapim/layer7-operator

## Overview

Layer7 Gateway Operator is a Kubernetes operator for deploying, maintaining, and upgrading Layer7 API Gateways. Its principal workflow starts when a user creates or changes a Kubernetes custom resource; a controller reconciles that resource and applies the desired cluster state. Separate controllers handle Gateway infrastructure, API deployment, repositories, portals, and state stores. API deployment and repository synchronization also involve bundle/Graphman processing and state persistence. The graph reflects documented capabilities and shown controller calls; some internal links are dashed because the relevant implementation was not excerpted.

Main entry points: [`pkg/api/reconcile/l7api.go`](https://github.com/caapim/layer7-operator/blob/main/pkg/api/reconcile/l7api.go) (API deployment), [`pkg/repository/reconcile/repository.go`](https://github.com/caapim/layer7-operator/blob/main/pkg/repository/reconcile/repository.go) (Repository sync), [`internal/controller/gateway/controller.go`](https://github.com/caapim/layer7-operator/blob/main/internal/controller/gateway/controller.go) (Gateway controller), [`internal/controller/api/controller.go`](https://github.com/caapim/layer7-operator/blob/main/internal/controller/api/controller.go) (API controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_controllers["Resource Controllers"]
  node_gateway_cr["Gateway resource<br/>[gateway_types.go]"]
  node_api_cr["L7Api resource<br/>[l7api_types.go]"]
  node_repo_cr["Repository resource"]
  node_portal_cr["L7Portal resource<br/>[l7portal_types.go]"]
  node_state_cr["L7StateStore resource"]
  node_gateway_controller["Gateway controller<br/>[controller.go]"]
  node_api_controller["API controller<br/>[controller.go]"]
  node_repo_controller["Repository controller<br/>[controller.go]"]
  node_portal_controller["Portal controller<br/>[controller.go]"]
  node_state_controller["State controller<br/>[controller.go]"]
end

subgraph group_gateway["Gateway Runtime"]
  node_gateway_reconcile["Gateway reconciliation<br/>[gateway.go]"]
  node_gateway_resources["Gateway services<br/>[service.go]"]
end

subgraph group_api["API Deployment"]
  node_api_reconcile["API deployment<br/>[l7api.go]"]
  node_api_bundle["API bundle tools<br/>[bundle.go]"]
  node_templates["Portal templates<br/>[templategen.go]"]
end

subgraph group_content["Content Sources"]
  node_graphman["Graphman processing<br/>[graphman.go]"]
  node_bundle_util["Bundle utilities<br/>[bundle.go]"]
  node_repo_reconcile["Repository sync<br/>[repository.go]"]
  node_repo_state["Repository state storage<br/>[statestorage.go]"]
end

subgraph group_state["Portal And State"]
  node_portal_reconcile["Portal jobs<br/>[portal.go]"]
  node_state_reconcile["State store setup<br/>[statestore.go]"]
  node_redis[("Redis state store")]
end

node_operator(("Kubernetes user"))
node_cluster[("Kubernetes API")]

node_operator -.->|"applies resources"| node_cluster
node_cluster -.->|"triggers reconcile"| node_gateway_controller
node_cluster -->|"triggers reconcile"| node_api_controller
node_cluster -->|"triggers reconcile"| node_repo_controller
node_cluster -->|"triggers reconcile"| node_portal_controller
node_cluster -->|"triggers reconcile"| node_state_controller
node_gateway_cr -.->|"stored in"| node_cluster
node_api_cr -->|"stored in"| node_cluster
node_repo_cr -->|"stored in"| node_cluster
node_portal_cr -->|"stored in"| node_cluster
node_state_cr -->|"stored in"| node_cluster
node_gateway_controller -.->|"runs operations"| node_gateway_reconcile
node_gateway_reconcile -.->|"creates desired services"| node_gateway_resources
node_gateway_controller -->|"reads resources"| node_cluster
node_api_controller -->|"calls reconcile steps"| node_api_reconcile
node_api_reconcile -.->|"uses bundle tools"| node_api_bundle
node_api_reconcile -->|"builds policy templates"| node_templates
node_api_reconcile -->|"deploys to gateways"| node_cluster
node_repo_controller -.->|"runs sync steps"| node_repo_reconcile
node_repo_reconcile -->|"validates bundles"| node_bundle_util
node_repo_reconcile -.->|"uses Graphman"| node_graphman
node_repo_reconcile -.->|"reconciles state"| node_repo_state
node_repo_state -->|"reads and writes"| node_redis
node_portal_controller -->|"runs portal jobs"| node_portal_reconcile
node_state_controller -->|"sets up state store"| node_state_reconcile
node_state_reconcile -.->|"configures Redis"| node_redis

click node_gateway_cr "https://github.com/caapim/layer7-operator/blob/main/api/v1/gateway_types.go"
click node_api_cr "https://github.com/caapim/layer7-operator/blob/main/api/v1alpha1/l7api_types.go"
click node_repo_cr "https://github.com/caapim/layer7-operator/blob/main/api/v1/repository_types.go"
click node_portal_cr "https://github.com/caapim/layer7-operator/blob/main/api/v1alpha1/l7portal_types.go"
click node_state_cr "https://github.com/caapim/layer7-operator/blob/main/api/v1alpha1/l7statestore_types.go"
click node_gateway_controller "https://github.com/caapim/layer7-operator/blob/main/internal/controller/gateway/controller.go"
click node_api_controller "https://github.com/caapim/layer7-operator/blob/main/internal/controller/api/controller.go"
click node_repo_controller "https://github.com/caapim/layer7-operator/blob/main/internal/controller/repository/controller.go"
click node_portal_controller "https://github.com/caapim/layer7-operator/blob/main/internal/controller/portal/controller.go"
click node_state_controller "https://github.com/caapim/layer7-operator/blob/main/internal/controller/statestore/controller.go"
click node_gateway_reconcile "https://github.com/caapim/layer7-operator/blob/main/pkg/gateway/reconcile/gateway.go"
click node_gateway_resources "https://github.com/caapim/layer7-operator/blob/main/pkg/gateway/service.go"
click node_api_reconcile "https://github.com/caapim/layer7-operator/blob/main/pkg/api/reconcile/l7api.go"
click node_api_bundle "https://github.com/caapim/layer7-operator/blob/main/pkg/api/bundle.go"
click node_templates "https://github.com/caapim/layer7-operator/blob/main/internal/templategen/templategen.go"
click node_graphman "https://github.com/caapim/layer7-operator/blob/main/internal/graphman/graphman.go"
click node_bundle_util "https://github.com/caapim/layer7-operator/blob/main/pkg/util/bundle.go"
click node_repo_reconcile "https://github.com/caapim/layer7-operator/blob/main/pkg/repository/reconcile/repository.go"
click node_repo_state "https://github.com/caapim/layer7-operator/blob/main/pkg/repository/reconcile/statestorage.go"
click node_portal_reconcile "https://github.com/caapim/layer7-operator/blob/main/pkg/portal/reconcile/portal.go"
click node_state_reconcile "https://github.com/caapim/layer7-operator/blob/main/pkg/statestore/reconcile/statestore.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_gateway_cr,node_api_cr,node_repo_cr,node_portal_cr,node_state_cr,node_gateway_controller,node_api_controller,node_repo_controller,node_portal_controller,node_state_controller,node_operator toneBlue
class node_gateway_reconcile,node_gateway_resources,node_cluster toneAmber
class node_api_reconcile,node_api_bundle,node_templates toneMint
class node_graphman,node_bundle_util,node_repo_reconcile,node_repo_state toneRose
class node_portal_reconcile,node_state_reconcile,node_redis toneIndigo
```

## Components

### Resource Controllers

- [Gateway resource](https://github.com/caapim/layer7-operator/blob/main/api/v1/gateway_types.go): `api/v1/gateway_types.go`
- [L7Api resource](https://github.com/caapim/layer7-operator/blob/main/api/v1alpha1/l7api_types.go): `api/v1alpha1/l7api_types.go`
- [Repository resource](https://github.com/caapim/layer7-operator/blob/main/api/v1/repository_types.go): `api/v1/repository_types.go`
- [L7Portal resource](https://github.com/caapim/layer7-operator/blob/main/api/v1alpha1/l7portal_types.go): `api/v1alpha1/l7portal_types.go`
- [L7StateStore resource](https://github.com/caapim/layer7-operator/blob/main/api/v1alpha1/l7statestore_types.go): `api/v1alpha1/l7statestore_types.go`
- [Gateway controller](https://github.com/caapim/layer7-operator/blob/main/internal/controller/gateway/controller.go): `internal/controller/gateway/controller.go`
- [API controller](https://github.com/caapim/layer7-operator/blob/main/internal/controller/api/controller.go): `internal/controller/api/controller.go`
- [Repository controller](https://github.com/caapim/layer7-operator/blob/main/internal/controller/repository/controller.go): `internal/controller/repository/controller.go`
- [Portal controller](https://github.com/caapim/layer7-operator/blob/main/internal/controller/portal/controller.go): `internal/controller/portal/controller.go`
- [State controller](https://github.com/caapim/layer7-operator/blob/main/internal/controller/statestore/controller.go): `internal/controller/statestore/controller.go`

### Gateway Runtime

- [Gateway reconciliation](https://github.com/caapim/layer7-operator/blob/main/pkg/gateway/reconcile/gateway.go): `pkg/gateway/reconcile/gateway.go`
- [Gateway services](https://github.com/caapim/layer7-operator/blob/main/pkg/gateway/service.go): `pkg/gateway/service.go`

### API Deployment

- [API deployment](https://github.com/caapim/layer7-operator/blob/main/pkg/api/reconcile/l7api.go): `pkg/api/reconcile/l7api.go`
- [API bundle tools](https://github.com/caapim/layer7-operator/blob/main/pkg/api/bundle.go): `pkg/api/bundle.go`
- [Portal templates](https://github.com/caapim/layer7-operator/blob/main/internal/templategen/templategen.go): `internal/templategen/templategen.go`

### Content Sources

- [Graphman processing](https://github.com/caapim/layer7-operator/blob/main/internal/graphman/graphman.go): `internal/graphman/graphman.go`
- [Bundle utilities](https://github.com/caapim/layer7-operator/blob/main/pkg/util/bundle.go): `pkg/util/bundle.go`
- [Repository sync](https://github.com/caapim/layer7-operator/blob/main/pkg/repository/reconcile/repository.go): `pkg/repository/reconcile/repository.go`
- [Repository state storage](https://github.com/caapim/layer7-operator/blob/main/pkg/repository/reconcile/statestorage.go): `pkg/repository/reconcile/statestorage.go`

### Portal And State

- [Portal jobs](https://github.com/caapim/layer7-operator/blob/main/pkg/portal/reconcile/portal.go): `pkg/portal/reconcile/portal.go`
- [State store setup](https://github.com/caapim/layer7-operator/blob/main/pkg/statestore/reconcile/statestore.go): `pkg/statestore/reconcile/statestore.go`
- **Redis state store**

### Other components

- **Kubernetes user**
- **Kubernetes API**

## Connections

- Kubernetes user → Kubernetes API: applies resources (evidence: `README.md`)
- Kubernetes API → Gateway controller: triggers reconcile (evidence: `internal/controller/gateway/controller.go`)
- Kubernetes API → API controller: triggers reconcile (evidence: `internal/controller/api/controller.go`)
- Kubernetes API → Repository controller: triggers reconcile (evidence: `internal/controller/repository/controller.go`)
- Kubernetes API → Portal controller: triggers reconcile (evidence: `internal/controller/portal/controller.go`)
- Kubernetes API → State controller: triggers reconcile (evidence: `internal/controller/statestore/controller.go`)
- Gateway resource → Kubernetes API: stored in (evidence: `README.md`)
- L7Api resource → Kubernetes API: stored in
- Repository resource → Kubernetes API: stored in
- L7Portal resource → Kubernetes API: stored in
- L7StateStore resource → Kubernetes API: stored in
- Gateway controller → Gateway reconciliation: runs operations
- Gateway reconciliation → Gateway services: creates desired services
- Gateway controller → Kubernetes API: reads resources (evidence: `internal/controller/gateway/controller.go`)
- API controller → API deployment: calls reconcile steps (evidence: `internal/controller/api/controller.go`)
- API deployment → API bundle tools: uses bundle tools
- API deployment → Portal templates: builds policy templates (evidence: `pkg/api/reconcile/l7api.go`)
- API deployment → Kubernetes API: deploys to gateways (evidence: `pkg/api/reconcile/l7api.go`)
- Repository controller → Repository sync: runs sync steps
- Repository sync → Bundle utilities: validates bundles (evidence: `pkg/repository/reconcile/repository.go`)
- Repository sync → Graphman processing: uses Graphman
- Repository sync → Repository state storage: reconciles state
- Repository state storage → Redis state store: reads and writes (evidence: `pkg/repository/reconcile/statestorage.go`)
- Portal controller → Portal jobs: runs portal jobs (evidence: `internal/controller/portal/controller.go`)
- State controller → State store setup: sets up state store (evidence: `internal/controller/statestore/controller.go`)
- State store setup → Redis state store: configures Redis
