How close can a Ruby on Rails app come to ideal ALA?

October 5, 2026 · ALA · Rails · Ruby · R11 · departures

The LiveView version of this question ended with six designs at 100 on the hand walk. Rails is a different kind of framework, and Ruby a different kind of language, so the question gets asked again: for each thing a Rails app does that Spray’s application wouldn’t, is it forced by Rails, forced by Ruby, or a habit? Two designs answer it, V01 and V02, and the second meets every rule the Ruby linter checks at --super-strict.

What Spray asks

The same as before: the application instantiates, configures and wires, holds all the product’s knowledge and none of its logic, “no normal programming language code such as assignments and if statements” (§3.5). For an OO language he adds what the Ruby checklist gathers: classes have a main interface for the layer above and ports for everything else; peers have no associations, “not even its interface. Not even a base class” (§2.1.3); wiring is explicit, never a container’s; configuration and wiring are “immutable after they are set” (§3.9); one thread per stateful instance. His own form is an object graph built once at start-up and then set running (§3.11.3).

What Rails hands the controller

A Rails app is called per request. It gets a controller action named by a route, params as strings, a session, a flash, and a response to render or redirect; then the request ends and everything it built is gone. Turbo hands it a second channel back to open pages, streams it broadcasts on. Active Job hands it a way to do work after the response.

Some of this is Spray’s model under other names. A controller action that pushes one input is a wire from an event to a port. A button_to is an event named by a URL. The template’s nesting is the “display inside” wiring. Other parts are foreign: a composition that can’t outlive a request, a session the framework owns, a form whose method the framework chooses, and an object model where every reference is mutable.

Rails’ pieces as abstractions

PieceWhat it isWhat it may do
a controller actionapplication: a wiredecode params, push one input of a composition, render or redirect
a screen class (Screens::Cart)applicationinstantiate, configure, wire, hold the words; built per request
a page templateapplication: UI-layout wiringplace components, pass values in; no loop, comparison, or model call
a partial that takes projected rowsUI domain abstractionrender what it’s given, name the URLs it’s given
a model (ApplicationRecord)persistence for one feature, or the shared identityreached as a configured store; owned by one feature
a validationan intrinsic constraintmessages from the composition or I18n keys it owns
a Turbo Stream broadcasta sink the composition wiresthe composition owns the stream names; since 2026-10-21 a change made elsewhere travels as a fact instead (see “Changes made elsewhere”)
an Active Joban asynchronous execution modeldeliver a push to an input the composition named
a Stimulus controllerUI state onlynever a product rule
a service object, a concern on a model, a DI containernot used—

The departures, one at a time

Forced by Rails, and valid

The composition is rebuilt per request. Spray wires once at start-up. Rails can’t, so each screen’s constructor runs per request, and every stateful instance keeps its state in a store it is configured with (the lines in cart_items, the undo offer in a removed_at column, the checkout step in its own table). The screen never looks inside what it stores. The dividend is that Puma’s threads never share an instance, which is Spray’s one-thread rule (§3.9) for free. The cost is that a job that finishes later has to rebuild the screen by name to deliver its result; PushLater does exactly that, and it is the one piece that reads as a trick.

Routing an outcome to a response. if screen.saved then redirect_to ... else render :form_again is a branch in the application. Its arms only redirect, render, or hand the page a value, which is R11’s own exemption for routing two outputs. A stricter reader would give Records two outputs and the controller two one-line actions; I left it, and the linter reads it as routing.

Decoding params. params[:id].to_i adapts the browser’s strings. Small, and at the edge. params.expect(...) does the rest.

The session as the identity’s home. The cart id lives in the session because Rails has nowhere else per browser. Reading it is the framework’s; the fallback for a flow that outlives its cart (session.fetch(:cart_id) { cart_id }) is the one place the guard moved into the connection rather than out of the code.

Forms, CSRF and HTTP methods. form_with model: picks the URL and the method from the record, which is the convention that removed a persisted? ternary from a page. It also sends _method=patch for a persisted record, which broke a POST-only validate route and a POST-only submit route until the browser tests found both. The live-validation fetch now drops _method and sends the page’s CSRF token, because Rails 8’s per-form tokens are bound to the form’s own action.

Framework base classes. ApplicationController, ApplicationRecord, ApplicationJob: subclassing a framework class to configure it is R9’s allowed form, and the linter exempts it. Subclassing your own class isn’t.

