How konveyor/kai works
High-level layers and key components
• Client/Integration Layer – Interfaces where users interact with Kai (for example, via VSCode extensions as referenced in the README, demo scripts in “example”, and notebooks that guide usage).
• Core Business Logic – The modules that perform code analysis, modernize code, and generate fixes.
• Communication & API Layer – Using JSON-RPC and the Go-based analyzer service.
• Data & Storage – Caching modules, configuration data, historical Konveyor analysis reports and migration incident reports.
• Web/Server Components – The “kai_solution_server” which provides RESTful routes for solution handling, incident store processing and integration with the hub.
• Auxiliary & Support Modules – Notebooks, tests, documentation, CI/CD definitions, and build configurations.
Every module, grouping them by their functionality
• Kai Core (Python):
• Analyzer Modules: “kai/analyzer.py”, “kai/analyzer_types.py” which perform static code analysis.
• Cache & Constants: “kai/cache.py” and “kai/constants.py” used for caching LLM responses and holding global settings.
• Data Storage: “kai/data” directory that holds llm_cache and related cached analysis results.
• JSON-RPC & Communication:
• “kai/jsonrpc” module, including “core.py”, “callbacks.py”, “logs.py”, “models.py”, “streams.py”, “util.py”. This layer deals with remote procedure call communication.
• LLM Interfacing:
• “kai/llm_interfacing” contains “model_provider.py” and the token output callbacks. Its purpose is to abstract interactions with external LLM providers.
• Logging:
• “kai/logging” which holds “kai_trace.py” and “logging.py” to trace events and debug operations.
• Reactive Code Planner:
• “kai/reactive_codeplanner” is one of the most complex modules. It includes:
▪ Agent modules: “agent/analyzer_fix”, “agent/ast_diff”, “agent/dependency_agent”, “agent/maven_compiler_fix”, and “agent/reflection_agent.py” – each responsible for different aspects of code modification.
▪ Task Manager and Task Runner: “kai/reactive_codeplanner/task_manager” and “kai/reactive_codeplanner/task_runner” (with subdirectories for analyzer LSP, compiler, and dependency task runners) which orchestrate jobs.
▪ Virtual File System (vfs): “kai/reactive_codeplanner/vfs” for snapshotting repository contexts.
▪ The main entry point “kai/reactive_codeplanner/main.py” that ties these pieces together.
• RPC Server:
• “kai/rpc_server” contains modules such as “chat.py”, “main.py”, “server.py”, and “util.py”. These provide direct communication endpoints for remote interactions.
• Go-Based Analyzer (kai_analyzer_rpc):
• Written in Go, this includes “kai_analyzer_rpc/main.go” and supporting packages like “pkg/codec”, “pkg/scope”, “pkg/service/analyzer.go”, and “pkg/tracing” for performance tracing.
• Solution Server:
• “kai_solution_server” provides server functionality with “main.py”, routing under “routes/”, build scripts under “build/”, and templates for solution presentation. It is responsible for integrating analysis reports and solution generation.
• Additional modules:
• “kai/kai_config.py” for configuration settings.
• “kai_analyzer_rpc/provider/java” for Java-specific analysis.
• “tests” directory contains unit and integration tests for various modules.
• “docs” contains design, configuration, design patterns, and sample scenarios.
• “notebooks” provide interactive demonstrations, evaluation examples, and even experiments—for both development and research purposes.
Relationships and interactions between these components
• Data Flow:
• The Client/Integration Layer sends user input (or file snapshots) into the Core Engine.
• The Analyzer (from the kai core) processes static code and triggers the Reactive Code Planner functions for generating transformation steps.
• For code modernization suggestions, the LLM Interfacing module sends requests to external LLM providers (using Retrieval Augmented Generation with historical context from Konveyor analysis).
• Communication between components is coordinated via the JSON-RPC modules and the serving endpoints provided by the “kai/rpc_server” and “kai_analyzer_rpc” (Go) modules.
• The “kai_solution_server” aggregates the generated solutions, applies templates (Jinja in “kai_solution_server/data/templates”), and serves these through RESTful API endpoints.
• Feedback Loops:
• Caching (kai/cache) and persistent data storage (kai/data) contribute to learning from past migrations and help refine recommendations.
• Logging and tracing (kai/logging and Go tracing) provide monitoring and debugging support.
Architectural Principles and Patterns
• Modular design: Each component (analysis, planning, LLM interfacing, RPC communication, UI integration) is a separate module.
• Layered architecture: Separate layers exist for data access, business logic, and presentation/service.
• Microservices: The use of independent services (such as the Go analyzer RPC service and the Python-based solution server) which communicate via well-defined interfaces.
• Extensibility: The presence of custom rules (under “docs/custom_ruleset-example” and “example/default_rules”) and dynamic templates (Jinja files in the solution server) illustrates a design that can be extended as new modernization rules emerge.