Crate Architecture
Kargo is a Rust workspace of ten crates. The layering is strict, and the constraints below are not style preferences — breaking them makes the build graph cyclic or drags I/O into pure data types.
graph LR
CLI["kargo-cli"] --> OPS["kargo-ops"]
OPS --> CORE["kargo-core"]
OPS --> RESOLVER["kargo-resolver"]
OPS --> COMPILER["kargo-compiler"]
OPS --> LINT["kargo-lint"]
OPS --> PLUGIN["kargo-plugin"]
OPS --> TOOLCHAIN["kargo-toolchain"]
RESOLVER --> MAVEN["kargo-maven"]
RESOLVER --> CORE
COMPILER --> TOOLCHAIN
COMPILER --> CORE
MAVEN --> CORE
LINT --> CORE
PLUGIN --> CORE
CORE --> UTIL["kargo-util"]
Who owns what
| Crate | Responsibility |
|---|---|
kargo-util | Error types, filesystem helpers, process spawning, hashing, progress bars. No domain logic. |
kargo-core | Data types and their parsing and serialization: Manifest, Package, Workspace, Target, SourceSet, Dependency, Flavor, Variant, Profile, Config, Lockfile, VersionCatalog, Properties. No I/O beyond reading config files. |
kargo-maven | The Maven protocol: POM parsing, maven-metadata.xml, artifact download, checksums, auth, publishing. |
kargo-resolver | The resolution algorithm. Uses kargo-maven for metadata. |
kargo-compiler | Compiler invocation, build cache, incremental state, unit graph, job queue, KSP and KAPT. |
kargo-toolchain | Kotlin and JDK download, version management, SDK discovery. |
kargo-plugin | Plugin system: script engine, subcommand discovery, hook dispatch. |
kargo-lint | Lint engine and formatter. Tree-sitter Kotlin parsing, rule execution. |
kargo-ops | High-level operations wiring the rest together. One module per CLI command. |
kargo-cli | Binary entry point. Clap parsing, dispatch to kargo-ops. No business logic. |
Hard constraints
kargo-coredepends on nothing butkargo-util. Never addkargo-core→kargo-maven,kargo-ops, or anything else.kargo-utildepends on no otherkargo-*crate.kargo-clidepends only onkargo-ops,kargo-core, andkargo-util.kargo-corecontains no async code and no network I/O.- A new crate needs a discussion about the boundary first.
The reason kargo-core is kept pure: every other crate depends on it, so anything
it pulls in becomes a dependency of the whole workspace, and anything it does at
runtime becomes impossible to test without a network or a filesystem.
Where code goes
| Adding | Goes in |
|---|---|
| A new manifest section | kargo-core (type plus parsing), then whoever consumes it |
| A new CLI command | kargo-cli/src/cli.rs (flags), commands/ (dispatch), kargo-ops (logic) |
| A new target backend | kargo-compiler: implement TargetCompiler, register in dispatch.rs |
| A resolution change | kargo-resolver |
| A repository-protocol change | kargo-maven |
| A lint rule | kargo-lint/src/rules/ |
| A shared helper | kargo-util — but only if it has no domain knowledge |
Adding a target backend is deliberately cheap: implement the TargetCompiler
trait and register it in dispatch::resolve. The build orchestration layer
needs no changes.
Command flow
kargo build --release
│
├─ kargo-cli parse flags into Command::Build
├─ commands/ dispatch to the handler
├─ kargo-ops ops_build: orchestrate the phases
│ ├─ kargo-core load and validate the manifest
│ ├─ kargo-toolchain ensure the Kotlin version and a JDK
│ ├─ kargo-resolver resolve, or read the lockfile
│ │ └─ kargo-maven fetch POMs and artifacts
│ └─ kargo-compiler plan units, fingerprint, compile, cache
└─ print the result
kargo-ops is the only layer that knows about more than one subsystem. That is
intentional: it keeps the orchestration in one readable place and the subsystems
independently testable.
Crate-specific notes
Several crates carry their own CLAUDE.md with local conventions:
crates/kargo-core/CLAUDE.mdcrates/kargo-maven/CLAUDE.mdcrates/kargo-resolver/CLAUDE.mdcrates/kargo-compiler/CLAUDE.md
Read the one for the crate you are editing.
Next
- Code Conventions
- Testing
- Build Lifecycle — the same flow from a user's angle