Forced by Ruby, and handled

No interfaces, no field types. Spray’s port is a field typed by a paradigm interface. Ruby has neither, so the Foundation declares ports with macros: output is a private instance variable the wiring fills, input a handler that stays private. It is the one vocabulary a Rails team hasn’t met, and it is ninety lines. The consequence a Rubyist meets first: an output port is the instance variable of its name, so a class can’t keep state under that name too.

Duck typing hides the knowledge, not the coupling. A class that sends a peer’s own messages to whatever it was given is written to that peer’s design whether or not anything declares it (§3.3.1). The rule became “send only a paradigm’s messages”, and the tell is respond_to?(:charge) on a collaborator. The linter flags that form; it can’t see a plain gateway.charge(...), which is the honest limit the checklist states for a dynamically typed language.

Mutable references. This is where Elixir had it for free. A value handed to two peers in Ruby can become a back channel; a getter can hand out a live collection for a peer to change. The variants put hashes built per call and frozen Money values on wires, keep configuration in constructor arguments that are never reassigned, and build the hardware command of the coffee maker with Data#with. The remaining live objects on wires are Active Record records that Records and the flows emit on form and created, which only the composition lands for the view. A clean R2 in Ruby is a design achievement; in Elixir it was the language.

One constant per file. Zeitwerk wants it, and so does Spray (“one abstraction per file”, §2.3.2). The one friction is that app/ala/ as an autoload root gives the layers their namespaces for free, and Rails.application makes Application an unusable layer name, so the compositions are Screens::.

Not forced: habits the second design removed

Each of these was a finding on V01 and a change in V02.

An association between features’ tables. belongs_to :product on every line table let the storefront’s lines read the catalogue’s columns, Spray’s shared entity (§6.17.2). V02 holds product ids and asks a products pull port, wired by the screen to one ProductIndex. One more query per page; the join was the coupling.

Broadcasts from model callbacks. after_commit { broadcast... } is a lower record deciding what happens next. Both designs wire broadcasts from screens; the linter flags a callback that reaches another unit as R1.

A helper as the agreed names. V01 kept the DOM ids live updates target in a helper both components and screens called, a peer edge from every component. V02 makes it Foundation::DomTargets, declared with helper, so both depend down.

Components rendering components. A cart line that renders a product line and a stock badge is a UI abstraction naming peers. V02 declares a views/elements/ tier of generic elements under views/components/, and no component renders a component.

Loops, comparisons and ternaries in pages. @s.rows.each, wishlist_ids.include?, form.persisted? ? ... : .... V02 renders collections, lets rows carry their URLs from a lambda the screen configures with the route helpers, and lets the cart line take the wishlist’s ids. The form’s URL comes from form_with model:.

One domain layer for everything. Totals calling pricing, a flow calling a stock check, looked like peers because the map said so. V02 declares a rules layer under the domain for the pure rules and projections. A map with one domain layer reports the same code as fifteen peer edges; the honesty is in what the layer holds: nothing in rules/ reads a store or a word.

Stateful abstractions holding what the page needs to decide. Records emits created and updated instead of saved so the screen wires two notices and two live updates with no branch; SubmitOrder emits its step after a failed submit so the controller’s failure arm only renders.

What the two designs show

V01V02
ala_lint default / --strict / --super-strict66 / 61 / 53100 / 100 / 100
Rules met under --super-strict (of 10 checked)410
Scored findings at --super-strict450
Functions with no scored finding182 / 204208 / 208
Tests (integration + browser)50 + 050 + 5
Familiarity44

The two measures the linter reports and never scores stay where they are: the composition’s share of functions (42%: controllers and templates count, and a request-per-action framework has many) and the average unit size (18 lines: one-port classes are small). Spray’s 3 to 10% was measured on wiring code; a Rails app’s “application” includes every action and every page.

How far a Rails app actually gets

Further than I expected, and for a reason different from LiveView’s. LiveView’s departures were about the page: events by name, two mounts, a URL that changes. Rails’ departures are about the request ending and the language’s objects. The first is solved by the same move every time, a store configured into the instance that needs it, and the move was already Spray’s: persistence is “an abstraction of persistence”, not a port to an adapter (§6.19). The second is solved by discipline the linter can only partly check.

