Developer Guide

For a contributor about to change code: what is where, which gate runs when, and where each task’s canonical page lives. Setting up a machine is Local Development; tests and the push battery are Testing.

Tech stack

Layer What the tree uses (source)

Language

Rust, edition 2024; exact toolchain 1.100.1 with rustfmt, clippy and wasm32-unknown-unknown (rust-toolchain.toml); rust-version 1.100 (Cargo.toml), the pinned toolchain's release line

Services

Axum 0.8 on tokio; every canopy-api service (18 of the 19) boots through canopy_api::bootstrap and exposes /livez + /readyz, with /v1 protected (crates/canopy-api/src/lib.rs); the applicant portal uses none of that framework and answers /healthz + /readyz (services/canopy-portal/src/main.rs)

Data

PostgreSQL 19 (postgres:19-alpine in the devstack) via sqlx 0.9; one database per service (ADR-001); forward-only migrations (ADR-016)

Events

RabbitMQ 4.4 via lapin 4; topic exchange canopy.events; the outbox row is written in the handler’s transaction (publish_tx) and drained (crates/canopy-mq, ADR-018)

Rules

zen-engine 2.1 evaluating the JDM files of the configuration layers (ADR-003)

Identity

canopy-identity, hosted in canopy-security (services/canopy-security/src/identity/), is the only token issuer (ADR-049). Every service’s /v1 admits its ES256 delegation and system tokens through an IdentityReceiver, and each service sends through its IdentitySender (crates/canopy-auth). Workers sign in at canopy-web, which federates to one upstream OIDC provider: Kanidm 1.12.2 on the devstack (ADR-050), its cast devstack/kanidm/migrations/00-canopy.hjson

Worker portal

services/canopy-web — Askama 0.16 templates + htmx

Applicant portal

services/canopy-portal — Dioxus 0.7 fullstack, Postgres-free with sessions in redis-sessions (ADR-026)

Documents

Typst via crates/canopy-typst (notices)

Storage

crates/canopy-store — local filesystem or S3-compatible; the clamav sidecar scans uploads (ADR-042)

Config and secrets

Layered YAML + CANOPY_<SVC>__* env (ADR-012); SOPS + age at rest (ADR-017)

Containers

Alpine multi-stage images, musl + rustls (openssl is banned in deny.toml); Docker Compose profiles per program mix (ADR-005)

Task runner

