1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//! # Eventide
//!
//! A pragmatic Rust toolkit for **Domain-Driven Design** with first-class
//! support for **event sourcing** and **CQRS**.
//!
//! This umbrella crate re-exports the three building blocks that make up the
//! toolkit so you can depend on a single crate and pull in everything you
//! need:
//!
//! | Module | Source crate | Purpose |
//! |-----------------|--------------------------|--------------------------------------------------------------------|
//! | [`domain`] | [`eventide-domain`] | Aggregates, entities, value objects, events, repositories. |
//! | [`application`] | [`eventide-application`] | Command bus, query bus, handlers, application context. |
//! | [`mod@macros`] | [`eventide-macros`] | `#[entity]`, `#[entity_id]`, `#[domain_event]`, `#[value_object]`. |
//!
//! [`eventide-domain`]: https://docs.rs/eventide-domain
//! [`eventide-application`]: https://docs.rs/eventide-application
//! [`eventide-macros`]: https://docs.rs/eventide-macros
//!
//! ## Quick start
//!
//! Add the crate to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! eventide = "0.1"
//! serde = { version = "1", features = ["derive"] }
//! ```
//!
//! Then bring the most common items into scope through the [`prelude`]:
//!
//! ```rust,ignore
//! use eventide::prelude::*;
//!
//! #[entity_id]
//! struct UserId(String);
//!
//! #[entity(id = UserId)]
//! #[derive(Clone, Default)]
//! struct User {
//! name: String,
//! }
//! ```
//!
//! ## Feature flags
//!
//! All flags are enabled by default. Disable them selectively with
//! `default-features = false` to trim the dependency tree.
//!
//! - **`eventing`** *(default)* — pull in [`eventide_domain::eventing`], the
//! asynchronous event bus / engine / dispatcher built on top of `tokio`.
//! - **`macros`** *(default)* — re-export [`eventide_macros`] as
//! [`mod@macros`].
//! - **`application`** *(default)* — re-export [`eventide_application`] as
//! [`application`].
//! - **`infra-sqlx`** — opt-in `sqlx` conversions on serialized events and
//! snapshots so infrastructure crates can talk to a Postgres-backed event
//! store without forcing a database driver into the domain layer.
//!
//! ## Layered architecture
//!
//! `eventide` is intentionally split into independent crates so the pieces
//! you do not need can be left out. The dependency graph flows in one
//! direction:
//!
//! ```text
//! eventide-application → eventide-domain ← eventide-macros
//! ↑
//! └──── (optional) infra-sqlx
//! ```
//!
//! Domain code never depends on application or infrastructure types, which
//! keeps your business logic pure and easy to test.
// Allow this crate to refer to itself as `::eventide` from inside its own
// integration tests / examples / docs. The procedural macros in
// `eventide-macros` route every generated path through `::eventide::domain`
// when the user depends on this umbrella crate, so the alias is what makes
// in-crate test usage of those macros resolve to the right place.
extern crate self as eventide;
/// Domain layer: aggregates, entities, value objects, events, repositories,
/// and the optional asynchronous event engine.
///
/// Re-export of the [`eventide_domain`] crate.
pub use eventide_domain as domain;
/// Re-export of the [`async_trait`] crate so users can write
/// `#[async_trait]` on their own trait impls (e.g. [`domain::domain_service::DomainService`],
/// [`domain::eventing::EventHandler`]) without adding a direct
/// `async-trait` dependency.
///
/// The accompanying attribute-macro re-export lives in the macro namespace
/// (see [`async_trait!`](macro@async_trait)) so `use eventide::async_trait;`
/// followed by `#[async_trait]` works out of the box.
pub use async_trait;
/// Re-export of the [`tokio`] runtime so users can write `#[tokio::main]`,
/// `tokio::spawn`, etc. through `eventide::tokio` without depending on
/// `tokio` directly. Available when the `eventing` feature is enabled
/// (default).
pub use tokio;
/// Application layer: command bus, query bus, handlers, application context.
///
/// Re-export of the [`eventide_application`] crate. Available when the
/// `application` feature is enabled (on by default).
pub use eventide_application as application;
/// Procedural macros for entities, entity IDs, value objects and domain
/// events.
///
/// Re-export of the [`eventide_macros`] crate. Available when the `macros`
/// feature is enabled (on by default).
pub use eventide_macros as macros;
/// Curated set of imports that cover the day-to-day needs of writing
/// aggregates, events, commands and queries.
///
/// Bring everything in with a single glob import:
///
/// ```rust,ignore
/// use eventide::prelude::*;
/// ```
///
/// The prelude is intentionally small. If you reach for something not
/// re-exported here, import it directly from [`crate::domain`],
/// [`crate::application`] or [`crate::macros`].