ddd-toolkit
Domain-Driven Design building blocks for Rust: entities, value objects,
aggregates, repositories, and event dispatch, plus derive macros for the
common cases. This crate is a single-dependency facade over
ddd-toolkit-core and
ddd-toolkit-macro - add
ddd-toolkit and you get both, re-exported under one path.
Reach for ddd-toolkit-core directly instead if you want the traits with
zero macro machinery and full control over every impl.
Installation
Or add it to Cargo.toml directly, enabling the features you need:
[]
= { = "0.1", = ["chrono", "uuid"] }
derive is on by default; disable default features if you'd rather
implement ValueObject/EntityId/SecretVo/EnumVo by hand. Requires
Rust 1.85 or newer (edition 2024).
What's here
Everything is reachable directly under ddd_toolkit::, whichever of the two
underlying crates it originates in:
domain-Entity,AggregateRoot,ValueObject/Wrapped,EntityId,SecretVo,EnumVo,DomainEvent,ValidationError. Withderiveenabled,#[derive(ValueObject, EntityId, SecretVo, EnumVo)]generates the boilerplate for those four.port-Load/Save/Deleterepository traits,EventDispatcher(withDispatchError<E>reporting undelivered events on partial failure),Clock(behindchrono),IdGenerator.adapter- real port implementations, gated per feature so you only pull in what you use:SystemClockbehindchrono,UuidV4Generator/UuidV7Generatorbehinduuid.mock- test doubles:InMemoryStore(aLoad/Save/Deleteimplementation backed by aHashMap) andFixedIdGeneratorbuild unconditionally;FixedClockis behind thechronofeature.application-UseCase.
Example
use ;
;
;
;
EntityId generates the same Wrapped/TryFrom/Display impls as
ValueObject, plus Eq/Hash/Ord/PartialOrd so the id can be used as a
map key or sorted. A real aggregate implements AggregateRoot to record
domain events, and is persisted through the Load/Save ports - here via
mock::repository::InMemoryStore, a drop-in test double:
use ;
use InMemoryStore;
use ;
;
;
async
More usage, including EventDispatcher and the chrono/uuid adapters, is
covered in the API docs.
Features
| Feature | Default | Enables |
|---|---|---|
derive |
yes | #[derive(ValueObject, EntityId, SecretVo, EnumVo)] via ddd-toolkit-macro |
chrono |
no | Clock port + SystemClock/FixedClock adapters |
uuid |
no | IdGenerator port + UuidV4Generator/UuidV7Generator adapters |
zeroize |
no | #[vo(zeroize)] support on SecretVo (also requires depending on the zeroize crate directly - see its docs) |
Crates in this project
ddd-toolkit(this crate) - the facade; depend on this for normal use.ddd-toolkit-core- the domain/port traits and reference (in-memory) adapters, with no macro dependency.ddd-toolkit-macro- the derive macros, usable standalone alongsideddd-toolkit-coreor through this facade.
Changelog
See CHANGELOG.md for release history.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.