V39-max: bound ports at 100
This is the second of three “max” posts, after V41-max and before V38-max. Each takes a design and changes it, in a copy, until a hand walk of the ALA Checklist finds nothing left to deduct.
V39 keeps each feature as a plain {state, outputs} function whose state lives in the page’s assigns, and puts each page’s whole design in one map, bindings/1, from a feature’s port to where it lands. A 111-line binder runs it. Every click is handled inside the page process, with no message hops at all. It scored 88 on the full walk as first published, and 82 after a rescore that added findings the first walk missed (words and a currency code below the page, logic in its views). The biggest losses were in one place: store work and composition in page helpers and handlers.
Store work behind a port
V39’s page had five helpers that did real work. finalize/2 placed the order, looped over the lines, took the stock and broadcast each new level. charge/1 built return URLs and called the payment gateway. add_line/2 and ensure_line/2 stored a line and looked it up again. Each was bound as a closure, &add_line(cart_id, &1), so the bindings map couldn’t say what those bindings did.
V39-max moves each into a domain abstraction configured once: AddLine, PlaceOrder, and a new StartPayment. To let the binder call them without a closure, they implement a small protocol, ZeroCoupled.Ports.Call. The protocol lives in the bottom layer and no domain module owns it. Spray calls “classes may not own any interface except the ‘main interface’” “critically important” (§2.3.4); a protocol that belongs to the paradigm, not to any one caller, is the Elixir form of that. The binding now names the instance:
{:wishlist, :taken} => [
{:via, %AddLine{carts: Carts, products: Products, cart_id: cart_id},
[{:input, :cart, &Cart.receive/2}, {:flash, :info, "Added to cart"}]}
],
{:checkout, :ready_to_pay} => [{:async, :payment, %StartPayment{gateway: ..., urls: ..., cart_key: ...}}],
{:checkout, :done} => [{:call, %PlaceOrder{orders: Orders, carts: Carts, products: Products, ...}}, :redirect]
No handler composes an input
Three V39 handlers built an input from what they could see. pay read the cart from assigns and fetched stock levels itself. toggle_wishlist found the cart line and handed it to the wishlist. start_checkout passed the page’s copy of the summary into checkout. Each is the application handling data between two abstractions, which R11 forbids.
In V39-max each of those is one feature input whose output the map binds onward. pay runs Cart.request_checkout/2; its checkout_requested output carries the cart, bound to Checkout.pay/2, which asks the stock source it was configured with. toggle_wishlist runs Cart.line/2, bound to Wishlist.toggle/2. Every handler is now one line that runs one input.
Mount had the same problem in a quieter form: it read the store and passed the lines into the cart. Now mount is an event on the diagram:
{:page, :mounted} => [
{:via, &Carts.list_items/1, [{:input, :cart, &Cart.load/2}]},
{:input, :checkout, &Checkout.show_form/2}
]
and mount/3 ends with Binder.deliver(socket, bindings, :page, mounted: cart_id).
Nothing dropped silently
V39’s binder drops an output that has no binding, so a typo in a port name loses data without a sound. V39-max keeps the drop, because it’s how a page ignores what it doesn’t need, but each page now says which ports it drops on purpose (grounded/0) and which feature each key names (features/0). A test checks both directions: every declared output is bound or grounded, and every binding names a port its feature declares.
Views only place
V39’s view modules still decided things. They compared the active tab, hid a list when a count was zero, and wrote “Free” when shipping cost nothing. Those decisions now sit in generic components (pane, tabs, none, cart_summary, shipping_selector, notice, primary_button) that take their words from the page. The views are placement and nothing else. The same fixes V41-max needed are here too: configuration built once, store-wide words and rates in one module, and every label and validation message supplied by the page.
A regression, caught
One existing test began failing about half the time: “a failed payment offers a retry”. It clicked Pay and read the page straight away, before the payment task had reported back. The original V39 happened to win that race every time I ran it; V39-max lost it often enough to see. The test now waits with LiveView’s render_async/1 and has passed every run since. The code didn’t have a bug, but the test had been relying on timing all along.
Techniques, with code
Each technique below is described under its rule in the ALA Checklist and the field guide.
Every word from the page (R3). The views render @texts, built once in the page from its own map and the store’s shared words:
<.cart_item_row row={row} wishlist_ids={@wishlist_ids} t={@texts.cart.row} ... />
<.notice shown={@undo_pending} text={@texts.undo.text} action={@texts.undo.undo} event="undo_remove" />
Form messages, values not words, store-wide literals (R3). As in V41-max: Checkout.new(..., messages: %{postal_code: "must be 4–10 digits"}), shipping options projected as money, and StoreConfig/CartSession for the shared literals and keys.
A label derived from its value (R5).
put_in(texts, [:cart, :gift_wrap_label], "Gift wrap (#{Money.new(@gift_wrap_unit)})")
Configuration once (R9). The instances the bindings name are built once, with their configuration:
%AddLine{carts: Carts, products: Products, cart_id: cart_id}
%PlaceOrder{orders: Orders, carts: Carts, products: Products, announce: &Broadcast.stock_changed/2, cart_id: cart_id}
Checkout.new(flow: @checkout_flow, stock_levels: &Products.stock_levels/1,
line_items: BuildLineItems.new(currency: StoreConfig.currency()), messages: ...)
The Call port (R9). The protocol, and one implementation:
defprotocol ZeroCoupled.Ports.Call do
def call(instance, payload)
end
defimpl ZeroCoupled.Ports.Call, for: ZeroCoupled.Domain.AddLine do
def call(a, {product, quantity}), do: {AddLine.run(a, a.cart_id, product), quantity}
def call(a, product), do: AddLine.run(a, a.cart_id, product)
end
The binder asks a callee the same way whether it’s a function or an instance:
defp ask(fun, payload) when is_function(fun, 1), do: fun.(payload)
defp ask(fun, _payload) when is_function(fun, 0), do: fun.()
defp ask(instance, payload), do: Call.call(instance, payload)
Facts drive the clock (R9). Undo announces captured and restored; the bindings start and stop its timer:
{:undo, :captured} => [{:set, :undo_pending, true}, {:start_timer, :undo, StoreConfig.undo_window_ms()}],
{:undo, :restored} => [{:stop_timer, :undo}, {:input, :cart, &Cart.receive/2}, {:flash, :info, "Item restored"}]
A composed input becomes an output (R11).
def handle_event("pay", _params, socket), do: {:noreply, run(socket, :cart, &Cart.request_checkout(&1, nil))}
def request_checkout(%Cart{} = cart, _), do: {cart, [checkout_requested: cart]} # in Features.Cart
{:cart, :checkout_requested} => [{:input, :checkout, &Checkout.pay/2}] # in bindings/1
Generic parts in the views (R11). The comparisons V39’s views made now sit in components:
<.pane current={@active_tab} name={:saved}>...<.none count={@saved_count} text={@texts.saved.empty} /></.pane>
<.cart_summary summary={@summary} t={@texts.cart} /> <%!-- decides "Free", the discount row --%>
<.primary_button event="start_checkout" disabled={@summary.empty?}>...</.primary_button>
The row component decides the wishlist mark itself (row.product_id in wishlist_ids), and the product pages use stock_indicator and Products.delete_by_id/1 as in V41-max.
Bound or grounded, tested (R8).
for {key, feature} <- page.features(), port <- Keyword.keys(feature.ports().out) do
assert {key, port} in Map.keys(page.bindings(1)) ++ page.grounded()
end
What it scores
| V39 | V39-max | |
|---|---|---|
| Full checklist, by hand | 82 (first published as 88) | 100 |
ala_lint default / --strict / --super-strict (2026-10-01 linter) | 95 / 95 / 82 | 100 / 100 / 99 |
| Tests | 83 | 89 |
Lines in lib/ | 4,188 | 4,750 |
| Binder | 111 lines, 13 kinds | 121 lines, 14 kinds |
| Familiarity | 4 of 5 | 3 of 5 |
Both lint rows use the same layer map. As with V41-max, the linter’s remaining reports are informational. The walk records judgement calls rather than deductions: the binder depends on the Call protocol in its own layer (a port type, more abstract than the runtime that uses it), and its fourteen binding kinds are a vocabulary, each a distinct placement, not helpers.
Rescored 2026-10-02: 99
Two of Spray’s statements are now read strictly, and every published variant was rescored.
- 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. Abstraction layers replace hierarchical containment” (§2.2). His provision for page-specific UI is layout and bindings built from domain UI abstractions: “Using one in a specific application only requires a label and a binding to an action” (§7.14). V39-max still has the
FormComponentthatphx.gen.livegenerated for the product pages, with its own state and save handler (R11, −1). - Spray’s features are compositions. “Each feature creates instances of domain abstractions, configures the instances with feature specific details, and connects them together as needed to express the feature or user story” (§2.2). V39-max’s
Featuresmodules are coded state and rules with ports, which he would call stateful domain abstractions. The edges don’t change, but the name misleads a reader who knows his vocabulary (R8 “should”, −0.5).
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.
The cart page, drawn from its bindings
Paradigms.Drawing.mermaid/1 draws a page from bindings/1, the same map the page runs, so the picture can’t drift from the wiring. A solid arrow is an input binding, labelled port → input, and names any configured instance a via asks on the way. A dotted arrow goes to the page effect a binding lands on.
flowchart LR
cart -.->|"changed"| call_apply_change["call apply_change"]
cart -->|"checkout_requested → pay"| checkout
cart -->|"checkout_started → start"| checkout
cart -->|"line → toggle"| wishlist
cart -.->|"promo_applied"| page_set["page: set"]
cart -.->|"promo_applied"| page_flash["page: flash"]
cart -.->|"promo_rejected"| page_set["page: set"]
cart -.->|"promo_rejected"| page_flash["page: flash"]
cart -->|"removed → capture"| undo
cart -.->|"rows"| page_stream["page: stream"]
cart -->|"saved → stash"| saved
cart -.->|"saved"| page_flash["page: flash"]
cart -.->|"summary"| page_assign["page: assign"]
checkout -.->|"address"| page_assign["page: assign"]
checkout -.->|"blocked"| page_flash_for["page: flash_for"]
checkout -.->|"done"| call_PlaceOrder["call PlaceOrder"]
checkout -.->|"done"| page_redirect["page: redirect"]
checkout -.->|"form"| page_form["page: form"]
checkout -.->|"ready_to_pay"| payment["task StartPayment"]
checkout -.->|"step"| page_assign["page: assign"]
checkout -.->|"step"| page_patch["page: patch"]
page -->|"mounted via list_items → load"| cart
page -->|"mounted → show_form"| checkout
saved -.->|"count"| page_assign["page: assign"]
saved -->|"moved → receive"| cart
saved -.->|"moved"| page_flash["page: flash"]
saved -.->|"rows"| page_stream["page: stream"]
ui -.->|"tab"| page_assign["page: assign"]
undo -.->|"captured"| page_set["page: set"]
undo -.->|"captured"| timer_undo["timer undo"]
undo -->|"expired → confirm_removal"| cart
undo -.->|"expired"| page_set["page: set"]
undo -.->|"restored: stop"| timer_undo["timer undo"]
undo -->|"restored → receive"| cart
undo -.->|"restored"| page_flash["page: flash"]
undo -.->|"restored"| page_set["page: set"]
wishlist -.->|"added"| page_flash["page: flash"]
wishlist -.->|"count"| page_assign["page: assign"]
wishlist -.->|"dropped"| page_flash["page: flash"]
wishlist -.->|"ids"| page_assign["page: assign"]
wishlist -.->|"rows"| page_stream["page: stream"]
wishlist -->|"taken via AddLine → receive"| cart
wishlist -.->|"taken via AddLine"| page_flash["page: flash"]
Did it stay V39?
Mostly. The idea is intact and stronger: each page’s design is one map, and now nothing the page does is outside it. What it lost is plainness. A reader now meets fourteen binding kinds, a protocol, a pseudo-feature called :page, and two declaration functions. That’s why familiarity drops a point, to 3.
The three max variants side by side
| V41-max | V39-max | V38-max | |
|---|---|---|---|
| Where a feature’s state lives | a LiveComponent per feature | the page’s assigns | the page’s assigns |
| How the wiring is written | a @routes map, 5 target kinds | a bindings/1 map, 14 binding kinds | wire/3 function clauses |
| Wiring runtime | 45 lines | 121 lines plus a protocol | 56 lines |
| Message hops per cross-feature effect | 1 | 0 | 0 |
| Coverage check | a test sends every announcement | a test over the map’s keys | a test over the clause heads |
| App | storefront and portal | storefront and portal | storefront and portal (GoodDeal foundation, V39-max’s features) |
No two are duplicates. V39-max shares its features and domain with V41-max almost file for file but puts state and wiring somewhere else. It shares its architecture with V38-max: features as values, zero hops. Those two differ on R8’s choice, a wiring value you can inspect and check by its keys against plain clauses you can only read.
The code is in ala_variants_elixir/v39-max.