Repository navigation
Closed
Labels
Description
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
- Create
src/domain/topology/traits.rswithPortDerivationtrait - Implement
PortDerivationforTrackerConfig,GrafanaConfig,PrometheusConfig - Create
src/domain/topology/fixed_ports.rsfor Caddy and MySQL - Add unit tests for each implementation
P4.2: Create Domain Topology Builder
- Create
src/domain/topology/builder.rswithDockerComposeTopologyBuilder - Move network computation logic from infrastructure to domain builder
- Wire up port derivation via trait calls
- Add integration tests
P4.3: Refactor Infrastructure to Pure DTOs
- Remove
compute_networks()from all service context types - Rename types to
*Context(e.g.,TrackerServiceContext) - Update
DockerComposeContextBuilderto receive domain topology - Update tests
P4.4: Cleanup
- Delete
src/infrastructure/.../context/port_derivation.rs - Remove any remaining business logic from infrastructure
- Update documentation
- Run full E2E test suite
Acceptance Criteria
- Pre-commit checks pass:
./scripts/pre-commit.sh -
PortDerivationtrait defined indomain/topology/traits.rs - All service configs implement
PortDerivation -
DockerComposeTopologyBuildercomputes networks in domain layer - Infrastructure context types are pure DTOs with no
compute_*()methods -
port_derivation.rsdeleted from infrastructure - All existing E2E tests pass
Related
- Parent Epic: [Epic] Docker Compose Topology Domain Model Refactoring #287 - Docker Compose Topology Domain Model Refactoring
- Predecessor: [Refactor] Phase 3: Port Topology Template Integration (P3.4) #300 - Phase 3 Port Topology Template Integration
- Spec:
docs/issues/phase-4-service-topology-ddd-alignment.md
Activity
refactor: [#300] Phase 3 Port Topology Template Integration (P3.4)
Merge #302: refactor: [#300] Phase 3 Port Topology Template Integrati…
refactor: [#301] add PortDerivation trait in domain topology
refactor: [#301] implement PortDerivation for PrometheusConfig
refactor: [#301] implement PortDerivation for GrafanaConfig
refactor: [#301] implement PortDerivation for TrackerConfig
refactor: [#301] add fixed port functions for Caddy and MySQL in domain
refactor: [#301] complete DDD migration - remove TrackerServiceConfig…
refactor: [#301] rename PrometheusServiceConfig and GrafanaServiceCon…
refactor(domain): [#301] add NetworkDerivation trait and EnabledServi…
docs: [#301] update Phase 4 progress - all main goals complete
docs: [#301] mark Phase 4 acceptance criteria complete
refactor(domain): [#301] replace fixed_ports.rs with domain types for…
refactor(infrastructure): [#301] rename service configs to *Context
refactor(infrastructure): [#301] remove TrackerPorts type alias
docs: [#301] update Phase 4 progress - Step 7.5 complete
refactor(infrastructure): [#301] remove legacy fields from TrackerSer…
refactor(infrastructure): [#301] remove unused fields from Grafana/Pr…
refactor(infrastructure): [#301] extract ServiceTopology shared type
fix(domain): [#301] re-enable aggregate tests with clippy allow attri…
chore: remove closed issue documentation files