Overview
Move port derivation and network computation logic from the infrastructure layer to the domain layer, ensuring proper DDD layer separation. This phase was identified during Phase 3 implementation when we discovered business rules incorrectly placed in infrastructure.
Problem Statement
The current architecture has domain logic (port derivation, network computation) incorrectly placed in the infrastructure layer:
infrastructure/context/port_derivation.rs ← Business rules about port exposure
infrastructure/context/tracker.rs ← compute_networks() method
infrastructure/context/grafana.rs ← compute_networks() method
infrastructure/context/prometheus.rs ← compute_networks() method
These are business rules that should be in the domain layer:
- "UDP ports are always exposed (no TLS for UDP)" - PORT-02
- "HTTP ports hidden when TLS enabled" - PORT-03, PORT-04
- "Tracker joins metrics_network when Prometheus is enabled"
Implementation Plan
P4.1: Add Trait and Implement in Domain
P4.2: Create Domain Topology Builder
P4.3: Refactor Infrastructure to Pure DTOs
P4.4: Cleanup
Acceptance Criteria
Related
Overview
Move port derivation and network computation logic from the infrastructure layer to the domain layer, ensuring proper DDD layer separation. This phase was identified during Phase 3 implementation when we discovered business rules incorrectly placed in infrastructure.
Problem Statement
The current architecture has domain logic (port derivation, network computation) incorrectly placed in the infrastructure layer:
These are business rules that should be in the domain layer:
Implementation Plan
P4.1: Add Trait and Implement in Domain
src/domain/topology/traits.rswithPortDerivationtraitPortDerivationforTrackerConfig,GrafanaConfig,PrometheusConfigsrc/domain/topology/fixed_ports.rsfor Caddy and MySQLP4.2: Create Domain Topology Builder
src/domain/topology/builder.rswithDockerComposeTopologyBuilderP4.3: Refactor Infrastructure to Pure DTOs
compute_networks()from all service context types*Context(e.g.,TrackerServiceContext)DockerComposeContextBuilderto receive domain topologyP4.4: Cleanup
src/infrastructure/.../context/port_derivation.rsAcceptance Criteria
./scripts/pre-commit.shPortDerivationtrait defined indomain/topology/traits.rsPortDerivationDockerComposeTopologyBuildercomputes networks in domain layercompute_*()methodsport_derivation.rsdeleted from infrastructureRelated
docs/issues/phase-4-service-topology-ddd-alignment.md