Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. 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.
  2. 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.
  3. 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-build runs from a one-line build.rs, scans slabs/<feature>/*.rs and jobs/*.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, explicit BEGIN IMMEDIATE transaction boundaries, side-effect enqueues, HTML markup, and co-located #[cfg(test)] mod tests. An agent reads one file plus schema.sql and sees the full behavior.
  • Repeating a four-field FromRow struct or a five-line SELECT query in two slabs costs almost nothing and keeps features independent. You can delete or rewrite any slab without breaking another slab.
  • schema.sql holds every table, column, and index in one file, and GET /_slabs/manifest (in development) or slabs list prints 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:

  1. The logic implements a stable, security-sensitive protocol or invariant (such as Argon2id hashing, HMAC webhook signing, FTS5 escaping, or CSRF verification).
  2. 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 FromRow structs instead of calling User::find(id). In return, every query is visible, tunable, and verified by co-located tests.
  • Because cargo fmt skips files included from OUT_DIR, teams and CI pipelines must run slabs fmt (or slabs check) alongside cargo fmt.
  • Because slabs query tables directly, update schema.sql with slabs db dump-schema after every migration so every contributor reads accurate column names.