finds.dev← search

// the find

joaomdmoura/machinery

★ 568 · Elixir · Apache-2.0 · updated May 2024

Elixir State machine thin layer for structs

Machinery is a small Elixir library for adding named-state transitions to structs, with a hook system (guard/persist/before/after/log) that plugs into Ecto and Phoenix apps. It's for someone who wants a lightweight state machine on an existing schema without pulling in something heavier like Fsm or a full workflow engine.

The transitions map with wildcard support (`"*" => "canceled"`) covers the common 'any state can be cancelled' case without repeating it everywhere. The callback split (guard_transition, persist, before/after_transition, log_transition) maps cleanly onto a typical Ecto changeset + audit log flow, and each callback just gets the struct plus the target state string, so it's easy to pattern-match. It's a thin layer by design — you keep your own persistence and don't have to adopt a DSL for your schema itself.

The `transitions` map is inconsistently typed: some values are a list of strings, others a bare string (`"partial" => "completed"`), which means callers and the library's own matching logic have to handle both shapes — a rough edge in a public API. There's no protection against concurrent transitions; two processes calling `transition_to/3` on stale state at the same time can both pass the guard and both persist, since there's no optimistic lock or CAS built in. Last push was May 2024 and the project has been essentially the same API since 2016 with only ~568 stars, so don't expect fast turnaround on issues or Elixir/OTP-version compatibility fixes. The 'dashboard' topic tag is misleading — there's no dashboard or telemetry integration in the code, just the transition callbacks.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →