Database Documentation Hub
Central hub for SveltyCMS database architecture β 2027-ready allocation-floor engine with 4 production adapters, schema-aware conversion, ring-buffer pooling, and zero-tax LocalCMS.
On this page
Welcome to the SveltyCMS Database Engine documentation. Our architecture is built on the principle of Strict Agnosticism, allowing you to swap between NoSQL and Relational engines without changing a single line of application logic.
π Documentation Structure
1. Database-Agnostic Architecture
- Core Infrastructure β
db.tslifecycle, self-healing proxy, plugin-registry topological boot, LocalCMS SDK - Database Methods Interface β
IDBAdapternamespaces:auth,crud,content,media,system,batch,collection - Database Resilience β Error handling, retry logic, circuit breaker, connection health monitoring
- Performance Architecture β 2027 allocation-floor optimizations, schema-aware conversion, ring-buffer pools, cross-database impact
2. Engine Implementations
- SQLite Implementation β Platinum β Default for local/edge. Sub-ms CRUD, WAL mode, zero network overhead.
- PostgreSQL Implementation β Production β Enterprise scaling, native JSONB, GIN indexing, PgBouncer support.
- MariaDB Implementation π‘ Planned β High-concurrency pooling via
mysql2, optimized relational schemas. - MongoDB Implementation β Production β NoSQL engine, safeQuery security, wire compression.
ποΈ Architecture Overview
π‘οΈ Shared Security Principles (All Adapters)
-
4-Layer Defense-in-Depth: Middleware β Dispatcher β Handler β Page Action
-
Tenant Isolation: Every query scoped by
tenantIdat adapter level β architecturally impossible to bypass -
Credential Hashing: Website tokens and API keys are stored as SHA-256 digests only; plaintext is returned once on creation. See
system.websiteTokens. -
Tenant-Scoped Bearer Lookup: Auth passes
locals.tenantIdinto credential lookups (aligned withauth.getApiKey) to narrow multi-tenant queries. -
MongoDB Soft-Delete Safety:
safeQuery()appliesisDeleted: { $ne: true }so legacy documents without the field remain visible to active queries. -
SSRF Prevention: Cloud storage adapters validate endpoints before connection
-
NoSQL Injection Protection:
sanitizeMongoQueryblocks$where,$function,$expr -
CSPRNG-Only Tokens:
globalThis.crypto.getRandomValues(), noMath.random()fallback -
Fail-Closed API: Unmapped namespaces return 403 by default
π Shared Resilience Patterns (All Adapters)
- Circuit Breaker: 5 consecutive failures β 60s open β probe recovery
- Self-Healing Reconnection: Auto-recovery on connection loss + HMR reload
- Exponential Backoff with Jitter: 1sβ2sβ4sβ8sβ16s, Β±500ms
- Connection Pool Diagnostics:
GET /api/database/pool-diagnostics+ dashboard widget β see Database Resilience - Migration Safety:
CREATE TABLE IF NOT EXISTSβ idempotent
β‘ 2027 Allocation-Floor Optimizations
| Optimization | SQLite | PostgreSQL | MariaDB | MongoDB |
|---|---|---|---|---|
| Schema-aware row conversion | β | β | π‘ Planned | N/A |
| Ring-buffer result pool (64 slots) | β | β | π‘ Planned | β |
| Conditions array pool (32 slots) | β | β | π‘ Planned | N/A |
| Fused mapQuery (no IR objects) | β | β | π‘ Planned | β |
| forβ¦in (zero Object.entries) | β | β | π‘ Planned | β |
| Pre-allocated meta object | β | β | π‘ Planned | β |
| MariaDB double-parse isolated | N/A | β Benefit | π‘ Planned | N/A |
SQL family: ~5-8 fewer allocations per filtered query. MongoDB: ~2-3 fewer (result pool + fused mapQuery). All 4: benefit from shared BaseAdapter optimizations.
π Performance Benchmarks (SQLite, Latest)
| Operation | Latency | RPS |
|---|---|---|
| FIND ONE | 0.090 ms | 10,386 |
| DELETE | 0.051 ms | 14,447 |
| Peak Throughput | β | 15,617 req/s |
| LocalCMS SDK Overhead | β | 0.00% |
Full cross-database benchmarks: Performance Benchmarks.
Adapter Selection Guide
| Scale | Recommended DB | Why |
|---|---|---|
| Dev, edge, small teams | SQLite (default) | In-process, zero network, sub-ms CRUD |
| Production single node | PostgreSQL | JSONB, FTS, replication ready |
| Enterprise / K8s | PostgreSQL + PgBouncer + Redis | Horizontal scale, cross-node invalidation |
| Global / multi-region | PostgreSQL + replicas + CDN | Read replicas, geo-distribution |
MongoDB for unstructured/high-volume. MariaDB for MySQL-compatible setups (planned). SQLite, PostgreSQL, and MongoDB are production-ready.
Last Updated: 2026-06-22 (website-token credential hardening, safeQuery soft-delete fix, parallel SQL list+count) Maintained by: SveltyCMS Team