For AI Agents, Organize Frontend by Page, Not by Type: Vertical Slices Cut File Reads by 62.5%
When AI agents do the editing, file layout becomes a direct cost metric: every extra file read consumes context and invites cross-page contamination. Shrinking the modification radius to one directory plus one shared file is a concrete way to reduce both token spend and the chance an AI copies patterns from the wrong page.
The argument starts with a concrete symptom: changing one button on an orders page means the AI must wander through routes, components, hooks, API, and styles directories, because horizontal type-based layering gives no signal about which files belong together. AI has no memory of the codebase; it only knows what it reads, so scattered files become a context-window cost, not just a navigation annoyance.
Vertical slicing reverses the axis: one URL, one directory containing the page's structure, styles, and tests, with pages forbidden from importing each other. The shared layer shrinks to a whitelist of three items with intrinsic single-source-of-truth properties: the API service layer, theme variables, and global toast. A router table is the sole registry connecting URLs to directories.
The article puts numbers on the trade-off: for a 20-page repo with 5 files per page, a type-layered change reads 8 files (~9600 tokens), while a sliced change reads 3 (~3600 tokens), a 62.5% reduction in context. It openly admits code volume rises ~30% short-term due to duplication, but argues AI cost tracks per-task read volume, not repo size, and that page-local duplication replaces O(page-count) regression risk with O(1) deletion risk. It closes with five pitfalls and clear criteria for when slicing is or isn't worth it.
The 8-to-3 reduction is a back-of-envelope estimate built on explicit assumptions, but its direction holds: the real variable is how many directories a single page spans, so the benefit grows with page count and file scattering and shrinks for small or tightly-coupled pages.
The article reframes code duplication as a feature: when the editor is a context-window LLM, duplicating page-local code replaces O(page-count) regression risk with O(1) read cost, which flips the usual human-centric DRY trade-off.
The whitelist of shared layers (API, theme, toast) is justified not by convention but by inherent singleton properties: a backend contract, site-wide visual tokens, and a single on-screen notification each have no natural page owner.
The honest admission that total lines rise ~30% directly contradicts the instinct that DRY is always better; the argument rests on the premise that AI is the primary modifier, which is a specific organizational decision, not a universal law.