domain-driven-design

Featured

Use when working with domain models, aggregates, value objects, domain events, or repositories in a DDD-style project. Ensures rich domain model over anemic CRUD.

AI & Automation 225 stars 37 forks Updated 6 days ago MIT

Install

View on GitHub

Quality Score: 88/100

Stars 20%
78
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Domain-Driven Design ## Aggregate Rules - One repository per aggregate root - External code only accesses aggregate through root — never child entities directly - Aggregates reference other aggregates by ID only, not direct object reference - Keep aggregates small — if it has more than 3-4 child entities, split it ```java // ✅ Aggregate root controls all access to children order.addItem(productId, quantity); // through root order.removeItem(itemId); // through root // ❌ Direct child access from outside order.getItems().add(new OrderItem(...)); // bypasses invariants ``` ## Value Objects Immutable, no identity, equality by value: ```java public record Money(BigDecimal amount, Currency currency) { public Money { if (amount.compareTo(BigDecimal.ZERO) < 0) throw new IllegalArgumentException("Amount cannot be negative"); Objects.requireNonNull(currency); } public Money add(Money other) { if (!currency.equals(other.currency)) throw new CurrencyMismatchException(currency, other.currency); return new Money(amount.add(other.amount), currency); } public static Money of(String amount, String currency) { return new Money(new BigDecimal(amount), Currency.getInstance(currency)); } } public record EmailAddress(String value) { public EmailAddress { if (!value.matches("^[\\w.-]+@[\\w.-]+\\.[a-z]{2,}$")) throw new InvalidEmailException(value); } } ``` ## Dom...

Details

Author
rrezartprebreza
Repository
rrezartprebreza/spring-boot-skills
Created
4 months ago
Last Updated
6 days ago
Language
Java
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category