Domain Driven Kit
Executable DDD for Spring Boot.
Domain building blocks out of the box, architecture rules enforced in CI, and the same guardrails for humans and AI coding agents.
English · 简体中文 · Documentation · Roadmap
Generate a project, let the domain model reach into the persistence layer, and the build fails with the rule, the class and how to fix it. The output is from a real run.
Highlights
- 🧱 Domain building blocks:
Identifier, ValueObject, Entity, AggregateRoot, domain events and specifications, with zero framework dependencies enforced by tests
- 🛡️ Architecture rules that fail the build: ArchUnit rules for three- and four-layer projects, included in every generated project
- 🗄️ Safe persistence: a generic MyBatis-Plus repository with optimistic locking; missing or duplicate mappers fail at startup
- ⚡ Two-level cache: Caffeine + Redis with cross-instance invalidation, Redis failure fallback and a deserialization allow-list
- 🤖 AI-agent ready: generated projects ship
AGENTS.md, CLAUDE.md and Claude Code Skills; architecture failures come with a report agents can act on; use cases can be exposed as MCP tools
- 🧩 Twelve Spring Boot starters under one
ddk.* namespace: web, MyBatis, Redis, cache, data sources, tracing, domain events, MCP, concurrency control, scheduled jobs, read-model projections, ArchGuard
- 🚀 Start in minutes: Maven archetypes and a runnable example, built and tested in CI on Java 21 and 25
Why DDK
domain-driven-kit is not a heavy business framework. It is an evolving Java DDD engineering toolkit that turns layered architecture, response contracts, exception handling, pagination, object mapping, repository abstractions, Spring Boot starters and architecture rules into reusable code.
It is designed for teams that want to:
- Start a Java project with a clear DDD / layered architecture baseline
- Keep Controller, Application, Domain and Infrastructure responsibilities explicit
- Standardize repeated backend concerns such as API responses, exceptions, pagination and repository boundaries
- Move architecture rules into tests and CI with ArchUnit instead of leaving them only in documentation
How it relates to COLA, Spring Modulith and jMolecules
These projects overlap with DDK in places and solve different problems. They are not mutually exclusive, and DDK builds on one of them.
| Project |
What it gives you |
Reach for it when |
| COLA |
A layered application architecture with archetypes, plus components such as an extension mechanism and a state machine |
You want Alibaba’s COLA layering and its components |
| Spring Modulith |
Verification of boundaries between business modules, module-level integration tests, and an event publication registry |
Your main concern is keeping the modules of a modular monolith apart |
| jMolecules |
Annotations and interfaces that name DDD and architecture concepts in code, with integrations that derive rules and boilerplate from them |
You want to express the concepts and keep full freedom over implementation |
| DDK |
Base classes for the building blocks, a MyBatis-Plus repository, starters for common middleware, archetypes, architecture rules with fix hints, and conventions for AI coding agents |
You want a working DDD project on Spring Boot 4 and MyBatis-Plus quickly, with the rules enforced from day one |
DDK does not replace Spring Modulith: reliable domain events in DDK run on Modulith’s event publication registry, and module boundaries inside a DDK project can still be verified with it. DDK’s layer rules and Modulith’s module rules check different axes of the same codebase.
jMolecules and DDK do not conflict, but DDK has no adapter for it either. ddk-core depends only on the JDK and JSpecify, so DDK’s base classes do not implement jMolecules’ interfaces. You can still use both in one project: put jMolecules annotations such as @AggregateRoot or @ValueObject on classes that extend DDK’s base classes, and use jMolecules’ integrations on top. Where both name the same concept, DDK’s base class is what its repository and architecture rules look at. Base classes that also implement jMolecules’ interfaces can come in a 1.x minor release, since adding an interface is compatible.
Quick Start
DDK is on Maven Central under the groupId com.domaindrivenkit from 0.10.0 on. Requirements: JDK 21+, Maven 3.9+, Spring Boot 4.1.x.
1.1.0 is out: a way out for messages that keep failing, tenants carried through cache, idempotency and rate-limit keys, dashboards and alert rules, and reproducible builds. Its new features are off by default, and upgrading from 1.0.x only changes the version. Since 1.0, breaking changes come only in a major release, as COMPATIBILITY.md describes. The upgrade guide covers every step, including from 0.12.
Generate a four-layer service (ddk-layer3-archetype for three layers):
mvn archetype:generate \
-DarchetypeGroupId=com.domaindrivenkit \
-DarchetypeArtifactId=ddk-layer4-archetype \
-DarchetypeVersion=1.1.0 \
-DgroupId=com.acme \
-DartifactId=order-service \
-Dpackage=com.acme.order \
-DinteractiveMode=false
cd order-service && mvn verify
To add DDK to an existing Spring Boot 4.1 project, import the BOM and leave out the versions. The BOM manages every DDK module and the versions of the few libraries DDK pins (Spring Modulith, the RocketMQ client, springdoc, Okio); Spring Boot itself still comes from your Spring Boot parent or BOM.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.domaindrivenkit</groupId>
<artifactId>ddk-dependencies</artifactId>
<version>1.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.domaindrivenkit</groupId>
<artifactId>ddk-web-starter</artifactId>
</dependency>
<dependency>
<groupId>com.domaindrivenkit</groupId>
<artifactId>ddk-mybatis-starter</artifactId>
</dependency>
<dependency>
<groupId>com.domaindrivenkit</groupId>
<artifactId>ddk-archguard-starter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
See the full guide: Quick Start.
Verifying artifacts
Artifacts on Maven Central are signed with the DDK release key, fingerprint 02F5 D443 996C 2388 C803 9D6C AE07 FF4C 8842 56F0 (public key). Download a jar and its .asc from Maven Central, import the key and verify; gpg should report a good signature and this primary key fingerprint:
curl -fsSO https://repo.maven.apache.org/maven2/com/domaindrivenkit/ddk-core/1.1.0/ddk-core-1.1.0.jar
curl -fsSO https://repo.maven.apache.org/maven2/com/domaindrivenkit/ddk-core/1.1.0/ddk-core-1.1.0.jar.asc
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 02F5D443996C2388C8039D6CAE07FF4C884256F0
gpg --verify ddk-core-1.1.0.jar.asc ddk-core-1.1.0.jar
The jars on GitHub Releases are built by the release workflow and carry a build provenance attestation: gh attestation verify <jar> --repo poppycoderr/domain-driven-kit. The two are separate builds of the same tag. From 1.1.0 the build is reproducible and the release checks that both places hold the same files, so a Maven Central jar has the same SHA-256 as the GitHub Release jar and the attestation and the signature cover both. Up to 1.0.x the jars differ: take the jar and the .asc from the same place.
Snapshots and older releases
Development snapshots and releases before 0.10.0 (groupId com.ddk) are not on Maven Central. scripts/ddk.sh builds them from source, installs them into your local Maven repository and runs the archetype; a release from 0.10.0 on it downloads from Maven Central instead. Building from source needs JDK 21.0.8 or newer, which the script checks; applications need only Java 21:
curl -fsSL https://raw.githubusercontent.com/poppycoderr/domain-driven-kit/main/scripts/ddk.sh | DDK_REF=main bash -s -- new order-service --group com.acme
Without DDK_REF it uses the newest release. DDK_REF=v0.9.0 picks a specific release, --layers 3 the three-layer skeleton, and ddk.sh help lists all options. A later run reuses an install only when it is the same ref, at the same commit, with its Maven artifacts still present. To build by hand instead, run mvn -B install in a clone of this repository.
Modules
DDK is maintained by one person and is in its 0.x series: a minor release may contain breaking changes, each listed in the changelog, with the steps to take in the upgrade guide. Releases from 0.10.0 on are published to Maven Central and as GitHub Releases; see Verifying artifacts. COMPATIBILITY.md lists what stays compatible between releases and what 1.0 freezes; SUPPORT.md says which versions get fixes, what DDK is tested against and how to roll back.
| Module |
Capability |
Status |
ddk-core |
Domain model primitives, ApiResponse, exceptions, pagination, mapper registry, repository contract |
Usable |
ddk-test |
Assertions on aggregates and business rules, Testcontainers presets for Redis, MySQL and RocketMQ |
Usable, used by DDK’s own tests |
ddk-mybatis |
MyBatis-Plus repository implementation, query parsing, pagination, optimistic locking, domain event publishing |
Usable, with H2 integration tests |
ddk-web-starter |
Jackson, CORS, global exception handling, and the error contract in OpenAPI docs when springdoc is present, configurable under ddk.web.* |
Usable |
ddk-mybatis-starter |
Pagination, optimistic locking, full-table update/delete guard, snowflake IDs, audit fields and multi-tenancy from the operator context, configurable under ddk.mybatis.* |
Usable, with H2 integration tests |
ddk-event-starter |
Spring-backed domain event publisher |
Usable |
ddk-mcp-starter |
Application use cases as MCP tools: argument validation, error codes, audit log, streamable HTTP by default |
Usable, with MCP client end-to-end tests |
ddk-concurrency-starter |
@AggregateLock, @Idempotent and @RateLimit on Redisson: one operation per aggregate, one execution per request, a call budget per user or tenant |
Usable, with Redis integration tests |
ddk-job-starter |
@Scheduled jobs that run on one instance at a time, on ShedLock with the lock in Redis |
Usable, with Redis integration tests |
ddk-projection-starter |
Read models refreshed from the write model: marked in the transaction, refreshed after commit, retried, rebuildable |
Usable, tested on H2, MySQL and PostgreSQL |
ddk-redis-starter |
JSON RedisTemplate with a deserialization type allow-list |
Usable |
ddk-cache-starter |
Caffeine (L1) + Redis (L2) two-level cache with cross-instance invalidation and Redis failure fallback |
Usable, with Redis integration tests |
ddk-archguard-starter |
ArchUnit rules for layering and domain purity |
Usable |
ddk-dependencies |
BOM, so downstream projects stop writing versions |
Usable |
ddk-db-starter |
Named data sources with configurable pools and a validated primary |
Usable, tested on PostgreSQL and MySQL |
ddk-tracer-starter |
Distributed tracing with the trace ID in a response header |
Usable |
ddk-archetypes |
Three- and four-layer Maven archetypes with architecture tests in every generated project |
Usable, with integration tests on generated projects |
ddk-examples |
ddk-example-user: a runnable four-layer user registration example. ddk-mall: a reference application where order, inventory and payment contexts work together through integration events, using every starter side by side |
Usable |
Domain Model
com.ddk.core.domain does exactly three things:
- Gives identity a type.
Identifier makes UserId(1) different from OrderId(1), so swapped arguments fail at compile time
- Separates value equality from identity equality.
ValueObject (an empty interface, so a record can implement it) and Entity
- Gives domain events a place to be collected and published.
AggregateRoot registers them, DomainEventPublisher publishes them after commit
The package depends on no framework at all — not Spring, MyBatis or Jackson. That constraint is enforced by DomainPackagePurityTest, not by a note in the docs.
The primitives provide mechanism without dictating process, and you can adopt only the part you need.
Architecture Guard
Core constraints:
adapter adapts external protocols and should not contain business rules
application orchestrates use cases, transactions and domain objects
domain owns business rules and should not depend on Spring, MyBatis, Jackson or other frameworks
infrastructure implements repository and external dependency contracts defined by the domain layer
Written in a document these are suggestions; written as a test they are constraints:
class ArchitectureTest {
private final JavaClasses classes = new ClassFileImporter()
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_JARS)
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
.importPackages("com.example.myapp");
@Test
void layered_architecture_is_respected() {
CommonArchRules.LAYERED_ARCHITECTURE_RULE.check(classes);
}
@Test
void domain_stays_framework_free() {
CommonArchRules.DOMAIN_MUST_NOT_DEPEND_ON_FRAMEWORKS.check(classes);
}
}
A violation fails the build. See ddk-examples/ddk-example-user for a working example.
Module Layout
domain-driven-kit
├── ddk-dependencies BOM, so downstream projects stop writing versions
├── ddk-core Core abstractions: domain model, exception, response, pagination, mapper, repository contract
├── ddk-test Domain assertions and Testcontainers presets
├── ddk-mybatis MyBatis-Plus repository implementation and query adapters
├── ddk-starters Spring Boot starter modules
│ ├── ddk-web-starter
│ ├── ddk-mybatis-starter
│ ├── ddk-redis-starter
│ ├── ddk-cache-starter
│ ├── ddk-db-starter
│ ├── ddk-tracer-starter
│ ├── ddk-event-starter
│ ├── ddk-mcp-starter
│ ├── ddk-concurrency-starter
│ ├── ddk-job-starter
│ ├── ddk-projection-starter
│ └── ddk-archguard-starter
├── ddk-archetypes 3-layer / 4-layer project skeletons
└── ddk-examples Example applications
Inside ddk-core:
com.ddk.core
├── domain Domain model primitives, zero framework dependencies
├── repository The GenericRepository contract
├── page PageQuery / PageResponse / Sort
├── mapper MapperProvider and @EnhancedMapper
├── response ApiResponse
└── exception ErrorCode and the exception hierarchy
Roadmap
Released so far:
-
v0.1 Modern baseline: Spring Boot 4.1 / Jackson 3 and the first GitHub Release
-
v0.2 AI collaboration: generated projects ship AGENTS.md and Skills, ArchGuard reports violations agents can act on, an MCP starter on Spring AI
-
v0.3 Reliable domain events: transactional outbox, Kafka / RocketMQ delivery, event contracts, idempotent consumers
-
v0.4 Middleware integrations: aggregate locks, duplicate-submit protection and rate limits, scheduled jobs, Flyway, the error contract in API docs, ddk-test
-
v0.5 Operator context: audit fields and fail-closed multi-tenancy driven by one operator context, ArchGuard fix hints in English
-
v0.6 Events end to end: declared consumers, traces that follow events across contexts, and the ddk-mall reference application
-
v0.7 Fail where the mistake is made: events published outside a transaction and locks taken inside one are rejected on the spot; job locks without Redis
-
v0.8 The query side: read models refreshed from the write model and rebuildable, row-level data scope
-
v0.9 Reliability and the production path: converging projections, safe idempotency, stable consumer identities, tenants in background work, event and projection operations, an upgrade guide
-
v0.10 Adoption and upgrades: the com.domaindrivenkit groupId, a review of the public API and dependencies, build provenance on releases, signing for Maven Central, upgrade rehearsals
-
v0.11 Contracts before the freeze: data and wire formats and the platform policy written down, fixtures of released data, an asserted upgrade and rollback rehearsal, a 1.0 freeze checklist draft
-
v0.12 Decisions before the freeze: cancelled requests answered with 503, the DB starter stable and the Seata starter deprecated, sampled publication metrics, more native images, a 30-second start for every starter
-
v1.0 Freeze: only what has been verified, with a support matrix and strict semantic versioning from now on; released on 2026-11-13
-
v1.1 Failures and tenants: a way out for failing messages, tenant-aware keys, dashboards and alert rules, the tracer starter out of preview, reproducible builds; released on 2026-12-04 (latest release)
Next: v1.2, guardrails between contexts: context isolation rules, aggregate-level rules and a domain catalog, as the roadmap plans.
See ROADMAP.md for the full plan.
Documentation
Contributing
Issues and PRs are welcome; CONTRIBUTING.md explains how. For a first contribution, pick an issue labelled good first issue. Each starter’s README starts with In 30 seconds and ends with Common errors, the place to look when a starter does not behave as expected.
The most useful contributions right now are:
- Starter auto-configuration fixes
- Tests and runnable examples
- DDD layering examples and documentation
- Clearer trade-off analysis for existing design decisions
Run mvn verify before opening a PR: it checks formatting with Spotless (fix with mvn spotless:apply) and requires at least 70% line and 50% branch coverage per module. Main code is @NullMarked: mark anything that may be null with @Nullable, or NullAway fails the compile.
Built With
- Code and docs are written in IntelliJ IDEA with the help of Claude Code and Codex; every change is reviewed, tested and passes CI before it is merged.
- The documentation site codesphere is built with VitePress; earlier versions used docsify.
License
Apache License 2.0. Free to use, modify and distribute, including commercially; keep the copyright and license notices, and state changes made to modified files.
评论