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/.
| Table | Primary key and key columns | Indexes | Owned by |
|---|---|---|---|
slabs_sessions | id (ses_...), user_id, role, token_hash (UNIQUE), expires_at, created_at | (user_id), (expires_at) | slabs-auth |
slabs_magic_links | id (mlk_...), email, purpose, code_hash (UNIQUE), expires_at, created_at | (expires_at) | slabs-auth |
slabs_access_tokens | id (pat_...), user_id, role, description, permission, token_hash (UNIQUE), last_used_at, expires_at, created_at | (user_id) | slabs-auth |
slabs_jobs | id (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_cache | cache_key (PRIMARY KEY), value_text, expires_at, updated_at | (expires_at) | slabs-cache |
slabs_mail_outbox | id (eml_...), from_addr, to_addr, subject, text_body, html_body, sent_at | Primary key | slabs-mail |
slabs_blobs | id (blb_...), filename, content_type, byte_size, checksum_sha256, storage_key (UNIQUE), created_at | Primary key, unique storage_key | slabs-storage |
slabs_webhooks | id (whk_...), scope_id, name, url, signing_secret, subscribed_actions_json, active, created_at | (scope_id, active) | slabs-webhooks |
slabs_webhook_deliveries | id, 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_at | Primary key | slabs-db / slabs-webhooks |
slabs_audit_log | id (aud_...), actor_id, action, target_type, target_id, metadata_json, created_at | (target_type, target_id, created_at DESC) | slabs-db |
slabs_incidents | id (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:
| Method | Path | Availability | Behavior |
|---|---|---|---|
GET | /health and /_slabs/health | Always | Runs SELECT 1 via ctx.db.ping() and returns {"status": "ok", "app": "<app_name>"}. |
GET | /health/live | Always | Liveness probe returning 200 OK JSON {"status": "ok"}. |
GET | /health/ready | Always | Readiness probe returning 503 Service Unavailable when draining after SIGTERM or when SELECT 1 fails, otherwise 200 OK. |
GET | /_slabs/metrics | Always (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/incidents | Always (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}/resolve | Always (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/manifest | development and test only | Returns the JSON AppManifest containing app_name, registered routes (RouteMeta), and registered jobs (JobMeta). |
GET | /_slabs/openapi.json | development and test only | Returns the OpenAPI 3.1.0 JSON document produced by AppManifest::to_openapi_3_1(). |
GET | /_slabs/mail | development and test only | Returns up to 50 recent messages from slabs_mail_outbox as {"emails": [...]}. |
GET | /_slabs/vendor/{*path} | Always | Serves 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} | Always | Serves 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:
sanitize_request_id_middlewarestrips malformed incomingX-Request-Idheaders longer than 64 bytes or containing characters outside[A-Za-z0-9_-].SetRequestIdLayergenerates a time-sortable ULIDX-Request-Id(req_<ulid>) when absent.TraceLayer::new_for_http()emits HTTP request and response tracing spans.PropagateRequestIdLayercopiesX-Request-Idonto the HTTP response.metrics_middlewarerecords per-route request counts, 5xx counts, latency histograms,slab_file-taggedtracinglogs, andhttp_5xx,panic, andslow_requestincidents inslabs_incidents.- Optional
CorsLayermounts only whenSLABS_CORS_ORIGINSis non-empty. It restricts cross-origin access to that allowlist withallow_credentials(true). - Optional
Strict-Transport-Security: max-age=31536000; includeSubDomainsmounts whencookie_secureistrue. Permissions-Policy: camera=(), microphone=(), geolocation=()is set if absent.Referrer-Policy: strict-origin-when-cross-originis set if absent.X-Frame-Options: SAMEORIGINis set if absent.X-Content-Type-Options: nosniffis set if absent.csrf_middlewareenforces Fetch Metadata (Sec-Fetch-Site: cross-site) andOriginchecks on cookie-authenticatedPOST,PUT,PATCH, andDELETErequests whenSLABS_CSRF_ENFORCE=true. Requests withAuthorization: Bearerheaders and/webhooks*or/api/webhooks*routes bypass this check.RequestBodyLimitLayerenforcesSLABS_MAX_BODY_BYTES(default 4 MiB).CompressionLayercompresses 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:
| Variant | HTTP status | JSON error field | Extra 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.