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

System tables, built-in routes, middleware, and error codes

This reference lists the twelve framework-owned database tables, the built-in routes mounted by build_router, the Tower middleware stack order, and the HTTP responses produced by SlabError.

System database tables

Db::init_system_tables(), Db::migrate(), and Db::migrate_dir() create these twelve tables idempotently. PgDb creates PostgreSQL equivalents using TIMESTAMPTZ, JSONB, BIGINT, and BOOLEAN. Applications define their own users table in migrations/.

TablePrimary key and key columnsIndexesOwned by
slabs_sessionsid (ses_...), user_id, role, token_hash (UNIQUE), expires_at, created_at(user_id), (expires_at)slabs-auth
slabs_magic_linksid (mlk_...), email, purpose, code_hash (UNIQUE), expires_at, created_at(expires_at)slabs-auth
slabs_access_tokensid (pat_...), user_id, role, description, permission, token_hash (UNIQUE), last_used_at, expires_at, created_at(user_id)slabs-auth
slabs_jobsid (job_...), job_name, queue, payload_json, status, attempts, max_attempts, run_at, last_error, created_at, updated_at(status, run_at, created_at)slabs-jobs
slabs_cachecache_key (PRIMARY KEY), value_text, expires_at, updated_at(expires_at)slabs-cache
slabs_mail_outboxid (eml_...), from_addr, to_addr, subject, text_body, html_body, sent_atPrimary keyslabs-mail
slabs_blobsid (blb_...), filename, content_type, byte_size, checksum_sha256, storage_key (UNIQUE), created_atPrimary key, unique storage_keyslabs-storage
slabs_webhooksid (whk_...), scope_id, name, url, signing_secret, subscribed_actions_json, active, created_at(scope_id, active)slabs-webhooks
slabs_webhook_deliveriesid, webhook_id (FK ON DELETE CASCADE), action, payload_json, signature, status, response_status, last_error, created_at, delivered_at(webhook_id, created_at DESC)slabs-webhooks
slabs_idempotency_keys(scope, key) (composite PRIMARY KEY), response_json, created_atPrimary keyslabs-db / slabs-webhooks
slabs_audit_logid (aud_...), actor_id, action, target_type, target_id, metadata_json, created_at(target_type, target_id, created_at DESC)slabs-db
slabs_incidentsid (inc_...), fingerprint (UNIQUE), kind, status (open, reopened, resolved), source_file, route_pattern, title, detail, context_json, repro_hint, recent_occurrences_json, occurrences, git_sha, resolved_in_sha, first_seen_at, last_seen_at, resolved_at(status, last_seen_at DESC)slabs-db / slabs-http

Built-in routes

slabs_http::build_router mounts these endpoints alongside your discovered slabs:

MethodPathAvailabilityBehavior
GET/health and /_slabs/healthAlwaysRuns SELECT 1 via ctx.db.ping() and returns {"status": "ok", "app": "<app_name>"}.
GET/health/liveAlwaysLiveness probe returning 200 OK JSON {"status": "ok"}.
GET/health/readyAlwaysReadiness probe returning 503 Service Unavailable when draining after SIGTERM or when SELECT 1 fails, otherwise 200 OK.
GET/_slabs/metricsAlways (token-gated in staging/prod)Returns Prometheus text (or JSON when Accept: application/json) covering per-route p50/p95/p99 latency histograms mapped to source_file, HTTP counts, job queue stats, active incident count, and active realtime topics. In staging and production, returns 404 unless SLABS_METRICS_TOKEN is set, and requires Authorization: Bearer <token> verified in constant time.
GET/_slabs/incidentsAlways (token-gated in staging/prod)Lists incidents filtered by status=active|open|reopened|resolved|all (default active) and limit, ordered by last_seen_at DESC. Protected by SLABS_METRICS_TOKEN.
GET/_slabs/incidents/{id}Always (token-gated in staging/prod)Returns one incident record with source_file, context_json, recent_occurrences_json, attachment blob IDs, and a ready-to-paste repro_test Rust skeleton. Protected by SLABS_METRICS_TOKEN.
GET/_slabs/incidents/{id}/attachments/{blob_id}Always (token-gated in staging/prod)Streams a scoped attachment blob belonging to the incident using safe download headers. Protected by SLABS_METRICS_TOKEN.
POST/_slabs/incidents/{id}/resolveAlways (token-gated in staging/prod)Transitions an incident to resolved with an optional {"resolved_in_sha": "<sha>"} body and dispatches an incident.resolved webhook when configured. Protected by SLABS_METRICS_TOKEN.
GET/_slabs/manifestdevelopment and test onlyReturns the JSON AppManifest containing app_name, registered routes (RouteMeta), and registered jobs (JobMeta).
GET/_slabs/openapi.jsondevelopment and test onlyReturns the OpenAPI 3.1.0 JSON document produced by AppManifest::to_openapi_3_1().
GET/_slabs/maildevelopment and test onlyReturns up to 50 recent messages from slabs_mail_outbox as {"emails": [...]}.
GET/_slabs/vendor/{*path}AlwaysServes embedded MIT assets (basecoat.min.css, basecoat.min.js, htmx.min.js, htmx-ext-sse.js, idiomorph-ext.min.js, alpine.min.js, sw-register.js) with ETag and Cache-Control: public, max-age=86400.
GET/assets/{hash}/{*path}AlwaysServes content-hashed static files from ctx.assets with Cache-Control: public, max-age=31536000, immutable and a sandbox CSP on SVG, HTML, and XHTML assets. Returns HTTP 404 when the path or 12-character SHA-256 hash does not match.

