Skip to content

refactor(http-protocol): decouple protocol types from domain primitives#1845

Merged
josecelano merged 2 commits into
torrust:developfrom
josecelano:1835-1669-14-decouple-http-protocol-from-tracker-primitives
May 27, 2026
Merged

refactor(http-protocol): decouple protocol types from domain primitives#1845
josecelano merged 2 commits into
torrust:developfrom
josecelano:1835-1669-14-decouple-http-protocol-from-tracker-primitives

Conversation

@josecelano
Copy link
Copy Markdown
Member

Summary

  • decouple torrust-tracker-http-tracker-protocol from torrust-tracker-primitives
  • keep protocol-local HTTP DTO/value types and perform explicit boundary mapping in higher layers
  • align HTTP handlers/services and benches with protocol-domain mapping
  • document the architectural decision in a new ADR and semantically link EPIC/issue/ADR artifacts

Changes

  • remove direct dependency from packages/http-protocol/Cargo.toml to torrust-tracker-primitives
  • introduce/retain protocol-local announce/scrape response and request-layer types in http-protocol
  • move/keep mapping responsibility in http-tracker-core and axum-http-server boundary layers
  • add ADR: docs/adrs/20260527175600_keep_protocol_and_domain_types_decoupled.md
  • update issue and EPIC metadata links for traceability

Validation

  • linter all
  • cargo test -p torrust-tracker-http-tracker-protocol
  • cargo test -p torrust-tracker-http-tracker-core
  • cargo test -p torrust-tracker-axum-http-server
  • cargo build --workspace
  • cargo tree -p torrust-tracker-http-tracker-protocol --depth 1 (no torrust-tracker-primitives)

Closes #1835

Copilot AI review requested due to automatic review settings May 27, 2026 18:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-primitives dependency from torrust-tracker-http-tracker-protocol and introduce protocol-owned DTO/value types (announce/scrape + byte counters).
  • Move protocol↔domain mapping into http-tracker-core (request mapping) and axum-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.

Comment thread packages/http-tracker-core/src/services/announce.rs Outdated
Comment thread packages/http-protocol/src/v1/requests/announce.rs Outdated
@josecelano josecelano self-assigned this May 27, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 90.43478% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.81%. Comparing base (f148319) to head (4387109).

Files with missing lines Patch % Lines
...ackages/http-protocol/src/v1/responses/announce.rs 77.77% 6 Missing ⚠️
...ackages/http-tracker-core/src/services/announce.rs 82.75% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@josecelano
Copy link
Copy Markdown
Member Author

ACK 4387109

@josecelano josecelano merged commit 633370f into torrust:develop May 27, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decouple http-protocol from torrust-tracker-primitives

2 participants