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.

templates/DomainEvent.java

View on GitHub
package com.example.common.domain;

import java.time.Instant;
import java.util.UUID;

/**
 * Base interface for all domain events.
 * Events are immutable facts about something that happened in the domain.
 */
public interface DomainEvent {
    UUID eventId();
    Instant occurredAt();
}

// --- Concrete domain events as records ---

package com.example.order.domain.event;

import com.example.common.domain.DomainEvent;
import com.example.order.domain.model.CustomerId;
import com.example.order.domain.model.Money;
import com.example.order.domain.model.OrderId;

import java.time.Instant;
import java.util.UUID;

public record OrderPlaced(
    UUID eventId,
    Instant occurredAt,
    OrderId orderId,
    CustomerId customerId,
    Money total
) implements DomainEvent {

    public static OrderPlaced of(Order order) {
        return new OrderPlaced(
            UUID.randomUUID(),
            Instant.now(),
            order.getId(),
            order.getCustomerId(),
            order.getTotal()
        );
    }
}

public record OrderCancelled(
    UUID eventId,
    Instant occurredAt,
    OrderId orderId,
    CustomerId customerId,
    String reason
) implements DomainEvent {

    public OrderCancelled(OrderId orderId, CustomerId customerId, String reason, Instant occurredAt) {
        this(UUID.randomUUID(), occurredAt, orderId, customerId, reason);
    }
}
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