Build functional, event-sourced domain models in Elixir using aggregate roots that rebuild state from events.
Eventsourced is an Elixir library for building functional, event-sourced domain models. It provides a structured approach to implementing the event sourcing pattern, where state changes are captured as immutable events and aggregate state is rebuilt by replaying those events. This enables reliable state reconstruction and audit trails.
Elixir developers building domain models that require strict auditability, reliable state reconstruction, and adherence to functional programming principles, particularly in systems like financial applications, inventory management, or any domain where a complete history of state changes is critical.
Developers choose Eventsourced for its functional, idiomatic Elixir approach to event sourcing, offering a clear macro-based structure for defining aggregates with explicit event handling and state reconstruction. Its flexibility in error handling (supporting both :ok/:error tuples and exceptions) and straightforward testing capabilities make it a practical choice for implementing event-sourced models.
Functional domain models with event sourcing in Elixir
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Commands are pure functions that accept current state and return new state with applied events, ensuring immutability and clear domain logic, as shown in the bank account example where deposit and withdraw functions update balance via events.
The `use EventSourced.AggregateRoot` macro simplifies defining aggregates with state fields and event application callbacks, reducing boilerplate code for setting up event-sourced models.
Supports both :ok/:error tuples and exceptions for business rule violations, allowing teams to choose based on their error handling philosophy, as detailed in the README's examples for account opening.
Testing involves verifying applied events and resulting state after command execution, making it easy to test domain logic without mocks, as demonstrated in the deposit money test case.
Eventsourced only handles domain modeling; developers must implement event storage, serialization, and retrieval themselves, adding complexity for production deployments.
When using :ok/:error tuples for error handling, the Elixir pipeline operator cannot be used, requiring the `with` special form instead, which may disrupt coding flow for teams accustomed to pipelines.
Each event type requires a separate `apply/2` function to update state, increasing boilerplate and potential for errors in domains with many events, as seen in the bank account's multiple apply functions.