Repository navigation
Description
Subissue of EPIC #1669 — Overhaul: Packages
Goal
Install and configure cargo deny to programmatically enforce the workspace's layered architecture rules, preventing accidental dependency edges between layers from being introduced.
Background
The workspace has a documented layered architecture (see packages/AGENTS.md and the EPIC #1669 layer guardrails). Dependencies may only flow downward — outer layers (servers) may depend on inner layers (core, protocol, domain), but inner layers must not depend on outer layers.
The EPIC defines these forbidden edges:
core -> servertracker-core -> coretracker-core -> protocoltracker-core -> serverprotocol -> coreprotocol -> tracker-coreprotocol -> server
Currently, these rules are documented but not enforced by CI. A developer could accidentally add a core -> server dependency edge (e.g., a core package depending on udp-server) and it would compile and pass CI without any check.
cargo deny is the standard Rust tool for linting dependency graphs. Its bans check supports per-crate wrappers — a mechanism to allow a crate as a dependency only for a specific set of direct dependents while denying it for everyone else. This is exactly the primitive needed for layer enforcement.
Why cargo deny instead of other approaches
| Approach | Limitation |
|---|---|
| Manual code review | Human error; not automated |
| Custom CI script | Reinventing cargo deny |
| Cargo features / cfg gates | Wrong abstraction for this concern |
Rust compiler (#![deny(..)]) |
Cannot enforce cross-crate dependency rules |
Known existing layer violation
One violation exists today: rest-api-core (a core-layer package) depends on udp-server (a server-layer package). This is tracked in #1924. Until that violation is fixed, the wrappers list for udp-server will include rest-api-core as a legitimate direct dependent.
Execution order: This issue should be implemented after the
rest-api-coredecoupling (#1924), or the final PR must include a second commit that removesrest-api-corefrom theudp-serverwrappers. If implemented first, deny will pass but the stale exception would remain until explicitly cleaned up.
Layer map and forbidden edges
Layer classification
| Layer | Packages |
|---|---|
Server (axum-*, *-server) |
torrust-tracker-axum-http-server, torrust-tracker-axum-rest-api-server, torrust-tracker-axum-health-check-api-server, torrust-tracker-axum-server, torrust-tracker-udp-server |
Core (*-core) |
torrust-tracker-core, torrust-tracker-http-core, torrust-tracker-udp-core, torrust-tracker-rest-api-core |
Protocol (*-protocol) |
torrust-tracker-http-protocol, torrust-tracker-udp-protocol |
| Domain / Shared | torrust-tracker-configuration, torrust-tracker-primitives, torrust-tracker-events, torrust-tracker-swarm-coordination-registry, torrust-tracker-client-lib |
| Tools / Benchmarks | torrust-tracker-test-helpers, torrust-tracker-torrent-repository-benchmarking, e2e-tools, persistence-benchmark |
| CLI tools | torrust-tracker-client (console binary) |
Forbidden dependency edges
| Edge | Description | Current violations |
|---|---|---|
core -> server |
Core must not depend on delivery-layer packages | rest-api-core -> udp-server |
tracker-core -> core |
Tracker core must not depend on its protocol-specific wrappers | None |
tracker-core -> protocol |
Tracker core must not depend on protocol parsing crates | None |
tracker-core -> server |
Tracker core must not depend on server crates | None |
protocol -> core |
Protocol crates must not depend on core logic | None |
protocol -> tracker-core |
Protocol crates must not depend on tracker core | None |
protocol -> server |
Protocol crates must not depend on server crates | None |
domain -> server |
Domain/shared packages must not depend on server crates | None |
Legitimate direct dependents (wrappers)
These are the packages that are currently allowed to depend on server-layer crates:
| Server crate | Legitimate direct dependents |
|---|---|
torrust-tracker-axum-http-server |
Root binary (torrust-tracker) |
torrust-tracker-axum-rest-api-server |
Root binary (torrust-tracker) |
torrust-tracker-axum-health-check-api-server |
Root binary (torrust-tracker) |
torrust-tracker-axum-server |
axum-http-server, axum-rest-api-server, axum-health-check-api-server, root (torrust-tracker) |
torrust-tracker-udp-server |
axum-rest-api-server, axum-health-check-api-server (dev), rest-api-core (pending fix #1924), root (torrust-tracker) |
Scope
In Scope
- Install
cargo denyin CI (GitHub Action) or as part of the existing lint pipeline. - Create
deny.tomlconfiguration file at the workspace root. - Configure the
[bans]section with explicitdenyentries for each server crate, usingwrappersto list the packages that are legitimately allowed to depend on them. - Add
cargo deny check bansto the CI testing workflow (GitHub Actions). - Add
cargo deny check bansto the pre-commit hook if it runs fast enough, otherwise to the pre-push hook. - Configure the
[licenses]and[advisories]checks if desired (secondary benefit).
Out of Scope
- Fixing existing layer violations (those are separate subissues in EPIC Overhaul: Packages #1669).
- Configuring
cargo denyfor non-workspace external dependencies (license checking, advisory scanning) — those are separate concerns. - Configuring
cargo denysources checks.
Implementation Plan
| ID | Status | Task | Notes / Expected Output |
|---|---|---|---|
| T1 | TODO | Install cargo deny (or confirm it's available) |
cargo install --locked cargo-deny or via system package manager |
| T2 | TODO | Create deny.toml at the workspace root with bans configuration |
Configuration matching the proposed deny rules |
| T3 | TODO | Run cargo deny check bans and verify it passes |
All dependency edges match the allowed wrappers |
| T4 | TODO | Add cargo deny check bans to CI testing workflow (GitHub Actions) |
CI catches violations before merge |
| T5 | TODO | Add cargo deny check bans to pre-commit (fast) or pre-push (slow) |
Gated by performance |
| T6 | TODO | Verify that adding a test core -> server dep triggers a deny error |
Proof the enforcement works |
| T7 | TODO | Document the deny.toml configuration in packages/AGENTS.md |
Future developers understand the rules |
Acceptance Criteria
-
deny.tomlexists at the workspace root with bans configuration. -
cargo deny check banspasses (exit code 0) on the current workspace state. - Adding a forbidden dependency edge (e.g.,
core -> server) causescargo deny check bansto fail. - CI (GitHub Actions testing workflow) runs
cargo deny check bansand rejects changes with new banned edges. - The pre-commit or pre-push hook runs
cargo deny check bans. -
packages/AGENTS.mdreferences thedeny.tomlenforcement in its Adding/Modifying a Package section.
Out of Scope (repeated from above for clarity)
- Fixing existing layer violations (separate subissues in EPIC Overhaul: Packages #1669).
- License checking, advisory scanning, and sources checks.
Activity
docs(issues): create GitHub issues #1924, #1925, #1926 for EPIC #1669 …
Merge #1927: chore(issues): archive closed issues and create EPIC #1669…
Merge torrust#1932: feat(ci): configure cargo deny for workspace laye…
chore: mark closed issues as completed and bump actions/checkout from…
Merge #1934: chore: mark closed issues as completed and bump actions/…
chore: move closed issue specs from open/ to closed/ folder
Merge #1935: chore: move closed issue specs from open/ to closed/ folder