# weibaohui/k8m architecture

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

- Interactive diagram: https://gitdiagram.com/weibaohui/k8m
- Repository: https://github.com/weibaohui/k8m

## Overview

K8M is an AI-assisted Kubernetes management console. Users sign in, select a connected cluster, and use the web console or APIs to inspect and manage Kubernetes resources; backend controllers call the Kubernetes client and return results. Major documented branches include AI diagnosis, Helm, inspections, event forwarding, MCP, and API keys. Relationships for unsampled features are documented rather than inferred from module names; source-level detail is limited to the excerpts and SOURCE INDEX.

Main entry points: [`main.go`](https://github.com/weibaohui/k8m/blob/main/main.go) (HTTP server), [`pkg/plugins/manager.go`](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/manager.go) (Plugin manager), [`pkg/plugins/modules/k8sgpt/service/analysis/analysis.go`](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/k8sgpt/service/analysis/analysis.go) (AI analysis), [`pkg/plugins/modules/eventhandler/admin/controller.go`](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/eventhandler/admin/controller.go) (Event forwarding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Console and API"]
  node_web["Web console<br/>[App.tsx]"]
  node_server["HTTP server<br/>[main.go]"]
  node_auth["Authentication<br/>[auth.go]"]
end

subgraph group_cluster["Cluster management"]
  node_deploy["Workload operations<br/>[deploy.go]"]
  node_dynamic["Dynamic resources<br/>[container.go]"]
  node_yaml["YAML editor<br/>[controller.go]"]
  node_storage["Storage classes<br/>[storage_class.go]"]
  node_clusters["Cluster registry<br/>[clusters.go]"]
end

subgraph group_extensions["AI and extensions"]
  node_ai["AI analysis<br/>[analysis.go]"]
  node_chat["AI assistant<br/>[chat.go]"]
  node_helm["Helm management<br/>[helm.go]"]
  node_inspection["Cluster inspection<br/>[lua_inspection.go]"]
  node_events["Event forwarding<br/>[controller.go]"]
  node_webhooks["Webhook delivery<br/>[webhook.go]"]
  node_mcp["MCP server<br/>[server.go]"]
  node_pluginmgr["Plugin manager<br/>[manager.go]"]
end

subgraph group_data["Identity and persistence"]
  node_identity["Users and permissions<br/>[permission.go]"]
  node_database[("Application database<br/>[conn.go]")]
  node_models["Domain models<br/>[migrate.go]"]
  node_apikey["API keys<br/>[controller.go]"]
  node_lease["HA leases<br/>[manager.go]"]
end

node_operator(("Operator"))
node_kube{{"Kubernetes clusters"}}
node_externalai{{"AI provider"}}
node_webhooktarget{{"Webhook targets"}}

node_operator -->|"uses"| node_web
node_web -.->|"sends requests"| node_server
node_server -.->|"routes through"| node_auth
node_server -->|"registers plugins"| node_pluginmgr
node_server -->|"initializes clusters"| node_clusters
node_auth -->|"checks roles"| node_identity
node_identity -.->|"persists users"| node_database
node_models -->|"migrates schema"| node_database
node_deploy -->|"manages workloads"| node_kube
node_dynamic -->|"manages resources"| node_kube
node_yaml -->|"applies manifests"| node_kube
node_storage -->|"reads and updates"| node_kube
node_clusters -->|"connects clusters"| node_kube
node_operator -->|"requests diagnosis"| node_ai
node_ai -->|"analyzes resources"| node_kube
node_chat -.->|"calls model"| node_externalai
node_operator -->|"manages charts"| node_helm
node_operator -->|"configures checks"| node_inspection
node_inspection -.->|"sends findings"| node_webhooks
node_operator -->|"configures forwarding"| node_events
node_events -.->|"delivers events"| node_webhooks
node_webhooks -.->|"posts notifications"| node_webhooktarget
node_operator -->|"calls tools"| node_mcp
node_mcp -->|"executes cluster tools"| node_kube
node_pluginmgr -.->|"manages plugin"| node_events
node_pluginmgr -.->|"manages plugin"| node_helm
node_pluginmgr -.->|"manages plugin"| node_ai
node_apikey -->|"creates user tokens"| node_identity
node_apikey -->|"stores keys"| node_database
node_lease -->|"coordinates leadership"| node_kube

click node_web "https://github.com/weibaohui/k8m/blob/main/ui/src/App.tsx"
click node_server "https://github.com/weibaohui/k8m/blob/main/main.go"
click node_auth "https://github.com/weibaohui/k8m/blob/main/pkg/middleware/auth.go"
click node_deploy "https://github.com/weibaohui/k8m/blob/main/pkg/controller/deploy/deploy.go"
click node_dynamic "https://github.com/weibaohui/k8m/blob/main/pkg/controller/dynamic/container.go"
click node_yaml "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/yaml_editor/controller/controller.go"
click node_storage "https://github.com/weibaohui/k8m/blob/main/pkg/controller/storageclass/storage_class.go"
click node_clusters "https://github.com/weibaohui/k8m/blob/main/pkg/service/clusters.go"
click node_ai "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/k8sgpt/service/analysis/analysis.go"
click node_chat "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/ai/controller/chat.go"
click node_helm "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/helm/service/helm.go"
click node_inspection "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/inspection/lua/lua_inspection.go"
click node_events "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/eventhandler/admin/controller.go"
click node_webhooks "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/webhook/service/webhook.go"
click node_mcp "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/k8m_mcp_server/server/server.go"
click node_pluginmgr "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/manager.go"
click node_identity "https://github.com/weibaohui/k8m/blob/main/pkg/comm/permission.go"
click node_database "https://github.com/weibaohui/k8m/blob/main/internal/dao/conn.go"
click node_models "https://github.com/weibaohui/k8m/blob/main/pkg/models/migrate.go"
click node_apikey "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/openapi/admin/controller.go"
click node_lease "https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/leader/lease/manager.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_web,node_server,node_auth toneBlue
class node_deploy,node_dynamic,node_yaml,node_storage,node_clusters toneAmber
class node_ai,node_chat,node_helm,node_inspection,node_events,node_webhooks,node_mcp,node_pluginmgr,node_webhooktarget toneMint
class node_identity,node_database,node_models,node_apikey,node_lease toneRose
class node_operator,node_kube,node_externalai toneIndigo
```

## Components

### Console and API

- [Web console](https://github.com/weibaohui/k8m/blob/main/ui/src/App.tsx): `ui/src/App.tsx`
- [HTTP server](https://github.com/weibaohui/k8m/blob/main/main.go): `main.go`
- [Authentication](https://github.com/weibaohui/k8m/blob/main/pkg/middleware/auth.go): `pkg/middleware/auth.go`

### Cluster management

- [Workload operations](https://github.com/weibaohui/k8m/blob/main/pkg/controller/deploy/deploy.go): `pkg/controller/deploy/deploy.go`
- [Dynamic resources](https://github.com/weibaohui/k8m/blob/main/pkg/controller/dynamic/container.go): `pkg/controller/dynamic/container.go`
- [YAML editor](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/yaml_editor/controller/controller.go): `pkg/plugins/modules/yaml_editor/controller/controller.go`
- [Storage classes](https://github.com/weibaohui/k8m/blob/main/pkg/controller/storageclass/storage_class.go): `pkg/controller/storageclass/storage_class.go`
- [Cluster registry](https://github.com/weibaohui/k8m/blob/main/pkg/service/clusters.go): `pkg/service/clusters.go`

### AI and extensions

- [AI analysis](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/k8sgpt/service/analysis/analysis.go): `pkg/plugins/modules/k8sgpt/service/analysis/analysis.go`
- [AI assistant](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/ai/controller/chat.go): `pkg/plugins/modules/ai/controller/chat.go`
- [Helm management](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/helm/service/helm.go): `pkg/plugins/modules/helm/service/helm.go`
- [Cluster inspection](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/inspection/lua/lua_inspection.go): `pkg/plugins/modules/inspection/lua/lua_inspection.go`
- [Event forwarding](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/eventhandler/admin/controller.go): `pkg/plugins/modules/eventhandler/admin/controller.go`
- [Webhook delivery](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/webhook/service/webhook.go): `pkg/plugins/modules/webhook/service/webhook.go`
- [MCP server](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/k8m_mcp_server/server/server.go): `pkg/plugins/modules/k8m_mcp_server/server/server.go`
- [Plugin manager](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/manager.go): `pkg/plugins/manager.go`

### Identity and persistence

- [Users and permissions](https://github.com/weibaohui/k8m/blob/main/pkg/comm/permission.go): `pkg/comm/permission.go`
- [Application database](https://github.com/weibaohui/k8m/blob/main/internal/dao/conn.go): `internal/dao/conn.go`
- [Domain models](https://github.com/weibaohui/k8m/blob/main/pkg/models/migrate.go): `pkg/models/migrate.go`
- [API keys](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/openapi/admin/controller.go): `pkg/plugins/modules/openapi/admin/controller.go`
- [HA leases](https://github.com/weibaohui/k8m/blob/main/pkg/plugins/modules/leader/lease/manager.go): `pkg/plugins/modules/leader/lease/manager.go`

### Other components

- **Operator**
- **Kubernetes clusters**
- **AI provider**
- **Webhook targets**

## Connections

- Operator → Web console: uses (evidence: `README.md`)
- Web console → HTTP server: sends requests
- HTTP server → Authentication: routes through
- HTTP server → Plugin manager: registers plugins (evidence: `main.go`)
- HTTP server → Cluster registry: initializes clusters (evidence: `main.go`)
- Authentication → Users and permissions: checks roles (evidence: `pkg/middleware/auth.go`)
- Users and permissions → Application database: persists users
- Domain models → Application database: migrates schema (evidence: `pkg/models/migrate.go`)
- Workload operations → Kubernetes clusters: manages workloads (evidence: `README.md`)
- Dynamic resources → Kubernetes clusters: manages resources (evidence: `README.md`)
- YAML editor → Kubernetes clusters: applies manifests (evidence: `pkg/plugins/modules/yaml_editor/controller/controller.go`)
- Storage classes → Kubernetes clusters: reads and updates (evidence: `pkg/controller/storageclass/storage_class.go`)
- Cluster registry → Kubernetes clusters: connects clusters (evidence: `README.md`)
- Operator → AI analysis: requests diagnosis (evidence: `README.md`)
- AI analysis → Kubernetes clusters: analyzes resources
- AI assistant → AI provider: calls model (evidence: `README.md`)
- Operator → Helm management: manages charts (evidence: `README.md`)
- Operator → Cluster inspection: configures checks (evidence: `README.md`)
- Cluster inspection → Webhook delivery: sends findings (evidence: `README.md`)
- Operator → Event forwarding: configures forwarding (evidence: `pkg/plugins/modules/eventhandler/admin/controller.go`)
- Event forwarding → Webhook delivery: delivers events (evidence: `README.md`)
- Webhook delivery → Webhook targets: posts notifications (evidence: `README.md`)
- Operator → MCP server: calls tools (evidence: `README.md`)
- MCP server → Kubernetes clusters: executes cluster tools (evidence: `README.md`)
- Plugin manager → Event forwarding: manages plugin
- Plugin manager → Helm management: manages plugin
- Plugin manager → AI analysis: manages plugin
- API keys → Users and permissions: creates user tokens (evidence: `pkg/plugins/modules/openapi/admin/controller.go`)
- API keys → Application database: stores keys (evidence: `pkg/plugins/modules/openapi/admin/controller.go`)
- HA leases → Kubernetes clusters: coordinates leadership (evidence: `pkg/plugins/modules/leader/lease/manager.go`)