cargo xtask (xtask/; the alias is in .cargo/config.toml) — cargo xtask --help is the authoritative list. Every command but init runs from the workspace root, whatever directory it is invoked from; a path argument is resolved against the invoking directory first (#2628)

Repository map

canopy/
├── AGENTS.md         the agent's project map: overrides and review rules (gadhs/pi)
├── .githooks/        pre-commit, commit-msg, pre-push (activate with core.hooksPath)
├── .gitlab-ci.yml    CI: security and supply-chain scans, static audits, unit lane, image build + promote, pages
├── compliance/       allow-lists and catalogues the CI audits consume
├── config/           config/canopy-<svc>/default.yaml, one per service
├── crates/           shared crates and the canopy-contracts-* crates
├── design/           design handoffs and renders (LFS-tracked images)
├── devstack/         postgres, rabbitmq, kanidm, ingress, garage, redis, redis-sessions, clamav, prometheus, grafana, seed, fixtures
├── docs/             the Antora site (modules/ROOT = canopy's pages, modules/standards = the standards)
├── fixtures/config/  the fixture configuration layers (real layers are fetched to target/config/)
├── secrets/          dev.yaml, SOPS-encrypted
├── services/         canopy-<svc>, one binary crate each
├── tests/e2e/        the Playwright suite (runs in the canopy-e2e container)
├── tools/            canopy-seed, canopy-cli (crates); canopy-devtools (a container image, not a crate)
├── xtask/            the task runner
├── docker-compose.yml, docker-compose.prebuilt.yml, Dockerfile, Dockerfile.integration
└── Cargo.toml        workspace members: crates/*, services/*, tools/*, xtask

Per crate: Shared Crates. Per service — ports, tables, routes, events: Service Catalog with its api/ and data-models/ pages. Per task: cargo xtask catalog.

The workflow

  1. Find or file the GitLab issue; branch {type}/For a contributor changing code — the tech stack, the repository map, how the commit and push gates work, and the common tasks with their canonical pages. with the type from feat|fix|chore|refactor|docs|test.

  2. Implement; add the CHANGELOG.adoc == Unreleased line and update the one canonical Antora page for the changed surface.

  3. Commit through the hooks (next section); push — git push runs cargo xtask test --unit and git-lfs.

  4. Open the MR with Closes #N (Relates to #N for a partial MR); it lands through the merge train, whose pipeline runs the whole battery and owns correctness. Regular merge commit, never squash.

Labels, the merge procedure and the working agreements: Contributor Workflow. The universal rules: Git Workflow, GitLab Workflow, Delivery Protocol.

Commit signing

Required: GitLab's reject_unsigned_commits push rule refuses any unsigned commit (#3249), and cargo xtask doctor (and validate's signing stage) checks commit.gpgsign and user.signingkey (check_signing in xtask/src/cmd/doctor.rs).

git config user.signingkey <KEY_ID>   # a GPG key id, or ~/.ssh/id_ed25519.pub after `git config gpg.format ssh`
git config commit.gpgsign true

Upload the public half to GitLab (SSH Keys with usage Signing, or GPG Keys).

How the gates work

Gate What it does (source)

commit-msg

The subject must match ^(feat|fix|chore|refactor|docs|test)(\(scope\))?: … and stay under 72 characters; Merge, Revert, fixup! and squash! are carved out; a missing Co-Authored-By: is a reminder, not a failure (.githooks/commit-msg)

pre-commit

Runs on every commit. It checks the SPDX header on every staged .rs blob, blocks an added FIXME/HACK/XXX/TODO line without a issue reference, and reminds you when .rs files are staged without CHANGELOG.adoc (.githooks/pre-commit). The judgment review of an agent’s commit is gadhs/pi’s, before git runs: J1–J8 plus the # Code Review Rules in AGENTS.md (#2989). Those rules reach the reviewer only in a project pi trusts; canopy counts as trusted by default while it has no trust-requiring .pi/ resource (.pi/settings.json, .pi/extensions/, …), and /trust makes it explicit

pre-push

Two steps, in order: cargo xtask test --unit (fmt, clippy, the unit lane) → git lfs pre-push (.githooks/pre-push). Nothing else runs locally; GitLab's push rule refuses an unsigned commit, and the merge train's pipeline runs the rest

cargo xtask validate

The ordered stage inventory is STAGES in xtask/src/validate_report.rs: bootstrap, the preconditions (preflight, visibility, signing, docs, spdx), the static audits, fmt, machete, clippy --all-targets --features <BATTERY_FEATURES> --profile test — -D warnings (the battery's one set, BATTERY_FEATURES in xtask/src/lanes.rs, #3343), quality-budgets, the lint sub-gates, devstack readiness, api-docs, the two nextest arms, doctests, docker-build. deny (cargo deny check) and machete block, and both tools are preflight requirements (#2239); docker-build is skipped under --skip-docker. The outcome is one file, test-results/validate-report.json

CI

.gitlab-ci.yml: a merge request's own pipeline runs lint (cargo fmt --check and every precompilation gate), docs and antora. The merge train's car runs the whole battery on one dhs-aws-autoscaler-docker-4xlarge VM: one compile, dev start, the unit, integration and e2e lanes, clippy, rustdoc, the feature builds, api-docs and the identity matrix. It owns correctness (CI is the gate). After a merge, main's own pipeline builds the operator CLI from that commit and keeps it for a week as a job artifact (canopy-cli). Tags and schedules add the release job, which builds, smoke-tests and pushes the two images; schedules also run coverage, policy drift and the fixture-smoke lane. GitLab's SAST, secret-detection and dependency-scanning templates run beside them.

Infrastructure tests never skip under a cargo xtask lane: every lane arms CANOPY_TEST_INFRA=required (xtask/src/bootstrap.rs), and infrastructure_available() panics when the stack is unreachable (crates/canopy-test-lib/src/infrastructure.rs). Lanes, the e2e battery and the CI job table: Testing.

Configuration and secrets

Each service loads config/canopy-<svc>/default.yaml, the optional overlay CANOPY_ENV names (dev.yaml for development, prod.yaml for production), the unprefixed CANOPY_CONFIG_SOURCE, CANOPY_POLICY_ROOT and CANOPY_CONFIG_ALLOW_UNVERIFIED, then CANOPY_<SVC>__* env, and rejects an unknown key by name (crates/canopy-common/src/settings.rs). The policy (packs, federal tables, notice templates) is not a setting: CANOPY_CONFIG_SOURCE names the configuration layers it is read through (crates/canopy-config, ADR-051). Secrets are SOPS + age in secrets/dev.yaml, handled by cargo xtask secrets … inside the canopy-devtools container. Every variable, the layering and the secrets workflow: Configuration Reference.

Common tasks

Add a migration

One forward-only file services/canopy-<svc>/migrations/<YYYYMMDDHHMMSS>_<name>.sql — no up/down pairs (ADR-016). The service applies it at boot through sqlx::migrate! (crates/canopy-api/src/bootstrap.rs); the devstack picks it up on cargo xtask dev refresh; deploy-time jobs use canopy-manage migrate apply --service canopy-<svc>. Rules and the lint gates: Migrations.

Edit a ruleset

Edit the JDM file in the layer’s repository (a fixture pack: fixtures/config/<pack>/) and run cargo xtask dev refresh (the fixture layers' files and the pins in config-sources.lock are what xtask/src/devstack_guard.rs watches, so a fetched layer changes with its pin). canopy-rules loads rulesets from disk at boot and exposes only GET /v1/rule-sets, GET /v1/rule-sets/{name}, POST /v1/evaluate, GET /v1/evaluations and GET /v1/corpus (services/canopy-rules/src/api/mod.rs) — there is no upload or hot-reload route. Authoring: Rulesets.

Regenerate the OpenAPI snapshots

cargo xtask api-docs diffs the live specs against docs/modules/ROOT/openapi/*.json; cargo xtask api-docs --update rewrites them (xtask/src/cmd/api_docs.rs). Doc-comment edits on ToSchema types change the contract — Troubleshooting › Contributor gotchas.

Build the images

docker build -t canopy:dev . builds every service binary into one image; compose selects each service’s binary with command:. Build args are CARGO_FEATURES (default empty) and CARGO_PROFILE (default release; the devstack passes devstack) — Dockerfile. The portal builds from services/canopy-portal/Dockerfile. cargo xtask validate builds the image only when run without --skip-docker.

Bump the toolchain

One MR changes rust-toolchain.toml, Dockerfile.ci's FROM (the CI image; its CI_IMAGE_TAG in .gitlab-ci.yml is the two files' content address, which ci-config-lint checks) and the six exact-patch FROM rust:X.Y.Z-alpine bases (Dockerfile, services/canopy-portal/Dockerfile, Dockerfile.integration, xtask/Dockerfile.validate-runner, tools/canopy-token-broker/Dockerfile, devstack/kanidm/Dockerfile), fixing any new lint surface in the same MR — the comment in rust-toolchain.toml.

Use a typed id or an actor identity

Import it from canopy_types (crates/canopy-types). A crate with a normal sqlx dependency declares canopy-types = { workspace = true, features = ["sqlx"] }, which gives the types their Postgres mapping, and declares canopy-common the same way (canopy-common = { workspace = true, features = ["sqlx"] }), which gives ApiError its From<sqlx::Error>, ApiError::database and ApiError::internal_database; a crate without one declares both with no feature, so it links no database driver. canopy-cli is such a crate: its boundary test refuses sqlx, and its binary is built apart from the services so their features are not unified into it (ADR-007 Amendment 5). The rule and its test: Shared Crates › canopy-types.

Run one service on the host

cargo run -p canopy-<svc> against a running devstack; .cargo/config.toml sets CANOPY_ENV=development for host runs so the fail-closed startup guards stay permissive.

Build caching with sccache (optional)

cargo install sccache --locked, then in ~/.cargo/config.toml:

[build]
rustc-wrapper = "sccache"
WARNING
Do not share one CARGO_TARGET_DIR across repositories. This workspace’s task runner is a package named xtask (xtask/Cargo.toml); another checkout with the same package name writes the same target/debug/xtask, and cargo xtask <cmd> then silently runs the other repository’s binary (symptom: error: unrecognized subcommand). sccache shares the compile cache without sharing the target directory.

Working with documentation

  • Pages are AsciiDoc under docs/modules/ROOT/pages/; render-check one with asciidoctor --failure-level WARN -o /dev/null <page> (Asciidoctor lint).

  • validate’s docs stage fails a mandatory page (architecture, services, security, local-dev) that is missing, prose-free or still carries the canopy:placeholder sentinel (#2990).

  • The site builds with Antora: the pages job in .gitlab-ci.yml runs antora --stacktrace antora-playbook.yml in antora/antora:3.2.3 after installing its pinned packages from the @gadhs registry it configures — reproduce a local build the same way. Diagrams render on the job's own yuzutech/kroki-mermaid service, which the playbook reaches as http://kroki:8002, and are saved into the site (#2630): for a local build, run that image on a network where the Antora container can reach it as kroki. A diagram the renderer refuses fails the job.

  • Slide decks: each docs/slides/*.adoc is rendered by docs/extensions/slides-extension.js with the reveal.js converter and published under canopy/slides/; deck figures come from repositoryCounts at build time, and the extension throws on a missing deck, index page or count. See Canopy at a Glance.

Coding conventions, architecture, troubleshooting

Edit this page · default