Datumo

An opinionated event-sourcing framework for Elixir apps built from Event Modeling slices, on the FACT event store.

Early. Datumo is being extracted from two real apps. Until 1.0 the API can change between minor versions; every change that touches your slices is in the changelog.

Datumo is Esperanto for "a datum": one piece of data, one fact.

What it is

Each slice of the board becomes a small module that Datumo runs:

The opinions are deliberate: one store (FACT), DCB instead of aggregates, folding on read, Ecto changesets for input. No database server.

Installation

def deps do
  [
    {:datumo, "~> 0.1"}
  ]
end

A write slice

defmodule Library.Slices.LendBook.Decider do
  use Datumo.StateChange

  alias Library.Slices.LendBook.{BookLent, LendBook}

  @impl true
  def query(%LendBook{book_id: book_id}) do
    Fact.QueryItem.types(["BookAdded", "BookLent"])
    |> Fact.QueryItem.tags(["book:#{book_id}"])
  end

  @impl true
  def initial_state, do: %{added: false, lent: false}

  @impl true
  def apply_event(state, %{"event_type" => "BookAdded"}), do: %{state | added: true}
  def apply_event(state, %{"event_type" => "BookLent"}), do: %{state | lent: true}

  @impl true
  def execute(%LendBook{} = cmd, state) do
    cond do
      not state.added -> {:error, :book_not_found}
      state.lent -> {:error, :book_already_lent}
      true -> {:ok, [%BookLent{loan_id: cmd.loan_id, book_id: cmd.book_id, member_id: cmd.member_id}]}
    end
  end
end

Datumo.Decide.execute(db, Library.Slices.LendBook.Decider, cmd)

A full app built this way: eventmodelers-elixir-fact-library, a lending library. It is built by the Elixir FACT build kit for eventmodelers.ai.

License

MIT