Middleware stack order

build_router wraps every route in these Tower layers from outermost (first to run on incoming requests) to innermost:

  1. sanitize_request_id_middleware strips malformed incoming X-Request-Id headers longer than 64 bytes or containing characters outside [A-Za-z0-9_-].
  2. SetRequestIdLayer generates a time-sortable ULID X-Request-Id (req_<ulid>) when absent.
  3. TraceLayer::new_for_http() emits HTTP request and response tracing spans.
  4. PropagateRequestIdLayer copies X-Request-Id onto the HTTP response.
  5. metrics_middleware records per-route request counts, 5xx counts, latency histograms, slab_file-tagged tracing logs, and http_5xx, panic, and slow_request incidents in slabs_incidents.
  6. Optional CorsLayer mounts only when SLABS_CORS_ORIGINS is non-empty. It restricts cross-origin access to that allowlist with allow_credentials(true).
  7. Optional Strict-Transport-Security: max-age=31536000; includeSubDomains mounts when cookie_secure is true.
  8. Permissions-Policy: camera=(), microphone=(), geolocation=() is set if absent.
  9. Referrer-Policy: strict-origin-when-cross-origin is set if absent.
  10. X-Frame-Options: SAMEORIGIN is set if absent.
  11. X-Content-Type-Options: nosniff is set if absent.
  12. csrf_middleware enforces Fetch Metadata (Sec-Fetch-Site: cross-site) and Origin checks on cookie-authenticated POST, PUT, PATCH, and DELETE requests when SLABS_CSRF_ENFORCE=true. Requests with Authorization: Bearer headers and /webhooks* or /api/webhooks* routes bypass this check.
  13. RequestBodyLimitLayer enforces SLABS_MAX_BODY_BYTES (default 4 MiB).
  14. CompressionLayer compresses responses with gzip and brotli (br).

SlabError HTTP mapping

Every slab returns SlabResult<T> (Result<T, SlabError>). SlabError::into_response serializes a JSON object with error and message fields:

VariantHTTP statusJSON error fieldExtra headers or fields
SlabError::BadRequest(msg)400"bad_request"Includes msg.
SlabError::Unauthorized(msg)401"unauthorized"Includes msg.
SlabError::Forbidden(msg)403"forbidden"Includes msg.
SlabError::NotFound(msg)404"not_found"Includes msg.
SlabError::Database(sqlx::Error::RowNotFound)404"not_found"Fixed message "record not found".
SlabError::Conflict(msg)409"conflict"Includes msg.
SlabError::Validation { field, message }422"validation_error"Includes "field": field and "message": message.
SlabError::ValidationErrors(fields)422"validation_error"Includes "fields": { "<field>": ["<message>", ...] } produced by Validate::finish.
SlabError::TooManyRequests { retry_after_secs, message }429"too_many_requests"Sets Retry-After: <secs> header and "retry_after_secs" JSON field.
SlabError::Database(other)500"database_error"Logs raw error via tracing::error!; returns "internal database error" without leaking SQL.
SlabError::Internal(msg)500"internal_error"Logs msg via tracing::error!; returns "internal server error".

Built-in background job

JobRegistry::new registers "slabs.deliver_webhook" on the "webhooks" queue automatically unless your app defines a job with the same name. When SLABS_WEBHOOKS_LIVE is true, it calls ctx.webhooks.deliver_http(delivery_id, ctx.config.webhooks_allow_local). Otherwise it records HTTP 200 in slabs_webhook_deliveries without outbound network I/O.