spring-boot-data-ddd
Spring Boot Data Layer for DDD
Implements DDD tactical patterns with Spring Data JPA and Spring Data JDBC in Spring Boot 4.
Technology Selection
| Choose | When |
|---|---|
| Spring Data JPA | Complex queries, existing Hibernate expertise, need lazy loading |
| Spring Data JDBC | DDD-first design, simpler mapping, aggregate-per-table, no lazy loading |
Spring Data JDBC enforces aggregate boundaries naturally—recommended for new DDD projects.
Core Workflow
- Define aggregate root → 2. Map value objects → 3. Create repository → 4. Implement service layer → 5. Add projections
See WORKFLOW.md for detailed step-by-step instructions with code examples.
Quick Patterns
See EXAMPLES.md for complete working examples including:
- Aggregate Root with AbstractAggregateRoot and domain events (Java + Kotlin)
- Repository with EntityGraph for N+1 prevention
- Transactional Service with proper boundaries
- Value Objects (Strongly-typed IDs, Money pattern)
- Projections for efficient read operations
- Auditing with automatic timestamps
Spring Boot 4 Specifics
- JSpecify null-safety:
@NullMarkedand@Nullableannotations - AOT Repository Compilation: Enabled by default for faster startup
- Jakarta EE 11: All imports use
jakarta.*namespace - ListCrudRepository: New interface returning
List<T>instead ofIterable<T>
ListCrudRepository (Spring Data 3.1+)
New repository interface returning List<T> for better API ergonomics:
// OLD: CrudRepository returns Iterable<T>
public interface UserRepository extends CrudRepository<User, Long> {
Iterable<User> findAll(); // Requires conversion to List
}
// NEW: ListCrudRepository returns List<T>
public interface UserRepository extends ListCrudRepository<User, Long> {
List<User> findAll(); // Direct List return
List<User> findAllById(Iterable<Long> ids); // Also List
}
// Can also extend both for full functionality
public interface UserRepository extends
ListCrudRepository<User, Long>,
ListPagingAndSortingRepository<User, Long> {
}
Benefits: No more StreamSupport.stream(iterable.spliterator(), false).toList() conversions.
Detailed References
- Workflow: See WORKFLOW.md for detailed step-by-step data layer implementation
- Examples: See EXAMPLES.md for complete working code examples
- Troubleshooting: See TROUBLESHOOTING.md for common issues and Boot 4 migration
- Aggregates & Entities: See references/AGGREGATES.md for complete patterns with value objects, typed IDs, auditing
- Repositories & Queries: See references/REPOSITORIES.md for custom queries, projections, specifications
- Transactions: See references/TRANSACTIONS.md for propagation, isolation, cross-aggregate consistency
Related Skills
| Need | Skill |
|---|---|
| DDD concepts and design | domain-driven-design |
| REST API for aggregates | spring-boot-web-api |
| Module boundaries | spring-boot-modulith |
| Repository testing | spring-boot-testing |
Anti-Pattern Checklist
| Anti-Pattern | Fix |
|---|---|
FetchType.EAGER on associations |
Use LAZY + @EntityGraph when needed |
| Returning entities from controllers | Convert to DTOs in service layer |
@Transactional on private methods |
Use public methods (proxy limitation) |
Missing readOnly = true on queries |
Add for read operations (performance) |
| Direct aggregate-to-aggregate references | Reference by ID only |
| Multiple aggregates in one transaction | Use domain events for eventual consistency |
Critical Reminders
- One aggregate per transaction — Cross-aggregate changes via domain events
- Repository per aggregate root — Never for child entities
- Value objects are immutable — No setters, return new instances
- Flush before events — Call
repository.save()before events dispatch - Test with
@DataJpaTest— UseTestEntityManagerfor setup
More from joaquimscosta/arkhe-claude-plugins
skill-validator
Validate skills against Anthropic best practices for frontmatter, structure, content, file organization, hooks, MCP, and security (62 rules in 8 categories). Use when creating new skills, updating existing skills, before publishing skills, reviewing skill quality, or when user mentions "validate skill", "check skill", "skill best practices", "skill review", or "lint skill".
30domain-driven-design
Expert guidance for Domain-Driven Design architecture and implementation. Use when designing complex business systems, defining bounded contexts, structuring domain models, choosing between modular monolith vs microservices, implementing aggregates/entities/value objects, or when users mention "DDD", "domain-driven design", "bounded context", "aggregate", "domain model", "ubiquitous language", "event storming", "context mapping", "domain events", "anemic domain model", strategic design, tactical patterns, or domain modeling. Helps make architectural decisions, identify subdomains, design aggregates, and avoid common DDD pitfalls.
26code-explanation
Explains complex code through clear narratives, visual diagrams, and step-by-step breakdowns. Use when user asks to explain code, understand algorithms, analyze design patterns, wants code walkthroughs, or mentions "explain this code", "how does this work", "code breakdown", or "understand this function".
22generating-changelog
Analyzes git commit history and generates professional changelogs with semantic versioning, conventional commit support, and multiple output formats (Keep a Changelog, Conventional, GitHub). Use when editing CHANGELOG.md, CHANGELOG.txt, or HISTORY.md files, preparing release notes, creating releases, bumping versions, updating changelog, documenting changes, writing release notes, tracking changes, version bump, tag release, or when user mentions "changelog", "release notes", "version history", "release", "semantic versioning", or "conventional commits".
21workflow-orchestration
>
19generating-stitch-screens
>
19