// Backend app for the {{projectName}} project. Read by `voltro dev`. // // This is the DURABLE KEY-VALUE template. It demonstrates `ctx.kv` — the // framework's second storage primitive, for state you CAN'T recompute — on a // small external-event-sync domain. `ctx.kv` is the opposite contract to // `ctx.cache`: entries are NEVER evicted for capacity; they live until you // delete them or their (optional) TTL lapses. // // The three storage primitives, side by side (the whole point of this template): // • ctx.store — the relational rows you sync in (queryable, joinable). LOSS = re-fetchable. // • ctx.kv — the sync CURSOR + idempotency MARKERS. LOSS = re-process / double-process. Durable. // • ctx.cache — recomputable derived views. LOSS = free (recompute). Not used here; see the api-data-advanced template. // // What's in here (all auto-discovered by file convention — nothing is // registered in this config): // // database/schema.ts — `syncedEvents` table (the rows we ingest) // actions/sync.pull.action.* — THE STAR: getOrElse(cursor) → dedupe via // has()/set(marker,{ttlMs}) → insert row → // set(cursor). The full write surface. // actions/sync.status.action.* — Effect-mode handler (`yield* Kv`): read // the cursor + count markers via list(). // actions/sync.reset.action.* — delete(cursor) + list()/delete() the markers. // queries/events.list.query.* — reactive list of the synced rows (store, not kv). // // `store: 'memory'` keeps boot zero-infra: `ctx.kv` runs on the `database` // backend (the framework's `_voltro_kv` table) which, on the memory store, is // in-process — durable within the run, reset on restart. Switch to `'postgres'` // and the cursor/markers survive restarts and are shared across replicas. import { defineEnv, envVar } from '@voltro/env' // Typed environment — declared once, validated at boot (fail-fast). export const env = defineEnv({ LOG_LEVEL: envVar.enum(['debug', 'info', 'warn', 'error'], { access: 'public', default: 'info' }), }) export default { type: 'api' as const, name: '{{capProjectName}}{{capAppName}}', store: 'memory' as const, // OPTIONAL infra knobs (both default to a zero-infra backend): // kv: 'redis' — durable ctx.kv on a PERSISTENT redis (default 'database'). // cache: 'redis' — distributed query/result cache (this template uses no cache). // Env `KV_BACKEND` / `CACHE_BACKEND` override. See docs → Caching → Key-value backends. // kv: 'redis' as const, // cache: 'redis' as const, env, }