superapp
Backend

Configuration

Configure and initialize the superapp backend engine with connections, auth, permissions, and more.

createEngine is the single entry point for configuring your backend. It returns an engine instance you pass to any adapter.

import { createEngine } from '@superapp/backend'

const engine = createEngine({
  connections: {
    main: { type: 'postgres', url: process.env.PG_URL! },
  },
})

Full Configuration

import { createEngine } from '@superapp/backend'
import { betterAuthProvider } from '@superapp/backend/auth/better-auth'
import { postgresProvider } from '@superapp/backend/integrations/postgres'
import { mysqlProvider } from '@superapp/backend/integrations/mysql'
import { sqliteProvider } from '@superapp/backend/integrations/sqlite'
import { csvProvider } from '@superapp/backend/integrations/csv'

const engine = createEngine({
  mode: 'programmatic',
  superapp_db: process.env.TURSO_URL ?? './superapp.db',
  integrations: [postgresProvider, mysqlProvider, sqliteProvider, csvProvider],
  connections: {
    main: { type: 'postgres', url: process.env.PG_URL! },
    warehouse: { type: 'mysql', url: process.env.MYSQL_URL! },
  },
  auth: betterAuthProvider({ /* ... */ }),
  duckdb: {
    maxMemory: '256MB',
    threads: 2,
    queryTimeout: 30_000,
    poolSize: 10,
    idleTimeout: 300_000,
  },
  limits: {
    maxLimit: 10_000,
    maxIncludeDepth: 3,
    maxFilterDepth: 5,
    rateLimitPerUser: 200,
    rateLimitPerIP: 500,
  },
  audit: {
    enabled: true,
    logQuery: true,
    logParams: true,
    logDuration: true,
    retention: '90d',
  },
  jwt: {
    algorithms: ['RS256', 'ES256'],
    issuer: 'https://auth.myapp.com',
  },
  security: {
    cors: {
      origin: ['https://myapp.com'],
      credentials: true,
    },
  },
  masterKey: process.env.SUPERAPP_MASTER_KEY!,
  permissions: { /* ... */ },
  roles: { /* ... */ },
})

Options Reference

OptionTypeDefaultDescription
mode'programmatic' | 'admin_ui''programmatic'Engine operation mode
superapp_dbstring'./superapp.db'Path to the database where superapp stores its own internal tables. Local file path for SQLite or a Turso URL.
integrationsProvider[][]Database integration providers to load
connectionsRecord<string, Connection>{}Named database connections
authAuthProvider—Authentication provider
duckdbDuckDBConfig—DuckDB memory, threads, pool settings
limitsLimitsConfig—Query and rate limit constraints
auditAuditConfig—Audit logging configuration
jwtJWTConfig—JWT algorithm and issuer settings
securitySecurityConfig—CORS and security headers
masterKeystring—Master API key for admin access
permissionsRecord<string, Permission>{}Permission definitions (snake_case slugs)
rolesRecord<string, string[]>{}Role-to-permission mappings

Minimal vs. Full

For development, only connections is required. Add auth, permissions, and roles when you need access control:

// Development — open access
const engine = createEngine({
  connections: {
    main: { type: 'postgres', url: 'postgres://localhost:5432/mydb' },
  },
})

// Production — full access control
const engine = createEngine({
  connections: { main: { type: 'postgres', url: process.env.PG_URL! } },
  auth: betterAuthProvider({ /* ... */ }),
  permissions: { /* ... */ },
  roles: { /* ... */ },
  masterKey: process.env.SUPERAPP_MASTER_KEY!,
  audit: { enabled: true },
})

On this page