// Rate-limited backend for the {{projectName}} project. // // `rateLimitPlugin` runs on the rpc interceptors — the one surface that sees // every call AND the resolved subject. A `default` fallback applies to every // procedure; `rules` override per endpoint (exact tag or `/regex/`), with a // choice of algorithm (sliding-window / fixed-window / token-bucket+burst) and // composite keying (`by: 'subject' | 'tenant' | 'apiKey' | 'global'` or an // array). Over-limit calls fail a typed `RateLimited` error — the plugin merges // it into every procedure's wire error union, so the client decodes it typed. // `store: 'memory'` is single-node; switch to 'postgres' / 'redis' for a cluster. import { defineEnv, envVar } from '@voltro/env' import { rateLimitPlugin } from '@voltro/plugin-ratelimit' 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, plugins: [ rateLimitPlugin({ // Global fallback: 100 calls/min, per subject. default: { limit: 100, window: '1m' }, rules: [ // Tight, per-endpoint: notes.create → 3/min per TENANT, token-bucket // (the bucket starts full, so a burst of 3 is allowed, then refills). { match: 'notes.create', limit: 3, window: '1m', algorithm: 'token-bucket', burst: 3, by: 'tenant', }, ], store: 'memory', }), ], env, }