What holds V02’s score up is five declarations the tool can’t judge: the rules and elements layers, peer_ok on the paradigms layer, the session fallback, the routing arms, and cart_items shared by the storefront and the portal as the lines abstraction both build on. The design records each. None is a trick, and any could be argued the other way by a reader who draws the map differently.

What it costs

What it costs at run time

Rails rebuilds the screen on every request, so the first question is what the composition itself costs: a few dozen allocations, O(parts + wires), before any query. It doesn’t register. The queries do, and ALA puts them in one visible place each:

The coffee maker shows the other shape: polled execution senses three abstractions every cycle (right for a controller), and Boiler#drive first emitted its heater command on every push of any input, so a cycle where state and pot both changed emitted it three times (harmless, since the last landing won). It now emits only when the output changes, as Not and Equals always did, and a test counts one command per change: the output-change guard is the connection’s guard, in Spray’s sense, written once in the instance that owns the output. The checklist’s “Kinds of connection” section now records these as the run-time properties a wiring makes checkable.

Changes made elsewhere

Added 2026-10-21. Rails’ own answer to showing a change made elsewhere is Turbo Streams from the model. broadcasts_to (or an after_update_commit that calls broadcast_replace_to) re-renders the record’s partial when it commits and pushes the HTML to every page that opened the stream with turbo_stream_from. It is very little code, and it is the coupling ALA forbids: the model decides which views hear about it and renders them, so a lower record knows every view (R1, R10). V01 and V02 moved the broadcasts out of the models into screens (LiveUpdate, wired like any sink). That fixed the direction but not the knowledge. The screen that made a change still rendered another page’s row and aimed it at a DOM id.

By V05 to V07 that had produced two bugs, found in all three. A staff stock edit at /products never reached an open cart, because nothing broadcast to the cart’s markup. And the portal’s catalogue row shared the /products row’s DOM id, so a staff edit replaced it with the staff row, Edit and Delete buttons included. A change-cost experiment run the same day, ten requirement changes made in sequence to a conventional Rails app and to V07, found the same thing from the other side: the steps that added live updates were ALA’s most expensive and held most of its confirmed defects, because a state-holding page had to build new machinery each time, while the conventional app reused broadcasts it already had.

ProgrammingParadigms::ChangeFeed makes outside change a paradigm, built once in the layer Spray keeps for paradigm interfaces (§2.2), with the observer inside the paradigm, where “the subscriber does not know the publisher” (§4.4.2). It is a Publish sink the changing screen wires, a Subscription part a page places with the topic and the kinds of fact it listens to, one channel, and one Stimulus controller:

# V07's catalogue: a staff save publishes the product's stock
@publish_stock = ProgrammingParadigms::ChangeFeed::Publish.new(topic: Store::CATALOG_TOPIC, kind: :stock, fields: ->(product) { { product_id: product.id, stock: product.stock } })

# V07's cart: a feed of that kind, and the arm that patches its badges
@feed = ProgrammingParadigms::ChangeFeed::Subscription.new(topic: Store::CATALOG_TOPIC, kinds: %i[stock], url: urls.live_cart_path)
in [ :feed, :stock ] then @patches.replace_all(@dom.stock_selector(payload[:product_id]), @badge_html.(payload))

What travels is a fact keyed by identity ({ product_id:, stock: }), never HTML. The topic is the one name both sides share, the way two sides agree on a global event name (§4.7.4), so it is declared once and handed to both compositions as configuration.

How it relates to the two Rails pieces it touches:

The cost is real. Every fact is a request per open page (V05, V07) or a whole-page GET (V06), where broadcasts_to sent one push of HTML that the browser applied. In return no model and no screen knows another page’s markup, and a new kind of outside change is a publish sink and a wire. The V05, V06 and V07 posts each have how it is wired there. The LiveView variants have the same paradigm over Phoenix.PubSub, and the LiveView post explains why it isn’t LiveView either.

What hasn’t been tried

Spray’s Features layer in Rails (V02’s screens are under 90 lines, so none has outgrown one abstraction); ViewComponent as the UI abstraction instead of partials; a contract check between templates’ data-action names and Stimulus controllers; a multi-page composition where two screens share a part; Turbo Stream responses instead of morph refresh for a shopper’s own changes; a real payment gateway with a webhook; and authentication, where before_action is the obvious place for a rule R11 says shouldn’t be there.

The code is in ala_variants_ruby.

← all posts