V01 in Rails, wired screens: Spray's object wiring, one composition per request

October 5, 2026 · ALA · V01 · Ruby · Rails · Hotwire

The Elixir variants took a LiveView storefront from a conventional app to designs that score 100 on the checklist. This is the first Ruby one: the same requirements, a catalogue with live validation, a cart with undo and saved items and a wishlist, an asynchronous checkout, and a bulk-order portal, built as a Rails 8.1 app with Hotwire against the Ruby edition of the checklist. The brief was to prefer the choice a Rails team already knows unless a less familiar one served the design better.

Two things make Rails different from LiveView for ALA. There is no long-lived process per page, so a composition can’t be built once and kept; and the natural wiring form is Spray’s own, objects with ports, because Ruby has classes and the checklist’s Foundation gives them ports.

A screen is a composition, built per request

Each page has a class under Screens::. Its constructor creates the page’s domain instances, configures them from Screens::Store (the calibration: rates, codes, tiers, words), and wires them. Nothing has run yet. The controller then pushes one input and either redirects with what the screen said or renders what landed:

class CartItemsController < ApplicationController
  def destroy
    screen.input_port(:remove).push(params[:id].to_i)
    back_to_cart
  end
end
module Screens
  class Cart
    include Foundation::Ports
    include DomainAbstractions

    input(:remove, ProgrammingParadigms::DataFlow) { |item_id| @lines.input_port(:remove).push(item_id) }

    def initialize(cart_id:)
      @lines = CartLines.new(lines: CartItem, cart_id:, stock_rule: StockStatus.new(low_at: Store::LOW_STOCK_AT))
      @undo = Undo.new(lines: CartItem, cart_id:, window: Store::UNDO_WINDOW)
      @totals = CartTotals.new(shipping:, gift_wrap: CalculateGiftWrapCost.new(unit: Store::GIFT_WRAP_CENTS))

      @lines.on(:rows) { @rows = _1 }
      @lines.wire_to(@totals, from: :contents, to: :contents)
      @lines.wire_to(@undo, from: :removed, to: :capture)
      @undo.on(:restored) { say :notice, "Item restored" }
      @totals.on(:summary) { @summary = _1 }
    end
  end
end

Because the composition is rebuilt per request, every instance that holds state keeps it in a store it is configured with: CartLines on the cart_items table, Undo on the same table’s removed_at column, CheckoutFlow on a checkouts table that holds the step. Puma serves requests on threads and no instance outlives one, which is Spray’s one-thread-per-stateful-instance (§3.9) for free.

Where LiveView’s process state went

In the Elixir variantsHere
gift-wrap marks in the cart’s statea column on cart_items
the undo offer and its timerremoved_at; a Stimulus countdown posts expire; the next load purges anything past the window
promo code, shipping method, checkout step, PO stepone small table per feature, keyed by cart id (R10)
the payment task and handle_asyncFoundation::PushLater, an Active Job wired as a port: it rebuilds the screen by name and pushes the charge input; a LiveUpdate sink replaces the status element, which carries a Stimulus visit to the success page
PubSub stock facts re-rendering each rowLiveUpdate broadcasts the stock badge to every element marked for that product
the active taba Stimulus controller; UI state only

Broadcasts are wired from screens, never from model callbacks. Screens::Catalog wires Records.saved to a LiveUpdate; Screens::Checkout wires SettleOrder.stock_changed to one. No after_commit anywhere.

The Rails choices, against the checklist

What the linter found

The 48 integration tests ported from the Elixir acceptance suites pass, and the pages were exercised by hand in a browser. Then the Ruby linter ran:

tierscorerules metfunctions clean
default66 (C)6 of 10192/204 (94%)
--strict615 of 10192/204
--super-strict53 (D)4 of 10182/204 (89%)

The density is low and concentrated: 18 of the scored findings are R1, in three kinds, and all three are real.

  1. Component partials rendering or calling peers. _cart_line renders components/product_line and stock_badge; four components call the LiveTargetsHelper that names DOM targets. In the declared map every component sits in the domain layer, so each is a cross-peer edge. The checklist’s answer is that the page places both; the honest alternative is to declare that a product line and a stock badge are more general than a cart line, which they are.
  2. Stateful abstractions calling pure rules. CartTotals and OrderTotals call Pricing; CheckoutFlow calls CheckStock. The design doc called these “rules one layer down”, but the layer map had one domain layer, so they are peers. The map didn’t say what the prose assumed.
  3. Foundation reaching up. LiveUpdate and PushLater build DataFlow ports, and LiveUpdate.component renders through ApplicationController. Execution models that use the paradigms belong beside them, not under them.

Then three R10 findings, belongs_to :product on every line table (the storefront’s lines read the catalogue’s columns through the association); two R5 names agreed between a screen and a component ("checkout_status", "modal"); and one R3 literal that is intrinsic. Under --super-strict, fifteen R11 findings: two branches inside wiring blocks, the session fallbacks’ ||, and loops and persisted? ternaries in page templates.

None of it was applied here. Each finding, with the options, is in LINT_NOTES.md, and V02 is the design that takes them.

The wiring, drawn from the built graph

The screens can draw themselves. Foundation::Ports records each wire as it is made, and ProgrammingParadigms::Drawing.mermaid(screen) walks the parts of a built screen, so the picture can’t drift from the code (R8’s technique). The cart:

flowchart LR
  screen[[Screens::Cart]]
  lines[lines: CartLines]
  undo[undo: Undo]
  saved[saved: SavedItems]
  wishlist[wishlist: Wishlist]
  pricing[pricing: PricingChoices]
  totals[totals: CartTotals]
  lines -- rows --> screen
  lines -- contents → contents --> totals
  lines -- removed → capture --> undo
  lines -- saved → stash --> saved
  lines -- saved --> screen
  lines -- line --> screen
  undo -- pending --> screen
  undo -- restored --> screen
  saved -- rows --> screen
  saved -- count --> screen
  saved -- moved → receive --> lines
  saved -- moved --> screen
  wishlist -- rows --> screen
  wishlist -- count --> screen
  wishlist -- ids --> screen
  wishlist -- added --> screen
  wishlist -- dropped --> screen
  wishlist -- taken → receive --> lines
  wishlist -- taken --> screen
  pricing -- discount → discount --> totals
  pricing -- shipping_method → shipping_method --> totals
  pricing -- promo_applied --> screen
  pricing -- promo_rejected --> screen
  totals -- summary --> screen

An edge to screen is an output the composition lands in a field or turns into a flash with on. rails ala:diagrams writes one of these per screen.

What it costs

The code is in ala_variants_ruby/v01-wired-screens.

← all posts