V39, bound ports: the page is one map

September 29, 2026 · ALA · V39 · LiveView · R9

V39 is the first variant built to the revised ALA Checklist rather than to an architecture I had in mind first. The checklist’s R9 says an output must never name its destination and should read as a result, not an operation. R3 says the product’s numbers and words live at the top. R11 says the top layer only wires. V39 takes those three literally and asks how little machinery is needed to hold them.

The answer turned out to be one map per page and a hundred-line reducer.

A feature is a function that announces

Every feature in V39 has the same signature: step(state, payload) :: {state, [{port, payload}]}. The cart, the undo window, saved items, the wishlist, checkout, the portal’s order lines and its PO form: nine modules, none of which imports Phoenix.

def remove(%Cart{} = cart, %{item_id: item_id}) do
  case Cart.remove_item(cart, item_id) do
    {:ok, cart, item} ->
      {cart, [rows: {:removed, row(cart, item)}, removed: item, summary: summary(cart)]}
    :error ->
      {cart, []}
  end
end

The feature says what happened: a row left, a summary changed, an item was removed. It does not say “delete from the stream”, “flash this text” or “tell the undo feature”. It has no idea those exist. That is R9’s must and should in one line.

The page is a map

Each page has a bindings/1 function that maps {feature, port} to where that port lands on this page:

{:cart, :rows}       => [{:stream, :cart_items}],
{:cart, :summary}    => [{:assign, :summary}],
{:cart, :persist}    => [{:call, &Carts.apply_change/1}],
{:cart, :removed}    => [{:input, :undo, &Undo.capture/2}],
{:undo, :timer}      => [{:timer, :undo, @undo_window_ms}],
{:undo, :restored}   => [{:input, :cart, &Cart.receive/2}, {:flash, :info, "Item restored"}],
{:checkout, :step}   => [{:assign, :step}, {:patch, @step_paths}],
{:checkout, :payment}=> [{:async, :payment, &charge/1}],
{:checkout, :done}   => [{:via, &finalize(cart_id, &1), [:redirect]}]

A stream, an assign, a flash, another feature’s input, a timer, a URL patch, an async job, a redirect, or a function of the page’s own. Thirteen binding kinds cover both pages, and the list did not grow when the second page was built. Every message the shopper sees, every price and every window is an attribute of the page module, next to the map. Reading bindings/1 and the attributes above it tells you what the store does.

The handlers are one line each and only route:

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

Binder.run/4, in a paradigms layer below the page, runs the step and delivers each output along the map. It knows LiveView and the binding kinds. It knows nothing about carts.

Where features need each other

The wishlist toggle needs the cart line; paying needs the cart and fresh stock. V39 composes these in the handler, in one expression: Wishlist.toggle(&1, Cart.find(socket.assigns.cart, id)). The checklist’s R10 allows the composition to pass values in, and the linter’s handles-data check accepts it because the value goes straight into one feature input. It is still the page reading one feature’s state to feed another, and V40 shows the alternative.

What the linter said

ala_lint scores V39 at 97 by default, 97 under --strict, and 95 under --super-strict, against V35’s 93, 93 and 91 on the same layer map (all re-scored 2026-09-30). The super-strict score dropped a point that day, when R11 learned to see for loops and nested hand-offs. It now reports four findings, all in the page: the order-placement loop and a line lookup in two private helpers (shared with V40), the portal’s ensure_line/2, and the toggle_wishlist handler passing Cart.find(...) straight into the wishlist. The gain is entirely R3 and R5: message text and calibration left the features for the page, and the Contracts registry V35 needed is gone. The linter also caught two mistakes while I was scoring: a checkout function that called the cart feature instead of the domain aggregate (a peer edge), and a portal function doing arithmetic on the page. Both were real, both were ten-minute fixes, and I would not have seen either by reading.

Re-scored 2026-10-01, after the linter learned to read templates and the words below a page, with a layer map that covers every module: 95 by default, 94 under --strict, 82 under --super-strict. Most of the 35 R11 findings are in the view modules’ markup: tab comparisons, :if on a count, Money.zero? choosing the word “Free”, and :for loops over streams. That’s the same logic the full walk’s rescore found by hand. The linter also now reports the four closures over page helpers in the bindings, as R8 prompts.

What remains is small and honest: the shipping table repeats in both pages, the low-stock threshold lives inside a domain rule, and the product pages are V35’s untouched.

What a generator would add

An earlier toy generated wiring from a map like this one and checked it in CI. I left that out of V39 on purpose, because the Binder already runs the map directly; a generator would add a check, not the wiring. The check matters, though. Nothing in V39 verifies that every port a feature emits has a binding: an unbound or misspelled port is silently dropped. A ports-coverage test would close that without a generator, and it is the first thing I would add before letting V39 grow.

The full checklist, by hand

Walked through every rule of the ALA Checklist with an explicit deduction per finding (the method from the V42 post), V39 scores 88. The rules V39 was built for hold: no output names its destination, and no peer calls another. The points go on what the linter can’t fully see. Page helpers do store work: finalize/2 places the order, loops over the lines and takes stock, and add_line/2 writes then looks up (−2). The page makes the payment call (−1), and composes inputs in handlers: pay fetches stock levels itself (−1). An output with no binding is dropped silently (−1), and four closures in the bindings hide what they do (−1). Per-call configuration of the domain rules costs half a point (a “should”). On top of that come the findings every variant in this family shares: a baked low-stock threshold, the rate table written twice, the shared cart aggregate, and a few smaller items (−6). Zero message hops is V39’s advantage: the binder runs every step in the page process.

Rescored 2026-10-01: 82. Walking the max variants turned up findings this walk missed. The line-item builder writes the currency "usd" in the domain (R3, −1). Words sit below the composition across many modules: the Cart feature builds “free over $50.00”, the checkout and PO schemas carry their validation messages, and the row components hold every row label (R3, structural, −2). The view says “Gift wrap ($2.99)” while the page configures the fee as 299, a contract between two modules nothing checks (R5, −1). And the view modules decide things beyond the tab comparison already counted: :if={@saved_count == 0}, Money.zero? choosing the word “Free”, comparisons on the selected shipping method, plus a case on stock status and live_action comparisons in the product pages (R11, structural, −1.5 more). That’s −5.5: 87.5 becomes 82. V39-max fixes all of them.

Rescored 2026-10-02: 81. Two of Spray’s statements are now read strictly. A page-specific LiveComponent is a contained sub-component. Spray has “no analog of a sub-module or sub-component, no such thing as a sub-abstraction” (§2.2), and his provision for page-specific UI is layout and bindings built from domain UI abstractions (§7.14). V39 still has the generated FormComponent (R11, −1). And Spray’s features are compositions: “Each feature creates instances of domain abstractions, configures the instances with feature specific details, and connects them together” (§2.2). The modules this variant calls Features are coded state and rules, which he would call stateful domain abstractions, so the name misleads a reader who knows his vocabulary (R8 “should”, −0.5). 82 becomes 80.5, which rounds to 81. Lint is unchanged at 94 under --strict.

Rescored 2026-10-03: 79. 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). 80.5 becomes 78.5, which rounds to 79. Lint under --strict is 93, meeting 5 of 10 rules: the linter now scores the shared aggregate from --strict up.

The code is in ala_variants_elixir/v39-bound-ports.

V39-max is V39 changed until the full walk finds nothing to deduct, at 100.

← all posts