API Reference
The complete technical surface of SveltyCMS β Remote Functions, REST, GraphQL, Real-Time Event Streams, and Local SDK for standard and multi-tenant setups.
On this page
SveltyCMS provides a comprehensive programmatic surface for building custom frontends, automating workflows, and synchronizing external data. Built on a architecture that supports the fastest unified OpenAPI specification, it enables maximum flexibility for any setup β from simple headless blogs to enterprise-grade multi-tenant platforms.
β‘ Core Access Patterns
| Pattern | Context | Latency | Best For |
|---|---|---|---|
| π― Remote Functions | ClientβServer (.server.ts) |
Typed | Auth, Setup, User profile forms |
| β‘ Local SDK | Server-side (.server.ts) |
0β5ms | Native SvelteKit, high-throughput |
| π REST API | External (Mobile, Apps) | 50β150ms | Simple CRUD & Integrations |
| π GraphQL API | Frontend (React, Vue, SPA) | 50β200ms | Complex data fetching |
| π GraphQL Subscriptions | Real-time (WebSocket) | <50ms | Live updates, collaborative editing |
| π OpenAPI Spec | Documentation & SDKs | Unified | Fastest automated client generation |
π― Remote Functions (2026 Architecture) {#remote-functions-2026-architecture}
SveltyCMS uses SvelteKit Remote Functions (.server.ts files) for type-safe client-to-server communication. These replace traditional form actions and manual fetch() calls with fully typed async functions that provide complete TypeScript inference between components and server logic.
File Structure
src/routes/
βββ login/
β βββ +page.server.ts β load, OAuth redirects, 2FA, resetSetup
β βββ auth.server.ts β signIn, signUp, forgotPW, resetPW, prefetch (592 lines)
βββ setup/
β βββ +page.server.ts β load, installDriver (~200 lines)
β βββ setup.server.ts β testDatabaseConnection, seedDatabase, completeSetup, testEmailConnection, testRedisConnection (665 lines)
βββ (app)/user/
βββ +page.server.ts β load
βββ user.server.ts β uploadAvatar, updateUserProfile, createToken, exportUserData, anonymizeAccount
```
### Enterprise Gains (Measured)
| Metric | Before (Form Actions) | After (Remote Functions) |
| ------------------------ | ----------------------------------- | ------------------------------------------------------------- |
| `login/+page.server.ts` | 1,625 lines | **310 lines (-81%)** |
| `setup/+page.server.ts` | 1,345 lines | ~200 lines (-85%) |
| Type safety | `formData.get("email")?.toString()` | `signIn(email: string, password: string, event)` |
| Rate limiting | Embedded in monolithic file | Explicit `RateLimiter` per function β auditable |
| Timing-attack mitigation | Buried in 1,625-line file | Explicit argon2 verify visible in `signIn` |
| Audit logging | Interleaved with form parsing | Fire-and-forget at function boundaries |
| Testability | Requires full SvelteKit event mock | Plain async functions with typed params |
| Security audit surface | 2,970 lines across 2 monoliths | 510 lines (page servers) + 1,524 lines (organized .server.ts) |
### Available Remote Functions
| Module | Functions | Security Preserved |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| `login/auth.server.ts` | `signIn`, `signUp`, `forgotPW`, `resetPW`, `prefetchFirstCollection` | Rate limiting, Argon2id, timing-attack mitigation, audit logging |
| `setup/setup.server.ts` | `testDatabaseConnection`, `seedDatabase`, `completeSetup`, `testEmailConnection`, `testRedisConnection` | Valibot validation, setup gating, preset-based seeding |
| `(app)/user/user.server.ts` | `uploadAvatar`, `deleteAvatar`, `updateUserProfile`, `verifyPassword`, `batchUserAction`, `createToken`, `updateToken`, `deleteToken`, `exportUserData`, `anonymizeAccount` | CSRF tokens, RBAC |
### What Stays as Form Actions
OAuth redirects (`signInOAuth`, `signInOAuthGithub`), 2FA verification (`verify2FA` β hidden form for CSRF), setup reset (`resetSetup` β disk I/O), and driver installation (`installDriver` β spawn-based) remain as traditional form actions because they involve browser redirects, hidden form patterns, or OS-level operations.
---
## π‘οΈ Unified Gatekeeper Architecture
SveltyCMS uses a high-performance **Unified Gatekeeper** (`src/routes/api/[...path]`) that dispatches requests to domain-specific handlers.
### Key Benefits
- **Zero-Latency Dispatching**: Internal server-to-server calls bypass HTTP overhead via the `LocalCMS` bridge.
- **Fail-Closed Security**: Every request must pass central authorization before being dispatched.
- **ETag Conditional Requests**: All GET 200 responses include XXH3 (xxhash64) ETag headers via `hash-wasm` β a high-performance non-cryptographic hash ~10Γ faster than SHA-256. Clients sending `If-None-Match` receive `304 Not Modified` with zero body when content hasn't changed.
- **API Versioning**: All responses include `X-API-Version: 1` header. `/api/v1/` path prefix automatically routes to the current API version.
---
## π Complete API Reference (Handler Based)
### Content & Data
- [π **Collections (collections.ts)**](/docs/reference/api/collections) β Entry CRUD, schema discovery, and revisions.
- [π **Content & Search (content.ts)**](/docs/reference/api/content) β Global search, SSE events, and GraphQL.
- [πΌοΈ **Media (media.ts)**](/docs/reference/api/media) β Asset uploads, processing, and folder management.
### Identity & Access
- [π₯ **Auth & Identity (auth.ts)**](/docs/reference/api/auth) β Login, 2FA, SAML SSO, and Profiles.
- [π **Tokens (tokens.ts)**](/docs/reference/api/tokens) β Invitation links and programmatic API keys.
- [π **SCIM 2.0 (scim.ts)**](/docs/reference/api/scim) β Standardized user provisioning.
### System & Infrastructure
- [βοΈ **System & Setup (system.ts / setup.ts)**](/docs/reference/api/system) β Settings, widgets, webhooks, AI translation, and job scheduling.
- [π **Dashboard (dashboard.ts)**](/docs/reference/api/dashboard) β Metrics, logs, and health data.
- [π **Utilities (utility.ts)**](/docs/reference/api/utility) β Cache, trash, and email services.
**New** `GET /api/health`, `POST /api/system-jobs`, `POST /api/ai/translate`
### π¦ Data Operations
APIs for configuration promotion, content transfer, migrations, importers, backups, and content sync.
- [π€ **Configuration Promotion**](/docs/reference/api/configuration-promotion) β Promote CMS structure between environments with plan-first workflow.
- [π¦ **Content Transfer**](/docs/reference/api/content-transfer) β Export/import editorial content as portable packages with NDJSON streaming.
- [π **Data Migrations**](/docs/reference/api/data-migrations) β Idempotent schema/data transformations with locking and risk scoring.
- [π₯ **External Importers**](/docs/reference/api/importers) β Import from WordPress, Drupal, CSV, JSON, and other sources.
- [πΎ **Backups & Restore**](/docs/reference/api/backups) β Encrypted disaster recovery with manifest validation and restore plans.
- [π **Content Sync**](/docs/reference/api/content-sync) β Controlled cross-environment content synchronization.
---
## π‘ Response Strategy
All REST endpoints follow a unified response shape:
### Success (200 / 201)
```
{ "success": true, "data": { ... } }
```
### Error (4xx / 5xx)
```
{ "success": false, "error": "UNAUTHORIZED", "message": "Invalid Bearer token." }
```
---
**Next Steps**: Start with the [Collections Reference](/docs/reference/api/collections) for data fetching. For real-time updates, see [Content & Search](/docs/reference/api/content). For type-safe client-server calls, use [Remote Functions](#remote-functions-2026-architecture).