Operations Kit

Operations Kit

The optional operations module is a local read model for an independent SaaS. It reads the generated project's database and business events; it does not send data to a NextDevTpl-hosted service. It requires auth, admin, and payment through automatic module dependencies.

Enable it

pnpm dlx create-nextdevtpl@latest my-ops \
  --preset custom \
  --modules auth,analytics,operations \
  --payment stripe \
  --alerts webhook \
  --analytics posthog

After generation, configure only the variables retained in .env.example, run the migration, and sign in with an admin account. Open /admin/operations to see the current UTC 30-day period. A metric displays -- with a status when its source is unavailable; an old snapshot is never presented as current data.

Event dictionary

The telemetry contract uses a dotted name, positive version, source, and JSON attributes. Product code should call the server helpers after the business transaction succeeds:

EventSourceRequired meaning
landing.viewedClientA public landing page view after analytics consent
signup.completedServerAccount creation completed
first_value.completedServerThe product-specific first useful result; define the action in your app
subscription.activatedServerA verified active subscription state
core_action.completedServerThe product's repeated value action; define the action in your app
api.request.failedServerA handled API failure with method, path, status, and class
action.failedServerA failed Server Action with action name and class
job.failedSystemA failed background dispatch or execution

first_value.completed and core_action.completed are extension points. The template does not infer them from page views or arbitrary button clicks.

Metric dictionary

The dashboard period is the previous 30 UTC days. Amounts are stored in the smallest currency unit, usually cents. Every metric includes a source and one of ready, zero-data, not-configured, partial, unauthorized, or query-failed.

MetricFormula or sourceCaveat
Total usersCount of user rowsAll-time total
Active subscriptionsActive rows in subscriptionCurrent state, not period count
New usersUsers created in the periodDatabase source
Credit consumptionSum of consumption transactions in the periodDatabase source
Confirmed revenueSum of payment_succeeded revenue_event rowsServer-side payment data only
MRRActive plan prices, with annual price divided by 12Requires a matching local price configuration
Paid conversionCohort users with a first valid subscription payment in the period / users registered in the same periodRenewals, proration adjustments, and browser checkout events are excluded from first-payment conversion
RefundsSum and count of refund revenue eventsProvider webhook must be processed
Payment failuresCount of payment_failed revenue eventsUsed by the alert rule
AI costToken usage multiplied by the effective model priceestimated when provider usage is available; unavailable otherwise
Token coverageRequests with actual token usage / AI requestsDoes not claim provider billing reconciliation
AI gross marginConfirmed revenue - estimated AI costThis is an operating estimate, not accounting profit
Success and latencyAI success ratio and average latencyMsUses recorded AI usage events
Funnel and retentionRegistered/paid are database-backed; landing, activation, D1/D7/D30 are explicit not-configured until a query source is addedDo not treat missing data as zero
System healthAPI, job, and webhook success ratiosExplicitly unavailable until log aggregation is connected

Use recordAIUsage after each completion when the operations module is selected. Never pass prompts, model output, or uploaded content to the usage record.

Alerts

Select one adapter at generation time:

AdapterVariablesBehavior
noopNonePersists alert state without sending
emailALERT_EMAIL_TO, EMAIL_FROM, selected mail adapterSends text and escaped HTML
webhookALERT_WEBHOOK_URL, optional ALERT_WEBHOOK_SECRETSends JSON and an optional HMAC-SHA256 X-NextDevTpl-Signature header

The initial rules are payment failure rate (20%, two consecutive breaches), AI cost (smallest-unit threshold, one breach), and paid conversion (2%, two consecutive breaches). Each rule has a 30-minute cooldown by default. Recovery uses a separate threshold to prevent flapping. Alert delivery failures are stored and do not fail the product request.

Schedule the protected endpoints with CRON_SECRET:

curl -X POST https://your-domain.example/api/jobs/operations/snapshot \
  -H "Authorization: Bearer $CRON_SECRET"
curl -X POST https://your-domain.example/api/jobs/operations/alerts \
  -H "Authorization: Bearer $CRON_SECRET"

Run snapshots daily and alert evaluation every 5-15 minutes. The generated Vercel file currently schedules credit expiry only; add these operations jobs in the platform scheduler yourself.

Privacy boundary

Client capture waits for analytics consent. The first-party anonymous ID is bounded and retained for at most one year in a cookie or local storage. The context may contain anonymous/user/session/request IDs, locale, source, and UTM values. Redaction removes password, token, cookie, authorization, email, prompt, content, upload, and filename fields. Server payment and AI read models retain business facts, usage counts, identifiers needed for aggregation, and alert history; they do not retain prompts or model responses.

Document the selected external provider, retention period, legal basis, and deletion process in the generated project's privacy and cookie policies. A configured provider is not proof that a production data-processing agreement or regional transfer requirement has been completed.

Troubleshooting

SymptomCheck
Dashboard returns 500Database migration, operations schema, payment dependency, and server logs
Metric is zero-dataThe period has no matching rows; create a real business event before changing the formula
Metric is not-configuredThe source is intentionally not wired, such as retention or log health
Alert does not sendCRON_SECRET, selected adapter variables, mail adapter, cooldown, and alert delivery history
Webhook rejectedVerify URL, JSON consumer, optional HMAC secret, and X-NextDevTpl-Signature validation
Client events missingAnalytics consent, browser network request to /api/telemetry, provider key/host, and redaction logs
Cloudflare build fails on WindowsBuild the generated project in a Linux-native directory or Linux CI; OpenNext may hit Windows symlink permissions

The operations module intentionally does not provide cohort query editing, automatic refunds, user bans, plan changes, service shutdowns, accounting-grade profit reports, or provider-specific dashboards.

On this page