V38-max: a plain LiveView at 100

September 30, 2026 · ALA · V38 · LiveView · wiring · checklist

This is the last of three “max” posts, after V41-max and V39-max. Each takes a design and changes it, in a copy, until a hand walk of the ALA Checklist finds nothing left to deduct.

V38 was the odd one out. Its charter was to evolve a conventional Phoenix app toward ALA without adding indirection, so its pages keep their logic on purpose. It was also smaller than the other storefronts: one cart page, the product pages, and a single-step checkout. On 2026-10-01 both V38 and V38-max were built out to the full storefront and portal requirements the other full variants meet: tabs, save for later, a wishlist, per-item gift wrap, undo with a window, a two-step checkout with URLs and async payment, and the B2B portal with volume tiers and a purchase-order form. Both now pass the same acceptance tests as V39-max, ported unchanged in substance.

So V38-max answers a narrower question than the other two: what is the least machinery that turns pages like V38’s into pure wiring, at full size?

The pages after

Each page is still one LiveView module (CartLive.Show, PortalLive.Show). There’s no bindings map, no route table and no LiveComponent. What changed is that the pages no longer decide anything.

The features are V39-max’s, reused unchanged apart from their names: Cart, Undo, SavedItems, Wishlist, PageUI, Checkout, OrderLines, PortalCatalog and PortalSubmit, each a plain module over its own struct whose inputs return {state, outputs}. So are the domain rules (CalculateShipping, ValidatePromo, StockStatus, VolumeTier, …) and the generic components. That’s ALA’s claim about domain abstractions put to a small test: they dropped into a different composition, over a different foundation, without changes. The store work stays V38-max’s own: Charge (V38’s charge/3 gateway), SettleOrder and AddLine, each configured once with its stores and its cart.

A handler runs one input:

def handle_event("remove_item", %{"item-id" => id}, socket),
  do: {:noreply, run(socket, :cart, &Cart.remove(&1, %{item_id: int(id)}))}

Clauses as wires

run/3 hands the step to a paradigm module, Steps (56 lines), which stores the feature’s new state and folds each output through the page’s own wire/3:

def run(socket, key, step, land) do
  {state, outputs} = step.(socket.assigns[key])
  Enum.reduce(outputs, assign(socket, key, state), &land.(&2, key, &1))
end

The page’s wire/3 clauses are its wiring, one per declared port, read top to bottom: 29 on the cart page and 15 on the portal.

defp wire(s, :cart, {:removed, item}), do: run(s, :undo, &Undo.capture(&1, item))
defp wire(s, :cart, {:checkout_requested, cart}), do: run(s, :checkout, &Checkout.pay(&1, cart))

defp wire(s, :undo, {:captured, item}),
  do: s |> assign(:undo_pending, true) |> Steps.start_timer(:undo, item, Catalog.undo_window_ms())

defp wire(s, :wishlist, {:taken, product}),
  do:
    s
    |> Steps.feed(:cart, &Cart.receive/2, &AddLine.run(s.assigns.add_line, &1), product, &wire/3)
    |> put_flash(:info, "Added to cart")

defp wire(s, :checkout, {:step, step}), do: s |> assign(:step, step) |> Steps.patch(@step_paths, step)

The checklist already lists this as a way to meet R8: keep the page legible, one clause per action, read as the page’s behaviour. Pattern matching does the job Spray’s port names do. It fits his description of what the top layer should be, the “3-10% of the entire application” that describes the requirements (§2.4), in one place.

Where V39-max’s map needs a binding kind, a clause just calls the function: put_flash, assign, start_async. Steps only adds what would otherwise put a decision or a nested call in a clause: feed/6 runs an input on what a source answers (a store read or a configured instance’s I/O), patch/3 patches only when the step has a URL, and start_timer/4 and stop_timer/2 keep a named timer. Six functions in all, against V39-max’s fourteen binding kinds and a protocol.

There’s no catch-all clause, so an output without a wire crashes the page instead of vanishing. One test per page backs that up. It parses the page’s source, collects every wire/3 clause head, and checks each feature’s declared outputs against them in both directions. I checked it by deleting a clause; it named the missing port.

Does it hold at forty ports? That was the open question when V38-max had eleven. At 44 the clauses still read as a list: each is one line or a short pipe, grouped by feature, and the cart page’s wiring block is about 86 lines, close to V39-max’s bindings map for the same page. What a map gives you that clauses don’t is a value you can print or check by key at run time. Here the check runs in the test suite, and the linter’s new :ports checks run in CI.

Techniques, with code

Each technique below is described under its rule in the ALA Checklist and the field guide.

Configured rules and instances, built once (R9, R3). Every number comes from GoodDeal.Catalog; the page builds each rule and each store-work instance once:

pricing = %{
  shipping: CalculateShipping.new(Catalog.rates()),
  stock_status: StockStatus.new(low_at: Catalog.low_stock_threshold()),
  promo: ValidatePromo.new(Catalog.promo_codes()),
  gift_wrap: CalculateGiftWrapCost.new(Catalog.gift_wrap_cents())
}
add_line: %AddLine{carts: Carts, products: Products, cart_id: cart_id},
settle: %SettleOrder{orders: Orders, carts: Carts, products: Products, announce: &Broadcast.stock_changed/2, cart_id: cart_id}

