Glossary and architecture decision records
This page defines core Slabs terms and records the architecture decisions behind the framework.
Glossary
| Term | Definition |
|---|---|
AppCtx | Cheap-to-clone runtime state struct passed to every HTTP slab (State<AppCtx>) and background job (AppCtx). Holds handles to config, db, auth, jobs, mail, storage, cache, realtime, webhooks, assets, rate_limit, and audit. |
AppEnv | Deployment environment enum (Development, Test, Staging, Production) parsed from SLABS_ENV. Controls fail-closed validation, cookie_secure defaults, and dev-only routes. |
| Basecoat UI | MIT-licensed CSS and minimal JS library implementing shadcn visual tokens and component classes for plain server-rendered HTML. |
Discovery (slabs-build) | Compile-time scan of slabs/<feature>/*.rs and jobs/*.rs run from build.rs that writes $OUT_DIR/discovered_slabs.rs (collect_slabs() and collect_jobs()). |
__Host-slabs_session | Hardened session cookie name used whenever cookie_secure is true (Path=/, Secure, HttpOnly, SameSite=Lax, no Domain). |
| Idiomorph | DOM morphing extension for HTMX (hx-ext="morph", hx-swap="morph:innerHTML") that diffs incoming server HTML against the live DOM without losing input focus or scroll state. |
| Job | Background transaction script at jobs/<name>.rs that exports pub fn job() -> JobDef, queues in slabs_jobs, and runs on JobRegistry workers. |
| Magic link | Passwordless 6-character alphanumeric sign-in code stored as a keyed HMAC bound to (email, purpose) in slabs_magic_links, locked out after 5 failed attempts in 15 minutes, and consumed atomically with DELETE ... RETURNING. |
| Manifest | JSON document listing every registered route (RouteMeta) and job (JobMeta), mounted at GET /_slabs/manifest in development and test and printed by slabs list. |
| Outbox | The slabs_mail_outbox and slabs_webhook_deliveries SQLite tables that record emails and signed webhooks for inspection in development (GET /_slabs/mail) and isolated tests (TestApp::sent_emails). |
| Prefixed ULID | Lowercase 26-character Crockford Base32 ULID prefixed with a short entity tag (such as usr_01j..., job_01j..., req_01j...) generated by slabs::id::new(prefix). |
| Presence | In-memory tracking of online participants per realtime topic via ctx.realtime.track_presence and ctx.realtime.list_presence, backed by automatic cleanup on PresenceGuard drop. |
| Slab | Self-contained HTTP Transaction Script at slabs/<feature>/<action>.rs that exports pub fn slab() -> SlabDef and holds its own input/output structs, guards, SQL, HTML/JSON response, and co-located tests. |
Architecture decision records
ADR-001. Compile-time file discovery over a central router
Status is accepted. Parallel contributors and AI agents frequently collide on routes.rs and mod.rs files. Slabs scans slabs/<feature>/*.rs and jobs/*.rs in build.rs via slabs_build::discover(), skips mod.rs, _-prefixed files, and ./_-prefixed directories, and includes the generated file once in src/lib.rs via slabs::discover_slabs!(). Adding endpoints touches zero shared files. Because cargo fmt does not traverse OUT_DIR includes, slabs fmt formats both src/ and discovered files.
ADR-002. Raw parameterized SQL over an ORM
Status is accepted. ORMs hide N+1 queries, implicit callbacks, and schema drift behind generated structs and traits. Slabs requires raw parameterized SQL via sqlx::query and sqlx::query_as (with optional compile-time sqlx::query! via slabs db prepare) and treats schema.sql as the single-file schema reference. Every SQL query stays readable inline inside its slab. Contributors bind parameters explicitly and pass FTS5 input through slabs::db::fts5_query.
ADR-003. Split SQLite WAL pools and BEGIN IMMEDIATE
Status is accepted. Shared read/write SQLite pools with deferred transactions fail with SQLITE_BUSY_SNAPSHOT under concurrent HTTP load. Slabs opens a 16-connection read-only pool (reader()) and a 1-connection writer pool (writer()) on file-backed SQLite databases, and runs BEGIN IMMEDIATE in Db::begin(). For sqlite::memory: test databases, Db::connect shares one connection so in-memory tables remain visible across calls.
ADR-004. Explicit line-1 guards over implicit auth middleware
Status is accepted. Route-group middleware makes it hard to verify authorization rules when reading a single endpoint file in isolation. Slabs exposes explicit methods on ctx.auth (require_session, require_admin, require_auth, require_write_auth) and ctx.rate_limit.check(...) to call directly at the top of each handler. Reading line 1 of handle proves who can call the endpoint and what rate limit applies.
ADR-005. Two-tier Clippy policy and static security scanning
Status is accepted. Strict pedantic lints catch bugs and missing docs in shared framework crates, while creating friction inside rapidly authored app endpoints. Slabs enforces unsafe_code = "forbid", missing_docs = "warn", and clippy::pedantic on crates/*, applies focused guardrails on generated apps, and runs a built-in [security] static analyzer inside slabs check and slabs doctor.
ADR-006. Vendored MIT browser assets with zero Node runtime
Status is accepted. JavaScript bundlers, CDN links, and node_modules increase build latency and break offline work. Slabs embeds Basecoat UI, HTMX 2, SSE, Idiomorph, Alpine.js 3, and sw-register.js inside slabs-http under /_slabs/vendor/ and compiles Tailwind CSS v4 with the standalone binary via mise. Every Slabs app compiles and runs offline as one Rust binary plus static CSS.
ADR-007. Fail-closed production boot validation
Status is accepted. Silent development defaults (such as hardcoded signing keys, open CORS, unauthenticated metrics, and exposed /_slabs/mail routes) cause security incidents when copied to production. Slabs introduces AppEnv (SLABS_ENV) and runs AppConfig::validate() inside SlabsApp::boot. In staging and production, boot fails if SLABS_SECRET_KEY is missing or shorter than 32 bytes. Dev routes mount only in development and test, /_slabs/metrics requires SLABS_METRICS_TOKEN, and SLABS_CORS_ORIGINS and SLABS_TRUST_PROXY stay off unless configured.