Why Transaction Scripts work for parallel AI agents
Slabs organizes every application around Martin Fowler’s Transaction Script pattern. Every HTTP endpoint lives in one file (slabs/<feature>/<action>.rs) and every background job lives in one file (jobs/<name>.rs). That layout removes the shared files and indirection layers that stall parallel work by both human teams and AI coding agents. See The Slabs doctrine for all eight architectural rules behind the framework.
The cost of layered MVC architectures
Traditional web frameworks split one user action across five or more directories, including a route table, a controller, a service class, a repository or ORM model, a serializer, and a separate test directory. That layout creates three concrete problems when multiple engineers or AI agents work at the same time:
- Every new endpoint edits the central router,
models/mod.rs, or a shared service file. Running ten agents in parallel guarantees rebase collisions on those shared files. - To verify a single write, an agent must open six files and trace implicit ORM callbacks, before-action filters, and dependency injection graphs. Hidden hooks (
before_save,after_commit) bury side effects far from the handler. - Shared DTO structs and generic repository traits break unrelated endpoints whenever one feature adds a field or changes a query shape.
How Slabs eliminates shared hotspots
Slabs replaces those layers with four concrete mechanisms:
slabs-buildruns from a one-linebuild.rs, scansslabs/<feature>/*.rsandjobs/*.rs, and writes$OUT_DIR/discovered_slabs.rs. Adding an endpoint touches zero existing files. Twenty agents can write twenty slabs in parallel with zero git merge conflicts.- One slab file holds the route definition (
pub fn slab() -> SlabDef), request and response types, explicit line-1 auth and rate-limit guards, parameterized SQL, explicitBEGIN IMMEDIATEtransaction boundaries, side-effect enqueues, HTML markup, and co-located#[cfg(test)] mod tests. An agent reads one file plusschema.sqland sees the full behavior. - Repeating a four-field
FromRowstruct or a five-lineSELECTquery in two slabs costs almost nothing and keeps features independent. You can delete or rewrite any slab without breaking another slab. schema.sqlholds every table, column, and index in one file, andGET /_slabs/manifest(in development) orslabs listprints every route and background job as structured metadata.
When to extract shared code
Slabs does not ban all shared code. It raises the bar for adding it. Put code in a library crate or a _-prefixed helper (_helpers.rs, which slabs-build skips) only when both conditions hold:
- The logic implements a stable, security-sensitive protocol or invariant (such as Argon2id hashing, HMAC webhook signing, FTS5 escaping, or CSRF verification).
- Divergent copies would create a correctness or security bug.
Everything else, including query projections, form structs, validation rules, and HTML fragments, belongs directly inside each slab.
Trade-offs to expect
- You write explicit SQL and local
FromRowstructs instead of callingUser::find(id). In return, every query is visible, tunable, and verified by co-located tests. - Because
cargo fmtskips files included fromOUT_DIR, teams and CI pipelines must runslabs fmt(orslabs check) alongsidecargo fmt. - Because slabs query tables directly, update
schema.sqlwithslabs db dump-schemaafter every migration so every contributor reads accurate column names.