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 |
Services |
Axum 0.8 on tokio; every canopy-api service (18 of the 19) boots through |
Data |
PostgreSQL 19 ( |
Events |
RabbitMQ 4.4 via lapin 4; topic exchange |
Rules |
zen-engine 2.1 evaluating the JDM files of the configuration layers (ADR-003) |
Identity |
canopy-identity, hosted in canopy-security ( |
Worker portal |
|
Applicant portal |
|
Documents |
Typst via |
Storage |
|
Config and secrets |
Layered YAML + |
Containers |
Alpine multi-stage images, musl + rustls ( |
Task runner |
|
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
-
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 fromfeat|fix|chore|refactor|docs|test. -
Implement; add the
CHANGELOG.adoc== Unreleasedline and update the one canonical Antora page for the changed surface. -
Commit through the hooks (next section); push —
git pushrunscargo xtask test --unitand git-lfs. -
Open the MR with
Closes #N(Relates to #Nfor 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) |
|---|---|
|
The subject must match |
|
Runs on every commit. It checks the SPDX header on every staged |
|
Two steps, in order: |
|
The ordered stage inventory is |
CI |
|
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— noup/downpairs (ADR-016). The service applies it at boot throughsqlx::migrate!(crates/canopy-api/src/bootstrap.rs); the devstack picks it up oncargo xtask dev refresh; deploy-time jobs usecanopy-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 runcargo xtask dev refresh(the fixture layers' files and the pins inconfig-sources.lockare whatxtask/src/devstack_guard.rswatches, so a fetched layer changes with its pin). canopy-rules loads rulesets from disk at boot and exposes onlyGET /v1/rule-sets,GET /v1/rule-sets/{name},POST /v1/evaluate,GET /v1/evaluationsandGET /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-docsdiffs the live specs againstdocs/modules/ROOT/openapi/*.json;cargo xtask api-docs --updaterewrites them (xtask/src/cmd/api_docs.rs). Doc-comment edits onToSchematypes 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 withcommand:. Build args areCARGO_FEATURES(default empty) andCARGO_PROFILE(defaultrelease; the devstack passesdevstack) —Dockerfile. The portal builds fromservices/canopy-portal/Dockerfile.cargo xtask validatebuilds the image only when run without--skip-docker. - Bump the toolchain
-
One MR changes
rust-toolchain.toml,Dockerfile.ci'sFROM(the CI image; itsCI_IMAGE_TAGin.gitlab-ci.ymlis the two files' content address, whichci-config-lintchecks) and the six exact-patchFROM rust:X.Y.Z-alpinebases (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 inrust-toolchain.toml. - Use a typed id or an actor identity
-
Import it from
canopy_types(crates/canopy-types). A crate with a normalsqlxdependency declarescanopy-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 givesApiErroritsFrom<sqlx::Error>,ApiError::databaseandApiError::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.tomlsetsCANOPY_ENV=developmentfor 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"
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 withasciidoctor --failure-level WARN -o /dev/null <page>(Asciidoctor lint). -
validate’s
docsstage fails a mandatory page (architecture,services,security,local-dev) that is missing, prose-free or still carries thecanopy:placeholdersentinel (#2990). -
The site builds with Antora: the
pagesjob in.gitlab-ci.ymlrunsantora --stacktrace antora-playbook.ymlinantora/antora:3.2.3after installing its pinned packages from the@gadhsregistry it configures — reproduce a local build the same way. Diagrams render on the job's ownyuzutech/kroki-mermaidservice, which the playbook reaches ashttp://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 askroki. A diagram the renderer refuses fails the job. -
Slide decks: each
docs/slides/*.adocis rendered bydocs/extensions/slides-extension.jswith the reveal.js converter and published undercanopy/slides/; deck figures come fromrepositoryCountsat build time, and the extension throws on a missing deck, index page or count. See Canopy at a Glance.
Coding conventions, architecture, troubleshooting
-
Conventions: Coding Conventions (canopy overlay) over the standard.
-
Architecture and the ADR index: Architecture; the per-service topology is the Service Catalog.
-
When something breaks: Troubleshooting.