Teaching Agents to Build Your SaaS: Inside Cornerstone

How a modular Rails 8 foundation uses explicit LLM instructions and swappable provider adapters to end the era of "clone and forget" boilerplates.

7 min read • View on GitHub • More from coreyhaines31

A sprawling architectural blueprint spread across a wooden drafting table. On the left side, a human hand holds a precise metal compass. On the right side, a sleek mechanical robotic hand holds an ink drafting pen. Both are working simultaneously on the same structural drawing. This illustrates the collaborative nature of AI and human developers working on the Cornerstone codebase.
Cornerstone is designed to be manipulated by both human engineers and autonomous coding agents.
Key Takeaways

The Codebase as an API for Agents

The era of the "clone and forget" boilerplate is dead. Cornerstone is interesting not just because it is a modern Rails template, but because it is designed specifically for the AI era. By treating the codebase as a living, modular framework and explicitly documenting its architecture for LLMs via a dedicated markdown file, Cornerstone shifts the paradigm. It is a foundation built to be manipulated by autonomous coding agents as much as by human engineers.

A Rails 8 SaaS template foundation with modern UI, authentication, and multi-tenancy. Built for rapid development with a clean, modular architecture.

coreyhaines31/cornerstone README, Project Documentation · Repository: coreyhaines31/cornerstone

The Provider Abstraction Engine

The core logic for billing, email, and AI adapters lives in a dedicated library directory intended to be highly swappable. Instead of hardcoding a specific payment processor, the system is designed around a generic gateway interface. This allows the template to support different vendors by simply swapping the adapter in a central configuration file.

The Provider Abstraction Pattern routes generic application calls to specific vendor APIs.

Multi-Tenancy by Default

The core data model revolves around the Account, User, and Membership triad. This allows a single user to belong to multiple organizations with different roles. The project uses a dedicated concern to handle automatic database scoping and a current attributes singleton to track the active account and user throughout the request lifecycle, ensuring data does not leak across tenants.

Safe Multi-Tenancy Data Scoping using the Account, Membership, and User triad.

Bringing ShadCN to Ruby

The project implements a robust design system using ViewComponent, bringing the highly successful ShadCN "copy-paste" component philosophy into the Rails ecosystem. A base component provides a helper to safely merge custom utility classes with default component styles. It uses a "Helper-First" approach, making the components accessible to developers who might find standard component rendering syntax verbose.

A close-up view of a traditional typesetter's wooden tray. Instead of lead letters, the individual compartments hold tiny, perfectly formed web UI elements like a button, a dropdown menu, and a toggle switch. A pair of fine metal tweezers is delicately lifting one of the buttons out of its designated slot. This represents the modular, copy-paste nature of the UI components.
The ViewComponent library allows developers to precisely place modular UI elements without writing verbose initialization code.

The Weight of Opinionated Boilerplates

Compared to established commercial templates, Cornerstone fills a niche for developers seeking a lightweight, unopinionated foundation. While heavy templates offer more out-of-the-box features, Cornerstone's modular approach is better suited for developers who want a starting point rather than a straightjacket.

The composition is split into two halves. The left side depicts a massive, monolithic stone block being chipped away by a single heavy chisel. The right side depicts a neat, organized collection of interchangeable brass clockwork gears sliding smoothly into a modular frame. A clear visual contrast showing rigid monoliths versus swappable modules.
Cornerstone favors a modular, swappable architecture over a rigid, monolithic boilerplate.
FeatureCornerstoneBullet TrainJumpstart Pro
Architecture StyleModular FoundationSuper-ScaffoldingCommercial Engine
AI ReadinessFirst-class agent docsAd-hocAd-hoc
UI ParadigmViewComponent/ShadCNCustom HelpersCustom Helpers
Upstream DriftManaged via upgrade scriptHighManaged via gem updates