Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

CrateResponsibility
kargo-utilError types, filesystem helpers, process spawning, hashing, progress bars. No domain logic.
kargo-coreData 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-mavenThe Maven protocol: POM parsing, maven-metadata.xml, artifact download, checksums, auth, publishing.
kargo-resolverThe resolution algorithm. Uses kargo-maven for metadata.
kargo-compilerCompiler invocation, build cache, incremental state, unit graph, job queue, KSP and KAPT.
kargo-toolchainKotlin and JDK download, version management, SDK discovery.
kargo-pluginPlugin system: script engine, subcommand discovery, hook dispatch.
kargo-lintLint engine and formatter. Tree-sitter Kotlin parsing, rule execution.
kargo-opsHigh-level operations wiring the rest together. One module per CLI command.
kargo-cliBinary entry point. Clap parsing, dispatch to kargo-ops. No business logic.

Hard constraints

  • kargo-core depends on nothing but kargo-util. Never add kargo-core → kargo-maven, kargo-ops, or anything else.
  • kargo-util depends on no other kargo-* crate.
  • kargo-cli depends only on kargo-ops, kargo-core, and kargo-util.
  • kargo-core contains 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

AddingGoes in
A new manifest sectionkargo-core (type plus parsing), then whoever consumes it
A new CLI commandkargo-cli/src/cli.rs (flags), commands/ (dispatch), kargo-ops (logic)
A new target backendkargo-compiler: implement TargetCompiler, register in dispatch.rs
A resolution changekargo-resolver
A repository-protocol changekargo-maven
A lint rulekargo-lint/src/rules/
A shared helperkargo-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.md
  • crates/kargo-maven/CLAUDE.md
  • crates/kargo-resolver/CLAUDE.md
  • crates/kargo-compiler/CLAUDE.md

Read the one for the crate you are editing.

Next