Spring boot data ddd

From joaquimscosta/arkhe-claude-plugins · View interactive version

Spring boot data ddd is an AI agent skill from the GitHub repository joaquimscosta/arkhe-claude-plugins. Spring Boot 4 data layer implementation for Domain-Driven Design. Use when implementing JPA or JDBC aggregates, Spring Data repositories, transactional services, projections, or entity auditing. Covers aggregate roots with AbstractAggregateRoot, value object mapping, EntityGraph for N+1 prevention,

How to use this skill

Skill file

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

  1. 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:

Spring Boot 4 Specifics

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

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

  1. One aggregate per transaction — Cross-aggregate changes via domain events
  2. Repository per aggregate root — Never for child entities
  3. Value objects are immutable — No setters, return new instances
  4. Flush before events — Call repository.save() before events dispatch
  5. Test with @DataJpaTest — Use TestEntityManager for setup
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.