How kusionstack/karpor works
Core Components
• Frontend UI: Located in the “ui” directory, it is built using React/TypeScript. It handles user interactions, displays dashboards (search, insights, topology maps, AI diagnostics) and communicates with the backend via REST/HTTP.
• API Server / Backend: The “cmd/karpor” folder and many packages inside “pkg” (especially pkg/core, pkg/server, pkg/syncer) form the backend. This part handles business logic, processes API requests, deals with authentication, and returns data to the frontend.
• API Specification: The “api” folder (with openapi spec files) documents the REST endpoints used by the API server. Include this as a “Contract/API Spec” component.
• Syncer and Data Aggregation: Under “pkg/syncer” you find modules for resource caching and synchronization. These components are responsible for collecting data from multiple Kubernetes clusters and keeping that in sync.
• Kubernetes Integration: The “pkg/kubernetes” directory contains generated clientsets, Kubernetes APIs, and registration logic. This enables the system to interact with one or many Kubernetes clusters.
• Infrastructure Integrations: The “pkg/infra” folder contains integrations with external services such as:
• AI Providers (see pkg/infra/ai – with clients for OpenAI, Azure OpenAI, HuggingFace, Deepseek).
• Persistence and Search: Modules for Elasticsearch clients are in pkg/infra/persistence/elasticsearch and pkg/infra/search/storage.
• Topology & Resource Relationship Management: Modules under pkg/infra/topology handle the resource mapping.
• Additional Services and Tools: There is a “cmd/cert-generator” (for certificate generation) and configuration files in “config” (which help define RBAC policies and sync strategies).
Depicting Relationships and Data Flows
• Within the “Backend” area, divide components into:
– API Layer (using contracts from the “api” folder).
– Business Logic and Core Module (pkg/core, pkg/server) that includes route handling, search & insight logic.
– Syncer/Cache Module (pkg/syncer), illustrating continuous communication with Kubernetes clusters and pulling real-time data.
• Backend to multiple external systems:
– Persistence/Search Engine: Add “Elasticsearch” (from pkg/infra/persistence and pkg/infra/search) and show how data from syncers or search handlers is pushed to/read from the search storage.
Architectural Patterns and Design Principles
• The code organization suggests use of separation of concerns (with clear divisions for API, business logic, external integration, and UI).
• Use of code generation (“hack” and parts of “pkg/kubernetes/generated”) that integrates with the Kubernetes API conventions.
• The project uses a modular design so that each integration (search, AI, topology) is encapsulated in its own package.
Putting It Together
• UI (React application).
• API/Backend (Golang-based service, including syncer, business logic, and Kubernetes integrations).
• External Systems (Kubernetes clusters, AI providers, Elasticsearch).
• Configuration/Deployment (Helm Charts, Docker, CI/CD as indicated by configuration and workflows).