Ash in an ALA app: which pieces fit, which don't, and where the rest goes

October 8, 2026 · ALA · Ash · Elixir · R10 · R1

The LiveView post asked how close a Phoenix page can come to Spray’s application layer. This one asks the same about the other framework an Elixir team is likely to adopt. Ash is popular, declarative and well engineered, and its central idea, a resource that is the single source of truth from which everything else is derived, is the idea Spray spends §6.17 arguing against. So the question isn’t whether Ash is “good” but which of its pieces an ALA app can use, in which layer, and what to do with the ones it can’t. Spray says nothing about Ash; every placement below is the checklist’s reading, with the rule it rests on.

What kind of framework Ash is

Ash calls itself a declarative, resource-oriented application framework. You declare an Ash.Resource: its attributes, relationships to other resources, actions (create, read, update, destroy, and generic ones), the changes and validations that run inside an action, calculations and aggregates over its data, identities, policies for authorization, and a data layer (AshPostgres, ETS, Mnesia). Extensions then derive the rest from that declaration: AshPhoenix builds forms, AshJsonApi and AshGraphql build APIs, AshAuthentication adds users, AshStateMachine adds a state field with transitions, AshOban schedules work against records, and the notifiers publish what an action did. Resources are grouped by an Ash.Domain, whose code interface (define :add_line) is how the rest of the app calls them.

Three characteristics matter for ALA:

  1. The resource is the hub. Everything attaches to the entity: its behaviour (actions), its rules (changes, validations, policies), its derived data (calculations, aggregates), its relationships, its side effects (notifiers, triggers). That is the “class per business noun, holding data, accessors and the behaviour of every use case that touches it” the OO checklist names as the entity Spray rejects: entities “will tend to hold some fields that, although they associate with an identity, really belong to separate use cases” (§6.17.2).
  2. It is a DSL over Spark, so declarations are knowledge dependencies on Ash. A resource uses Ash.Resource; a change implements Ash.Resource.Change; a notifier implements Ash.Notifier. Each is a module configuring a far more general framework, which R9 allows: the same as implementing GenServer or LiveView’s callbacks. The framework itself sits in Programming Paradigms and Foundation, library-provided.
  3. It composes by containment, not by wiring. A change lives inside an action, which lives inside a resource; a trigger lives inside a resource’s oban block. Spray has “no analog of a sub-module or sub-component” (§2.2). The composition an ALA app wants, this feature’s store wired to that feature’s input by the layer above, has no place in the DSL. The DSL’s place for cross-cutting behaviour is the resource.

So Ash is best read as a very good implementation of the architecture ALA replaces. That doesn’t make it unusable. It makes the usable slice narrow and specific.

Where each piece sits

Ash pieceALA readingLayer, and the rule
Ash.Resource with attributes and a data layeran abstraction of persistence: one table and its schema (§6.19)Foundation, like a Repo plus a schema
one resource per feature’s private data, keyed by an identity (cart_items with cart_id)Spray’s identity-key technique (§6.17.2)Foundation; owned by that feature, configured into it by the composition
one Order resource every feature reads and writes, with attributes for each use casethe shared entity: two features knowing the meaning of the same data (R10), each reaching it by name (R1, R9)the defect; split by use case, share the key
relationships across features’ resources, and loading through theman association that lets one feature walk into another’s data (R10)avoid across features; inside one feature’s resources it’s that feature’s own joins
actions with changes and validatesthe feature’s rules, when the resource is that feature’s; a shared rule stuffed into a shared entity, when it isn’tper-feature: Foundation store with its intrinsic rules; shared: R10, R6
validation messages in the resource (message: "...")words below the composition (R3)pass them in: Ash takes messages as options, and a form can supply them
calculations, aggregatespure rules over the resource’s own data: fine; an aggregate across features’ resources is a shared read (R10)with the resource it belongs to
identities, multitenancyintrinsic to the tableFoundation
policies (Ash.Policy.Authorizer)an intrinsic constraint of the data (who may read a table) or a product rule (who may check out)? Usually the latter: R3 and R11 when the app’s rules live in a resourcekeep the intrinsic ones; pass product rules in as configured checks
Ash.Domain and code interfaces (define)the main interface of a store: configuration-shaped calls from the layer above (§2.3.4). A problem only when features call peers’ domains through itFoundation entry point
AshPhoenix.Forma generic record form the page configures and wires: a UI domain abstraction hostDomain UI
AshStateMachinea state machine inside the entity: history belongs in a state-machine abstraction (§4.16), which this is, but attached to the hubfine for a per-feature resource; a shared resource’s state machine is a shared rule
Ash.Notifier, Ash.Notifier.PubSubthe resource publishing what it did: see below—
AshOban triggers and scheduled actionsthe resource scheduling its own follow-ups: see below—
Reactora saga runner: an execution modelProgramming Paradigms, if used generically

