Building blocks & stereotypes

An aggregate is a cluster of associated objects — a root entity together with the entities and value objects it owns — treated as a single unit for data changes. The aggregate root is the only entry point and enforces the invariants that must hold across the cluster; each aggregate is the boundary of one transaction and one unit of consistency. Value objects and child entities are the other core building blocks of the domain model.

Spring DDD’s annotations are provided by the spring-ddd-annotations, spring-ddd-cqrs, spring-ddd-eventsourcing, and spring-ddd-domain-events libraries. Each annotation drives concrete framework behaviour and carries the matching jMolecules stereotype as a meta-annotation, so the domain model stays legible to jMolecules-aware tooling (ArchUnit, Spring Modulith) without a direct jMolecules compile dependency.

Spring DDD annotations

Annotation Module Package jMolecules stereotype

@Aggregate

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

AggregateRoot

@AggregateId

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

Identity

@ApplicationService

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

Service

@DomainService

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

Service

@DomainEvent

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

DomainEvent

@Command

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

Command

@Query

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

@ReadModel

spring-ddd-annotations

de.dwittkoetter.ddd.annotation

QueryModel

@EventSourcingHandler

spring-ddd-eventsourcing

de.dwittkoetter.ddd.eventsourcing

DomainEventHandler

@DomainEventHandler

spring-ddd-domain-events

de.dwittkoetter.ddd.domainevents

DomainEventHandler

@CommandHandler

spring-ddd-cqrs

de.dwittkoetter.ddd.cqrs

CommandHandler

@QueryHandler

spring-ddd-cqrs

de.dwittkoetter.ddd.cqrs

Meta-annotation detection

The framework detects annotations via Spring’s meta-annotation resolution, not by exact type. You can define your own annotation meta-annotated with @Command, @Query, or @DomainEvent and the framework detects it automatically — no additional registration required.

import de.dwittkoetter.ddd.annotation.Command

@Command(namespace = "banking")
annotation class BankingCommand

A class annotated with @BankingCommand is treated as a command everywhere Spring DDD inspects the type.

jMolecules annotations used as-is

The jMolecules DDD and CQRS annotations are on the classpath transitively. Use them directly to mark entities, value objects, and query models:

Annotation Package

@Entity

org.jmolecules.ddd.annotation

@ValueObject

org.jmolecules.ddd.annotation

@QueryModel

org.jmolecules.architecture.cqrs