This document provides a comprehensive overview of the KCL repository to help AI assistants understand the codebase for future work.
KCL (KCL Constraint-based Record & Functional Language) is an open-source configuration and policy language designed for cloud-native scenarios. It's a CNCF Sandbox project that enhances the writing of complex configurations through advanced programming language technology.
- Generate low-level static configuration data (JSON, YAML) for cloud-native applications
- Reduce boilerplate in configuration through schema modeling
- Define and validate configuration data with rule constraints
- Manage large-scale configurations with GitOps and automation
- Mutate/validate Kubernetes resources through various tool plugins
- Platform engineering language for modern application delivery (used with KusionStack)
- Kubernetes configuration management and abstraction
- Terraform resource model abstraction
- Configuration validation and constraint checking
- Large-scale infrastructure as code
- Platform engineering and GitOps workflows
Ant Group, Youzan, and Huawei are notable production users managing large-scale Kubernetes deployments.
/crates/ Core KCL VM and compiler implementation (main codebase)
/compiler_base/ Base compiler libraries and utilities (WIP, rustc-derived)
/cli/ Command-line interface binary wrapper
/test/ Integration and grammar tests
/grammar/ Extensive grammar test cases
/integration/ Integration test suites
/docs/ Developer guides and documentation
/dev_guide/ Development guide (architecture, quick start, etc.)
/design/ Design documents
/scripts/ Build and release automation scripts
/.github/workflows/ CI/CD pipelines for multiple platforms
Makefile- Top-level build orchestrationLICENSE- Apache License 2.0README.md- Project documentation
- 362+ Rust source files
- ~32,673 lines of Rust code in core modules
- Requires Rust 1.91+ for building
- Rust 2024 edition
- KCL - The language itself (.k files for examples and tests)
- Python - Integration tests and test infrastructure
- Shell/Bash - Build scripts and automation
- C/C++ - Runtime interop and FFI interfaces
- Protobuf - API definitions and RPC communication
- WASM - WebAssembly compilation target support
- tokio - Async runtime (for LSP and server)
- salsa - Incremental computation (for LSP)
Source Code (.k files)
↓
[Lexer] → Tokens
↓
[Parser] → AST
↓
[Resolver/Sema] → Semantic Analysis & Type Checking
↓
[Evaluator/Runner] → Execution
↓
Output (YAML/JSON)
Frontend (Parsing & Analysis):
kcl-lexer- Lexical analysis and tokenizationkcl-parser- Parse KCL source into ASTkcl-ast- Abstract Syntax Tree definitions and walkerkcl-ast-pretty- AST formatting and pretty-printingkcl-span- Source code span/position trackingkcl-error- Error handling and diagnostics
Semantic Analysis:
kcl-sema- Semantic analysis, type checking, and validationkcl-loader- Module loading and dependency managementkcl-query- Code query and information retrieval
Compilation & Execution:
kcl-evaluator- Expression evaluation enginekcl-runner- Program execution environmentkcl-driver- Compilation driver and orchestration
Runtime:
kcl-runtime- Runtime support libraries with extensive standard library- Value representation and type system
- Standard library modules: json, yaml, base64, regex, crypto, datetime, math, net, etc.
- Template rendering (handlebars)
- File I/O and manifests
Tooling:
kcl-tools- Development tools- Format, Lint, Fix, Vet
- Testing infrastructure
- LSP (Language Server) - Full IDE support with autocomplete, goto-definition, diagnostics
kcl-api- Public API layer for multi-language SDKskcl-cmd- CLI command implementation
Utilities:
kcl-config- Configuration parsingkcl-version- Version managementkcl-utils- Common utilitieskcl-primitives- Primitive type definitionskcl-macros- Procedural macros
- Salsa-based incremental compilation for performance
- VFS (Virtual File System) for handling unsaved changes
- Thread pool for concurrent request handling
- Event-driven architecture (Tasks + LSP Messages)
- Compile unit discovery for projects without explicit config
- Located at:
/crates/tools/src/LSP
- Cargo - Primary Rust build system (workspace-based with 20+ crates)
- Make - Top-level orchestration
- Docker - Containerized build environment (recommended:
kcllang/kcl-builder)
make build # Standard build
make release # Release build
make check # Type checking
make build-lsp # Language server
make build-wasm # WASM target- Workspace with 20+ member crates
- Support for multiple targets: native, WASM (wasm32-wasip1), WASM-unknown
- Cross-platform: Linux (AMD64, ARM64), macOS (AMD64, ARM64), Windows (MinGW)
- Release profile optimized for size (opt-level = "z", LTO enabled)
- serde/serde_json - Serialization
- 3rdparty/serde_yaml - YAML support (note: migrated from serde_yaml)
- prost/protobuf - Protocol buffers
- tokio - Async runtime
- lsp-server/lsp-types - Language Server Protocol
- salsa - Incremental computation
- rustc_lexer - Rust's lexer for tokenization
- petgraph - Graph data structures
- regex/fancy-regex - Regular expressions
1. Unit Tests:
- Cargo-based unit tests across all crates
- Command:
make testorcargo test --workspace
2. Grammar Tests:
- Extensive grammar test suite in
/test/grammar - Python-based pytest framework
- Parallel execution:
pytest -v -n 5 - Tests both AST evaluator and fast evaluator
- Command:
make test-grammar
3. Integration Tests:
tests/grammar- Python integration tests
4. Runtime Tests:
- Python-based runtime library tests
- Command:
make test-runtime
Comprehensive GitHub Actions workflows (11 pipelines) for:
- Linux AMD64 and ARM64
- macOS AMD64 and ARM64
- Windows (MSVC and MinGW)
- Alpine Linux (musl)
- CentOS 7
- WASM/WASI
- Compiler base tests
-
Official Website: https://kcl-lang.io/
- User guides, language tour, API reference
- Installation instructions
- Tutorial and examples
-
Repository Documentation:
/README.md- Project overview and quick start/README-zh.md- Chinese documentation/docs/dev_guide/- Developer guide1.about_this_guide.md- Guide overview2.quick_start.md- Building and setup3.coding_conventions.md- Code style4.architecture.md- Compiler architecture5.source_code.md- Source code structure6.languager_server.md- LSP implementation
-
Governance:
/GOVERNANCE.md- Project governance (CNCF sandbox)/CODE_OF_CONDUCT.md- Community guidelines/ADOPTERS.md- Production users/MAINTAINERS- Maintainer list
- Spec-driven: Independent syntax and semantics specification
- Functional: Low side-effects, no system-level operations (no threads/IO)
- Constraint-based: Schema + Rule + Lambda for configuration validation
- API-first: Multi-language SDKs (Rust, Go, Python, .NET, Java, Node.js)
- Cloud-native: Native support for OpenAPI, K8s CRD, KRM spec
- Type Safety: Static type system with constraints and validation rules
# Recommended: Use Docker builder image
docker pull kcllang/kcl-builder
# Or install dependencies locally
# - Rust 1.91+
# - Python 3.x (for tests)
# - Protobuf compiler
# Build the project
make build
# Run tests
make test
make test-grammar- Full Language Server Protocol (LSP) support
- VSCode extension available
- Rust-analyzer recommended for Rust development
- Dev container configuration in
.devcontainer/
- Production-Ready: Used by major companies for large-scale Kubernetes management
- Multi-Platform: Exceptional cross-platform support including ARM and WASM
- Rich Ecosystem:
- Kubectl, Kustomize, Helm, KPT, Crossplane plugins
- Package registry at artifacthub.io
- Integration with GitOps workflows
- Developer Experience:
- Full LSP implementation with IDE support
- Comprehensive tooling (format, lint, test, vet)
- Extensive test coverage and fuzzing
- Performance Focus:
- WASM compilation target
- Size-optimized release builds
- Main branch:
main(use this for PRs) - License: Apache License 2.0
- Current version: 0.11.2
- Recent focus areas: YAML serialization fixes, LSP formatter improvements, documentation
- Always check existing code patterns - This is a mature codebase with established conventions
- Test coverage is critical - Add tests for any new functionality
- Performance matters - This is used in production for large-scale configurations
- Cross-platform support - Consider multiple platforms when making changes
- Documentation - Keep docs in sync with code changes
- The codebase uses workspaces - Changes may affect multiple crates
- Recent migration from serde_yaml to serde_yaml - Use the new library
| Task | Command |
|---|---|
| Build | make build |
| Test | make test |
| Format | cargo fmt |
| Lint | cargo clippy |
| Grammar tests | make test-grammar |
| Build LSP | make build-lsp |
| Build WASM | make build-wasm |
| Release build | make release |
- Official website: https://kcl-lang.io/
- GitHub: Current repository
- CNCF: Sandbox project with formal governance