The rule in one sentence: use Ash.Resource as the store abstraction for one feature’s private table, keyed by an identity, with that feature’s intrinsic rules inside it, and nothing more. Attributes, a data layer, per-feature actions and calculations, identities, code interfaces and the form are the parts that fit. Relationships across features, a resource every feature reads, policies encoding product rules, and the two mechanisms below are the parts that don’t, each with a named rule against it.

The honest caveat: Ash’s power is in exactly the parts ALA forbids. Cross-resource loads, relationships, notifiers that fan out, triggers that react to data. An Ash-in-ALA app uses a small and unusual slice, and a team that chose Ash for its derivations will feel it fighting them. If the team wants the derivations, they are choosing the entity architecture, and the checklist’s job is to say so, not to pretend the two agree.

Notifications, the PubSub notifier, and AshOban

These three are where Ash does the most for you and where ALA’s rules bite hardest, because each is a lower abstraction deciding what happens next. Spray’s rule for that is §4.4.2: “receivers never register themselves to a sender, or to a public event”, and its mirror, an output port “may say ‘This has happened’ or ‘Here is my result’, not ‘do this next’” (§7.2.6). The LiveView variants settled the same question for plain Phoenix: broadcasts are wired by the page, never fired from an Ecto callback, and a topic is a global event name owned by one module.

Ash notifications

After an action commits, Ash builds an Ash.Notifier.Notification (the resource, the action, the record, the changeset) and hands it to every notifier the resource declares. Two ways to receive it:

Ash’s PubSub notifier

Ash.Notifier.PubSub is the second form with the destination written in the resource:

pub_sub do
  module MyAppWeb.Endpoint
  prefix "cart"
  publish :update, ["item", :cart_id]
end

The resource names the endpoint, the prefix and the topic shape, and every page that subscribes to "cart:item:42" agrees on that string with the resource. That is both halves of the smell at once: the resource is the sender choosing its receivers’ channel (§4.4.2), and the topic is a symbolic connection two modules agree on (§4.7.4, R5). It is also exactly as convenient as it looks, which is why the LiveView variants had to find a replacement they could live with.

The replacement is the same as plain Phoenix’s: the composition owns the topic. Either return the notification to the caller and let the page broadcast through the Broadcast module that owns the topic (V50, V51), or configure a generic notifier with the topic from application config so the resource never writes it. In both, one module owns publish and subscribe, the page subscribes through an on_mount hook, and handle_info is a wire to a feature’s input. What you give up: the resource no longer fans out on its own, so a second page that wants the fact has to be wired to it. What you get: the wiring diagram shows every fan-out, which was the point.

AshOban

AshOban attaches two things to a resource. A trigger declares a scheduled scan (trigger :process do where expr(status == :pending); action :process end): every so often, find records matching the condition and run the action on each. A scheduled action declares a cron (scheduled_action :daily_digest, "0 8 * * *") that runs a generic action. Both put knowledge in the resource that belongs above it:

The ALA shape keeps Oban as the execution model (Programming Paradigms: a job runner is “how a kind of connection runs”) and moves the declarations up:

A layer map for an Ash app

With the pieces placed, the linter’s map is short:

def layers do
  [
    {:app,       [~r/Web\..*Live$/], paths: [~r{/live/}]},
    {:feature,   [~r/\.Features\./]},
    {:domain,    [~r/\.Domain\./, ~r/Web\.Components\./]},
    {:paradigms, [~r/\.Paradigms\./, ~r/Notifier$/, ~r/\.Jobs\./]},
    {:store,     [], uses: [~r/Ash\.Resource/, ~r/Ash\.Domain/], peer_ok: true}
  ]
end

A resource lands in the bottom layer by its use, wherever its file sits. Then the linter sees what it can see: a feature referencing another feature’s resource is R1 (and R10 once two features read one); a resource module referencing a notifier that reaches up to a page is an upward edge; a topic string in a resource and a page is R5. What it can’t see is the DSL’s own containment, relationships declared as atoms, a policy’s product rule, or a cron in a scheduled_action. Those stay a reader’s.

So, should an ALA app use Ash?

For the store abstraction, yes, and it is a good one: a resource with attributes, a data layer, intrinsic validations and a code interface is cleaner than a hand-written Repo module, and AshPhoenix.Form is a ready domain UI abstraction. For everything Ash derives from the resource across resources, no: relationships between features, notifiers that name their destination, the PubSub notifier’s topics, triggers that encode what happens next. Each of those has an ALA form that is more code and more explicit, and the explicitness is what the checklist is for. Neither variant corpus has an Ash app yet; a V51B built this way would be the honest test of whether the narrow slice is worth the dependency.

← all posts