refactor(http-protocol): decouple protocol types from domain primitives#1845
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the HTTP tracker protocol crate to remove its direct dependency on domain primitives, introducing protocol-local request/response DTOs and shifting mapping responsibilities to boundary layers (http-tracker-core and axum-http-server). This supports the broader EPIC goal of reducing cross-crate coupling and clarifying architectural ownership.
Changes:
- Remove
torrust-tracker-primitivesdependency fromtorrust-tracker-http-tracker-protocoland introduce protocol-owned DTO/value types (announce/scrape + byte counters). - Move protocol↔domain mapping into
http-tracker-core(request mapping) andaxum-http-server(response mapping). - Add ADR documenting the protocol/domain decoupling decision and update EPIC/issue artifacts for traceability.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/udp-protocol/src/common.rs | Clarifies rationale for keeping UDP-local byte counter type. |
| packages/http-tracker-core/src/services/announce.rs | Adds protocol→domain mapping for announce requests (moves boundary mapping into core). |
| packages/http-tracker-core/benches/helpers/util.rs | Updates bench fixtures to construct protocol-local request types. |
| packages/http-protocol/src/v1/responses/scrape.rs | Introduces protocol-local scrape DTOs and updates encoding/tests accordingly. |
| packages/http-protocol/src/v1/responses/announce.rs | Introduces protocol-local announce response DTOs and updates encoding/tests accordingly. |
| packages/http-protocol/src/v1/requests/announce.rs | Introduces protocol-local NumberOfBytes, removes domain conversions and peer builder helper. |
| packages/http-protocol/src/percent_encoding.rs | Removes primitives dependency by decoding directly into bittorrent_peer_id::PeerId with local error type. |
| packages/http-protocol/Cargo.toml | Drops torrust-tracker-primitives dependency; adds bittorrent-peer-id. |
| packages/axum-http-server/src/v1/handlers/scrape.rs | Adds domain→protocol mapping for scrape responses before encoding. |
| packages/axum-http-server/src/v1/handlers/announce.rs | Adds domain→protocol mapping for announce responses before encoding. |
| packages/axum-http-server/src/v1/extractors/announce_request.rs | Updates extractor tests to use protocol-local NumberOfBytes. |
| docs/issues/open/1835-1669-14-decouple-http-protocol-from-tracker-primitives.md | Updates task/verification evidence and links to new ADR and touched artifacts. |
| docs/issues/open/1669-overhaul-packages/EPIC.md | Marks SI-14 complete and updates dependency notes/links. |
| docs/adrs/index.md | Adds ADR entry to index. |
| docs/adrs/20260527175600_keep_protocol_and_domain_types_decoupled.md | Adds ADR documenting the decoupling rationale and consequences. |
| Cargo.lock | Reflects updated dependency graph for the protocol crate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1845 +/- ##
===========================================
- Coverage 77.83% 77.81% -0.03%
===========================================
Files 380 380
Lines 28585 28647 +62
Branches 28585 28647 +62
===========================================
+ Hits 22250 22292 +42
- Misses 6023 6044 +21
+ Partials 312 311 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
ACK 4387109 |
Summary
torrust-tracker-http-tracker-protocolfromtorrust-tracker-primitivesChanges
packages/http-protocol/Cargo.tomltotorrust-tracker-primitiveshttp-protocolhttp-tracker-coreandaxum-http-serverboundary layersdocs/adrs/20260527175600_keep_protocol_and_domain_types_decoupled.mdValidation
linter allcargo test -p torrust-tracker-http-tracker-protocolcargo test -p torrust-tracker-http-tracker-corecargo test -p torrust-tracker-axum-http-servercargo build --workspacecargo tree -p torrust-tracker-http-tracker-protocol --depth 1(notorrust-tracker-primitives)Closes #1835