Skip to content

Commit 69c25c3

Browse files
committed
docs: [#281] add issue specification and link issue to refactor plan
1 parent 8c0ead1 commit 69c25c3

3 files changed

Lines changed: 67 additions & 4 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Strengthen Domain Invariant Enforcement (DDD Refactor)
2+
3+
**Issue**: [#281](https://github.com/torrust/torrust-tracker-deployer/issues/281)
4+
**Type**: Refactor
5+
**Status**: In Progress
6+
7+
## Overview
8+
9+
Apply the DDD validated constructor pattern to all domain configuration types, ensuring domain invariants are enforced at construction time rather than validated post-hoc.
10+
11+
## Detailed Plan
12+
13+
See: [`docs/refactors/plans/strengthen-domain-invariant-enforcement.md`](../refactors/plans/strengthen-domain-invariant-enforcement.md)
14+
15+
## Related ADRs
16+
17+
- [Validated Deserialization for Domain Types](../decisions/validated-deserialization-for-domain-types.md)
18+
- [TryFrom for DTO to Domain Conversion](../decisions/tryfrom-for-dto-to-domain-conversion.md)
19+
20+
## Reference Implementation
21+
22+
`HttpApiConfig` has been refactored as the reference implementation (Phase 0, Proposal #0):
23+
24+
- Location: `src/domain/tracker/config/http_api.rs`
25+
- DTO: `src/application/command_handlers/create/config/tracker/http_api_section.rs`
26+
27+
## Implementation Checklist
28+
29+
### Phase 0: HTTP API Config ✅
30+
31+
- [x] `HttpApiConfig` validated constructor with `HttpApiConfigError`
32+
- [x] Private fields with getter methods
33+
- [x] Custom `Deserialize` using `HttpApiConfigRaw`
34+
- [x] `TryFrom<HttpApiSection> for HttpApiConfig`
35+
- [x] Documentation and ADRs
36+
37+
### Phase 1: Tracker Configuration Types
38+
39+
- [ ] `UdpTrackerConfig` - validated constructor, private fields, getters
40+
- [ ] `HttpTrackerConfig` - validated constructor, private fields, getters
41+
- [ ] `HealthCheckApiConfig` - validated constructor, private fields, getters
42+
- [ ] `TryFrom` implementations for each DTO section
43+
44+
### Phase 2: Cross-Cutting Invariants
45+
46+
- [ ] `TrackerCoreConfig` - database configuration validation
47+
- [ ] `TrackerConfig` - validates at construction (socket conflicts)
48+
- [ ] `UserInputs` - validated constructor (Grafana requires Prometheus)
49+
50+
## Acceptance Criteria
51+
52+
- [ ] All domain configuration types use validated constructors
53+
- [ ] All fields are private with getter methods
54+
- [ ] All types implement custom `Deserialize` with validation
55+
- [ ] All DTO→Domain conversions use `TryFrom` trait
56+
- [ ] Validation logic moved from application to domain layer
57+
- [ ] Pre-commit checks pass: `./scripts/pre-commit.sh`
58+
59+
## Contributing Guide
60+
61+
See [`docs/contributing/ddd-practices.md`](../contributing/ddd-practices.md) for implementation patterns.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Active Refactoring Plans
22

3-
| Document | Status | Issue | Target | Created |
4-
| ----------------------------------------------------------------------------------------------------- | ----------- | ----- | -------------------------------------- | ---------- |
5-
| [Simplify Controller Command Handler Creation](plans/simplify-controller-command-handler-creation.md) | 📋 Planning | TBD | Remove unnecessary progress steps | 2025-12-17 |
6-
| [Strengthen Domain Invariant Enforcement](plans/strengthen-domain-invariant-enforcement.md) | 📋 Planning | TBD | Enforce DDD invariants in domain layer | 2026-01-21 |
3+
| Document | Status | Issue | Target | Created |
4+
| ----------------------------------------------------------------------------------------------------- | -------------- | ---------------------------------------------------------------------- | -------------------------------------- | ---------- |
5+
| [Simplify Controller Command Handler Creation](plans/simplify-controller-command-handler-creation.md) | 📋 Planning | TBD | Remove unnecessary progress steps | 2025-12-17 |
6+
| [Strengthen Domain Invariant Enforcement](plans/strengthen-domain-invariant-enforcement.md) | 🚧 In Progress | [#281](https://github.com/torrust/torrust-tracker-deployer/issues/281) | Enforce DDD invariants in domain layer | 2026-01-21 |

docs/refactors/plans/strengthen-domain-invariant-enforcement.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Strengthen Domain Invariant Enforcement
22

3+
**Issue**: [#281](https://github.com/torrust/torrust-tracker-deployer/issues/281)
4+
35
## 📋 Overview
46

57
This refactoring plan addresses DDD violations where domain types fail to enforce business invariants. Currently, some domain configuration types have public fields and lack validated constructors, allowing the creation of invalid domain objects. This undermines the core DDD principle that domain entities should be "always valid" after construction.

0 commit comments

Comments
 (0)