refactor: [#298] Phase 3 Port Topology Domain Model - Foundation (P3.1-P3.3) #299
+879
−81
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the domain layer foundation for Phase 3 of the Docker Compose Topology refactoring (Epic #287). It creates type-safe port binding types and cross-service port conflict validation, following the same pattern established for networks in Phase 1-2.
Changes
P3.1: Create Port Domain Types ✅
Protocolenum fromdomain/tracker/protocol.rs(no duplication)PortBindingstruct with:host_port,container_port,protocol,host_ip,descriptiontcp(),udp(),localhost_tcp()docker_compose_binding()method for YAML rendering (e.g.,"6969:6969/udp")P3.2: Extend ServiceTopology with Ports ✅
ports: Vec<PortBinding>field toServiceTopologynew()constructor with ports parameterwith_networks()for backward compatibilityP3.3: Add Cross-Service Port Validation ✅
PortConflicterror type with full context (both services, both bindings)TopologyErrorenum withhelp()method (DDD error conventions)validate_port_uniqueness()onDockerComposeTopologyDDD Compliance
All code follows the project's DDD practices (docs/contributing/ddd-practices.md):
#[must_use]on gettershelp()TopologyError::help()What's NOT in this PR
P3.4 (Template Integration) will be a follow-up PR:
DockerComposeContextto use derived portsdocker-compose.yml.teraport sectionsThis split allows the domain foundation to be reviewed and merged independently.
Testing
Files Changed
src/domain/topology/port.rsPortBindingstructsrc/domain/topology/error.rsPortConflict,TopologyErrorsrc/domain/topology/aggregate.rsServiceTopologywith portssrc/domain/topology/mod.rsdocs/issues/287-*.mddocs/issues/298-*.mdRelated