# akira-core/kube-state-graph architecture

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

- Interactive diagram: https://gitdiagram.com/akira-core/kube-state-graph
- Repository: https://github.com/akira-core/kube-state-graph

## Overview

kube-state-graph is a Go REST service that builds multi-cluster Kubernetes workload and storage graphs from VictoriaMetrics data. The main workflow is an HTTP graph request, shared request parsing and filtering, PromQL retrieval, graph construction/projection, and Cytoscape JSON serialization. The README also documents a separate storage-graph endpoint and authentication, health, metrics, and documentation routes. The excerpts show the API and graph-engine seams, but not the complete query/build implementation; edges reflect only shown calls or documented relationships.

Main entry points: [`pkg/kubegraph/engine.go`](https://github.com/akira-core/kube-state-graph/blob/main/pkg/kubegraph/engine.go) (Graph engine), [`internal/api/handlers.go`](https://github.com/akira-core/kube-state-graph/blob/main/internal/api/handlers.go) (Graph handlers), [`pkg/route/resolver.go`](https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/resolver.go) (Route resolver), [`internal/api/server.go`](https://github.com/akira-core/kube-state-graph/blob/main/internal/api/server.go) (HTTP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["HTTP server<br/>[server.go]"]
  node_handlers["Graph handlers<br/>[handlers.go]"]
  node_auth["API key auth<br/>[auth_middleware.go]"]
  node_config["Runtime config<br/>[config.go]"]
end

subgraph group_engine["Graph engine"]
  node_parse["Request parsing<br/>[parse.go]"]
  node_enginecore["Graph engine<br/>[engine.go]"]
  node_graph["Graph model"]
  node_project["Graph projection<br/>[project.go]"]
  node_storageproject["Storage projection<br/>[project_storage.go]"]
  node_serializer["Cytoscape output<br/>[cytoscape.go]"]
end

subgraph group_upstream["Metrics access"]
  node_promrouter["PromQL router<br/>[router.go]"]
  node_promclient["VictoriaMetrics client<br/>[client.go]"]
  node_backends["Backend routing config<br/>[backendsfile.go]"]
end

subgraph group_routing["Route resolution"]
  node_route["Route resolver<br/>[resolver.go]"]
  node_snapshot["Config snapshot<br/>[snapshot.go]"]
  node_translate["Route translation<br/>[translate.go]"]
  node_store[("Route config store<br/>[store.go]")]
  node_matchcheck["Route match check<br/>[matchcheck.go]"]
end

node_caller(("API caller"))
node_victoriametrics[("VictoriaMetrics")]

node_caller -->|"requests"| node_server
node_server -->|"routes to"| node_handlers
node_server -.->|"authenticates"| node_auth
node_handlers -->|"parses with"| node_parse
node_handlers -->|"builds via"| node_enginecore
node_handlers -->|"uses"| node_graph
node_handlers -->|"serializes with"| node_serializer
node_enginecore -->|"queries through"| node_promrouter
node_enginecore -->|"builds"| node_graph
node_enginecore -.->|"projects graph"| node_project
node_enginecore -->|"projects storage"| node_storageproject
node_enginecore -->|"serializes result"| node_serializer
node_promrouter -.->|"dispatches queries"| node_promclient
node_promclient -->|"queries metrics"| node_victoriametrics
node_backends -->|"configures routes"| node_promrouter
node_route -->|"loads config"| node_store
node_route -->|"loads snapshot"| node_snapshot
node_route -->|"translates config"| node_translate
node_route -->|"runs checks"| node_matchcheck
node_snapshot -->|"reads data"| node_store
node_snapshot -->|"uses translator"| node_translate
node_translate -->|"resolves gateways"| node_route

click node_server "https://github.com/akira-core/kube-state-graph/blob/main/internal/api/server.go"
click node_handlers "https://github.com/akira-core/kube-state-graph/blob/main/internal/api/handlers.go"
click node_auth "https://github.com/akira-core/kube-state-graph/blob/main/internal/api/auth_middleware.go"
click node_config "https://github.com/akira-core/kube-state-graph/blob/main/internal/config/config.go"
click node_parse "https://github.com/akira-core/kube-state-graph/blob/main/pkg/kubegraph/parse.go"
click node_enginecore "https://github.com/akira-core/kube-state-graph/blob/main/pkg/kubegraph/engine.go"
click node_graph "https://github.com/akira-core/kube-state-graph/tree/main/pkg/graph"
click node_project "https://github.com/akira-core/kube-state-graph/blob/main/pkg/graph/project.go"
click node_storageproject "https://github.com/akira-core/kube-state-graph/blob/main/pkg/graph/project_storage.go"
click node_serializer "https://github.com/akira-core/kube-state-graph/blob/main/pkg/cytoscape/cytoscape.go"
click node_promrouter "https://github.com/akira-core/kube-state-graph/blob/main/pkg/promql/router.go"
click node_promclient "https://github.com/akira-core/kube-state-graph/blob/main/pkg/promql/client.go"
click node_backends "https://github.com/akira-core/kube-state-graph/blob/main/pkg/promql/backendsfile/backendsfile.go"
click node_route "https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/resolver.go"
click node_snapshot "https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/snapshot/snapshot.go"
click node_translate "https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/translate/translate.go"
click node_store "https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/store/store.go"
click node_matchcheck "https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/matchcheck/matchcheck.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_server,node_handlers,node_auth,node_config toneBlue
class node_parse,node_enginecore,node_graph,node_project,node_storageproject,node_serializer,node_victoriametrics toneAmber
class node_promrouter,node_promclient,node_backends,node_caller toneMint
class node_route,node_snapshot,node_translate,node_store,node_matchcheck toneRose
```

## Components

### HTTP API

- [HTTP server](https://github.com/akira-core/kube-state-graph/blob/main/internal/api/server.go): `internal/api/server.go`
- [Graph handlers](https://github.com/akira-core/kube-state-graph/blob/main/internal/api/handlers.go): `internal/api/handlers.go`
- [API key auth](https://github.com/akira-core/kube-state-graph/blob/main/internal/api/auth_middleware.go): `internal/api/auth_middleware.go`
- [Runtime config](https://github.com/akira-core/kube-state-graph/blob/main/internal/config/config.go): `internal/config/config.go`

### Graph engine

- [Request parsing](https://github.com/akira-core/kube-state-graph/blob/main/pkg/kubegraph/parse.go): `pkg/kubegraph/parse.go`
- [Graph engine](https://github.com/akira-core/kube-state-graph/blob/main/pkg/kubegraph/engine.go): `pkg/kubegraph/engine.go`
- [Graph model](https://github.com/akira-core/kube-state-graph/tree/main/pkg/graph): `pkg/graph`
- [Graph projection](https://github.com/akira-core/kube-state-graph/blob/main/pkg/graph/project.go): `pkg/graph/project.go`
- [Storage projection](https://github.com/akira-core/kube-state-graph/blob/main/pkg/graph/project_storage.go): `pkg/graph/project_storage.go`
- [Cytoscape output](https://github.com/akira-core/kube-state-graph/blob/main/pkg/cytoscape/cytoscape.go): `pkg/cytoscape/cytoscape.go`

### Metrics access

- [PromQL router](https://github.com/akira-core/kube-state-graph/blob/main/pkg/promql/router.go): `pkg/promql/router.go`
- [VictoriaMetrics client](https://github.com/akira-core/kube-state-graph/blob/main/pkg/promql/client.go): `pkg/promql/client.go`
- [Backend routing config](https://github.com/akira-core/kube-state-graph/blob/main/pkg/promql/backendsfile/backendsfile.go): `pkg/promql/backendsfile/backendsfile.go`

### Route resolution

- [Route resolver](https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/resolver.go): `pkg/route/resolver.go`
- [Config snapshot](https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/snapshot/snapshot.go): `pkg/route/snapshot/snapshot.go`
- [Route translation](https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/translate/translate.go): `pkg/route/translate/translate.go`
- [Route config store](https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/store/store.go): `pkg/route/store/store.go`
- [Route match check](https://github.com/akira-core/kube-state-graph/blob/main/pkg/route/matchcheck/matchcheck.go): `pkg/route/matchcheck/matchcheck.go`

### Other components

- **API caller**
- **VictoriaMetrics**

## Connections

- API caller → HTTP server: requests (evidence: `README.md`)
- HTTP server → Graph handlers: routes to (evidence: `internal/api/server.go`)
- HTTP server → API key auth: authenticates
- Graph handlers → Request parsing: parses with (evidence: `internal/api/handlers.go`)
- Graph handlers → Graph engine: builds via (evidence: `internal/api/handlers.go`)
- Graph handlers → Graph model: uses (evidence: `internal/api/handlers.go`)
- Graph handlers → Cytoscape output: serializes with (evidence: `internal/api/handlers.go`)
- Graph engine → PromQL router: queries through (evidence: `pkg/kubegraph/engine.go`)
- Graph engine → Graph model: builds (evidence: `pkg/kubegraph/engine.go`)
- Graph engine → Graph projection: projects graph
- Graph engine → Storage projection: projects storage (evidence: `pkg/kubegraph/engine.go`)
- Graph engine → Cytoscape output: serializes result (evidence: `pkg/kubegraph/engine.go`)
- PromQL router → VictoriaMetrics client: dispatches queries
- VictoriaMetrics client → VictoriaMetrics: queries metrics (evidence: `README.md`)
- Backend routing config → PromQL router: configures routes
- Route resolver → Route config store: loads config (evidence: `pkg/route/resolver.go`)
- Route resolver → Config snapshot: loads snapshot (evidence: `pkg/route/resolver.go`)
- Route resolver → Route translation: translates config (evidence: `pkg/route/resolver.go`)
- Route resolver → Route match check: runs checks (evidence: `pkg/route/resolver.go`)
- Config snapshot → Route config store: reads data (evidence: `pkg/route/snapshot/snapshot.go`)
- Config snapshot → Route translation: uses translator (evidence: `pkg/route/snapshot/snapshot.go`)
- Route translation → Route resolver: resolves gateways (evidence: `pkg/route/translate/translate.go`)
