Skip to content

rrezartprebreza/spring-boot-skills / skills/spring-boot-3/domain-driven-design

domain-driven-design

Verified

Use when evolving aggregate invariants, value objects or domain events in an existing DDD-style Spring Boot 3 application, or when DDD is explicitly requested. Preserve existing API identifiers and architecture when changing domain behavior.

examples/bad-aggregate.java

View on GitHub
// BAD — anemic model, no invariant enforcement, no typed IDs, no events

@Entity
@Data                                        // generates public setters — anyone can mutate state
@NoArgsConstructor                           // public no-arg constructor allows invalid objects
public class Order {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;                         // Long ID — not a typed value object

    private Long customerId;                 // Long — should be CustomerId value object

    private String customerEmail;            // raw String — should be EmailAddress value object

    @Enumerated(EnumType.ORDINAL)            // ORDINAL breaks if enum is reordered
    private OrderStatus status;

    private BigDecimal total;                // raw BigDecimal — should be Money value object

    @OneToMany(mappedBy = "order")           // missing cascade, orphanRemoval
    private List<OrderItem> items;           // not initialized — NPE risk

    // No behavior methods — all logic will live in service:
    // - No addItem() method
    // - No place() method
    // - No state transition validation
    // - No domain events
    // - Total is set manually from outside, not calculated

    // External code does:
    // order.getItems().add(new OrderItem(...));  // bypasses aggregate boundary
    // order.setStatus(OrderStatus.PLACED);       // no invariant check
    // order.setTotal(calculateTotal(items));      // logic outside domain
}
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall