🧠 Deep DDD & Model Improvements Roadmap
🎯 Purpose
This issue tracks structural improvements in the model package to:
- Strengthen DDD alignment
- Make invariants explicit
- Improve SOLID compliance
- Remove hidden assumptions
- Increase long-term maintainability
This is not a bug fix.
This is a model hardening and architectural refinement task.
🔴 Priority 1 – Critical Domain Consistency
☐ Refactor Transaction to be DDD-consistent
☐ Make FIFO explicit in Holding.sell()
- ☐ Define FIFO rule formally (by
purchasedAt)
- ☐ Sort lots before selling OR
- ☐ Replace internal structure with ordered queue
- ☐ Add unit test proving FIFO independent of insertion order
🟠 Priority 2 – Domain Invariants Clarification
☐ Define invariant for empty holdings
☐ Standardize exception strategy
- ☐ Introduce
DomainException base class
- ☐ Replace
IllegalArgumentException in domain layer
- ☐ Align JavaDoc with actual thrown exceptions
- ☐ Ensure consistency across all IDs and Value Objects
🟡 Priority 3 – Model Expressiveness Improvements
☐ Replace ownerName String with OwnerName Value Object
- ☐ Enforce non-blank
- ☐ Trim input
- ☐ Possibly length validation
- ☐ Add unit tests
☐ Reduce redundant validations (improve DRY)
-
☐ Audit duplicate checks in:
- ☐
Portfolio.buy
- ☐
Lot.create
- ☐
Portfolio.deposit
-
☐ Centralize validation inside Value Objects where possible
-
☐ Keep defense-in-depth but remove unnecessary duplication
🟢 Priority 4 – Minor Cleanups & Naming
- ☐ Rename awkward method names (e.g.
getRemainingSharesPurchasePrice)
- ☐ Avoid repeated
getTotalShares() calls in same block
- ☐ Improve domain wording consistency
- ☐ Review Javadoc coherence across model
🧪 Optional Hardening Tasks
- ☐ Add tests for invariant enforcement
- ☐ Add tests for FIFO correctness after rehydration
- ☐ Add tests for invalid Transaction states
- ☐ Review aggregate boundaries under stress scenarios
📌 Acceptance Criteria
This issue can be closed when:
- All critical invariants are explicit
- Transaction modeling is internally consistent
- FIFO behavior is deterministic and tested
- Exception strategy is unified
- Domain language is coherent and expressive
- No hidden ordering assumptions remain
🧭 Long-Term Vision
Goal:
Turn this model into ailgrade DDD reference implementation suitable for:
- Teaching advanced DDD
- Architectural demonstrations
- Production-grade domain modeling patterns
🧠 Deep DDD & Model Improvements Roadmap
🎯 Purpose
This issue tracks structural improvements in the
modelpackage to:This is not a bug fix.
This is a model hardening and architectural refinement task.
🔴 Priority 1 – Critical Domain Consistency
☐ Refactor
Transactionto be DDD-consistent☐ Decide: Entity or true Value Object?
☐ If Value Object:
record)TransactionType☐ If Entity:
☐ Align documentation with real behavior
☐ Make FIFO explicit in
Holding.sell()purchasedAt)🟠 Priority 2 – Domain Invariants Clarification
☐ Define invariant for empty holdings
☐ Decide: remove holding when shares reach zero?
☐ If yes:
☐ If no:
☐ Standardize exception strategy
DomainExceptionbase classIllegalArgumentExceptionin domain layer🟡 Priority 3 – Model Expressiveness Improvements
☐ Replace
ownerNameString withOwnerNameValue Object☐ Reduce redundant validations (improve DRY)
☐ Audit duplicate checks in:
Portfolio.buyLot.createPortfolio.deposit☐ Centralize validation inside Value Objects where possible
☐ Keep defense-in-depth but remove unnecessary duplication
🟢 Priority 4 – Minor Cleanups & Naming
getRemainingSharesPurchasePrice)getTotalShares()calls in same block🧪 Optional Hardening Tasks
📌 Acceptance Criteria
This issue can be closed when:
🧭 Long-Term Vision
Goal:
Turn this model into ailgrade DDD reference implementation suitable for: