Backend Setup
Backend functions allow you to execute server-side logic from your Sp00ky application. Currently, Sp00ky supports backend integration through the outbox pattern, where client operations create job records that are processed asynchronously by a backend service.
How It Works
The outbox pattern decouples your frontend from backend services:
- Your client calls
db.run()to create a job record in SurrealDB - A separate job runner service polls for pending jobs
- The job runner executes the HTTP request to your backend API
- The job status is updated in the database
- Your client can query the job status reactively
Direct backend calls may be supported in future versions. For now, the outbox pattern is the recommended approach for all backend integrations.
Configuration
Backend functions are configured in your sp00ky.yml file in the schema directory.
You can validate your config at any time with spky lint.
Configuration Fields
All apps are defined under the apps key. Each app has a required type field (backend or frontend).
Backend-specific fields:
spec(required): Path to the OpenAPI specification file that defines your API routesbaseUrl: The base URL of your HTTP backend serviceauth(optional): Authentication configuration for the backendtype: Authentication type (currently onlytokenis supported)token: The bearer token to include in HTTP requests
method(required): Trigger method configurationtype: The method type (useoutboxfor the outbox pattern)table: The name of the job table in SurrealDB (e.g.,job)schema: Path to the SurrealQL schema file that defines the job table structure
Shared fields (all app types):
dev(optional): A dev server command thatspky devwill spawn alongside infrastructure (see Dev Server below)deploy(optional): Cloud deployment configuration (dockerfile, port, resources)timeout: HTTP request timeout in seconds (default:10, backend only)timeoutOverridable: Whentrue, the frontend can override the timeout per-job (backend only)
env(optional): Environment variable configuration (see Environment Variables below)
Timeout Configuration
By default, the job runner allows 10 seconds for each HTTP request to complete. For backends that perform long-running operations (e.g., LLM inference, file processing), you can increase the timeout in the deploy section:
When timeoutOverridable is true, the frontend can pass a timeout option to db.run():
If timeoutOverridable is false (the default), the timeout option in db.run() is ignored and the deploy-time value is always used.
Authentication
When you configure an auth block in your backend configuration, the job runner will automatically include the token in all HTTP requests to that backend using the Authorization: Bearer <token> header.
This is useful for securing your backend APIs and ensuring that only authorized job runners can execute requests.
On your backend server, validate the bearer token in your middleware:
OpenAPI Specification
Your backend routes are defined using an OpenAPI specification. Each path becomes a callable route from your Sp00ky client.
The request body schema defines the parameters that will be validated when you call db.run(). In this example, the /spookify endpoint requires an id parameter.