Feature Isolation in the UI Layer: Pages Compose, Features Stay Apart

A librarian asks for a small thing: the "My holds" list should show the same book card as the search results, with the cover, title and author. A developer sees the card already exists in the search feature, adds one import, and ships it before lunch. That single line is how front ends slowly stop being changeable.

Why the harmless import isn't

Follow the dependency forward. The holds feature now depends on the internals of search. Next quarter, search is redesigned and the card gains a "borrow" button and a rating widget. Holds changes appearance without anyone asking for it, and its tests start failing for reasons unrelated to holds.

Worse, features tend to want each other in both directions. Search results need a "place hold" action, which lives in holds. Add that import and the two features form a cycle, so neither can be moved, rewritten or deleted alone. The book's rule for the UI is blunt: no feature imports another feature. Each one is a unit that the rest of the application sees only through a small public surface.

Two ways out, and a third worth admitting

If features cannot reach sideways, shared needs have to go somewhere else. The book gives two destinations: push the shared piece down into the UI's shared folders, or let the page that shows both features do the joining. A third option, from ordinary front-end experience rather than from the book, is to tolerate a little duplication when the two uses are likely to diverge.

  1. Push it down. If the book card has no knowledge of holds or search, only a book's title and author passed in as props, it is a shared presentational component. Both features use it, and neither knows about the other.
  2. Let the page wire it. When one feature needs something that belongs to another, the page can hand it over. The search feature exposes a slot, and the page fills it:
// pages/BrowsePage.tsx: the only file that knows both features exist
import { SearchResults } from "../features/search";
import { PlaceHoldButton } from "../features/holds";

export const BrowsePage = () => (
  <SearchResults
    renderAction={(book) => <PlaceHoldButton bookId={book.id} />}
  />
);

Search never learns that holds exist. It only knows it has an empty slot per result. The page is the one place permitted to see both, which is exactly what a page is for: it describes which features appear together on a screen.

Promote late, not early

The shared folder tempts people into promoting components too soon. The book's guidance is that a component begins inside the feature that needs it and moves to the shared area only when a second feature wants it and the component can shed its domain knowledge. I would add a diagnostic from experience: if a "shared" card has a prop called holdStatus, it was never shared, only borrowed.

Early promotion has a cost that is easy to miss. A component with one real caller, sitting in a shared folder, invites other teams to depend on it. Its API then freezes around one feature's needs while looking like a general-purpose building block.

Make the rule mechanical

Rules about folders decay unless something checks them. The cheapest fence is a public entry file per feature, so that anything importing from inside a feature's folder is easy to flag. Most linters can then be told to reject cross-feature paths, and the book's lvd-lint checks the UI layer's rules from folder paths alone.

That matters for adoption. A rule enforced by review depends on whoever is tired that day. A rule enforced by the build never has an off day, and it turns the awkward "can I just import this?" conversation into an automatic answer with a suggested alternative.

The takeaway

Out of everything one could say about organising a UI, keeping features apart pays back the fastest. Features stay independent, pages do the joining, and shared components are promoted only when they have earned it. For the layer's place in the model, start with why the UI is its own layer, and see UI layer violations for what happens when the fence is missing.

What the book covers

  • The standard folder organisation of the UI layer and the volatility each folder tracks
  • The three kinds of import Axiom A6 allows from outside the UI, and the ones it forbids
  • What the browser-shipping consequence means for Schema and Utils
  • The remaining in-layer import rules and the direction imports flow
  • How lvd-lint checks the UI's rules from folder paths alone