A source fed into an input (R11). Mount doesn’t hand the store’s rows to the cart; the runner does:

|> Steps.feed(:cart, &Cart.load/2, &Carts.list_items/1, cart_id, &wire/3)

Store work in domain instances (R11). V38’s apply_effect/2 arithmetic and finalize_order/1 loop became Charge and SettleOrder:

def call(%Charge{gateway: gateway, metadata: metadata}, {[first | _] = line_items, cart_id}) do
  amount = line_items |> Enum.map(&(&1.unit_amount * &1.quantity)) |> Enum.sum()
  gateway.charge(amount, first.currency, metadata.(cart_id))
end

Facts, not instructions (R9). Features announce what happened (removed, captured, checkout_requested, ready_to_pay, done); the clauses decide what each fact does on this page.

Words from the page, values from features (R3, R5). Every label lives in the page’s @texts, merged with the store’s shared words; the gift-wrap label is built from the configured fee, not restated.

Generic placement (R11). tabs, pane, only_on, none, stream_list, the row components, cart_summary, shipping_selector, promo_form, primary_button. The application templates compare nothing and iterate nothing:

<.stream_list :let={{dom_id, row}} id="cart_items" stream={@streams.cart_items}>
  <.cart_item_row id={dom_id} row={row} wishlist_ids={@wishlist_ids} t={@texts.cart.row} ... />
</.stream_list>

Product pages (R11). stock_indicator with the configured rule, AddLine.run/2 with its cart configured, Products.delete_by_id/1, and a map lookup for the form’s saved message.

The coverage test (R8). It reads clause heads, so it needs no running page:

Macro.prewalk(Code.string_to_quoted!(File.read!(source)), [], fn
  {:defp, _, [{:land, _, [_, key, {port, _}]} | _]} = node, acc -> {node, [{key, port} | acc]}
  node, acc -> {node, acc}
end)

What it scores

V38 (built out)V38-max
Full checklist, by hand85100
ala_lint default / --strict / --super-strict (2026-10-01 linter)96 / 95 / 51100 / 100 / 99
R11 findings (--super-strict)820
Share of application functions holding logic (:r11_share)39% (25 of 64)0% (0 of 60)
Tests (same acceptance tests)111116
Lines in lib/3,6704,827
Cart page / portal page854 / 388 lines481 / 305 lines
Familiarity5 of 54 of 5

V38-max is larger than V38 in total: logic that sat in two page modules now sits in nine features, a dozen domain rules and the generic components. Its pages are smaller. Next to the other max variants it’s the same size (V39-max 4,772 lines, V41-max 4,955), so the wiring form isn’t what drives size.

The remaining linter reports are informational: the shared cart aggregate (read through its functions), wide public surfaces on the cart modules, the application layer at 22% of functions (a clause per wire), and the product index’s form component relaying through the page (one hop, as in every variant’s generated product pages).

Rescored 2026-10-02: 99

Two of Spray’s statements are now read strictly, and every published variant was rescored.

100 becomes 98.5, which rounds to 99. The lint score stays 100: the linter now reports the FormComponent as subcomponent under --strict, but one finding in a codebase of about 5,000 lines rounds away. Both fixes, a generic record form the page configures and wires, and a layer named for what it holds, are in V46 and V47, which score 100 under these readings.

Rescored 2026-10-03: 97

Spray’s §6.17.2 is now read strictly under R10. Checkout receives the whole cart (%Cart{}) to use three facts of it; the checklist already named that as missing R10, and every walk had passed it (−1). And the storefront’s cart, which carries promo, gift-wrap and shipping state, is the struct the portal’s order lines are built on: one use case’s data in a struct another use case shares, which Spray says an identity “should not be used as the carrier of” (−1). 98.5 becomes 96.5, which rounds to 97. Lint under --strict is 99, meeting 8 of 10 rules: the linter now scores the shared aggregate from --strict up.

Did it stay V38?

No, and it couldn’t. V38’s point was a conventional page that kept its logic, and a page at 100 keeps none. What survives is the part of V38’s approach worth keeping: take the most familiar option that conforms. Of the three max variants, this one adds the least. It needs no binding vocabulary, no protocol and no components, just a small runner and the idea that a private function clause can be a wire.

One caution remains. The coverage check runs in tests, not at compile time, so a missing clause is caught when the suite runs, not when the code compiles.

How it compares

V38-max and V39-max share an architecture: features as values in the page’s assigns, and zero message hops. They now share the same features too. What separates them is only how the wiring is written: plain clauses here, a data map with fourteen kinds there. V41-max differs most, with state in components and one hop per cross-feature effect. The V39-max post has the side-by-side table. No two of the three are duplicates, but V38-max and V39-max are now a controlled comparison of one variable.

The code is in ala_variants_elixir/v38-max.

← all posts