zazzy
Features

Usage tracking

Metering, quotas, and usage-based billing.

Usage tracking meters what orgs consume, enforces per-metric quotas, and feeds usage-based billing. Events are recorded append-only, rolled up daily by a cron into a read model, and surfaced on a dashboard (charts via Recharts). Metered metrics are pushed to Stripe Billing Meters through billing's seam.

Optional feature

Usage is optional (core: false, requires: ["billing", "flags", "jobs"]). It is a leaf — no feature depends on it — so it prunes cleanly on its own.

What it does

  • IngestionrecordUsage(...) is the append-only entry point, callable from anywhere server-side; an optional idempotency key dedups replays.
  • Consumption & quotasusageConsumption / getConsumedAmount provide the QuotaConsumption that flags' checkQuota reads; enforceQuota is the per-metric block/warn gate. Metrics are declared in config/usage.ts.
  • Rollup & retention — a daily usage/rollup cron aggregates events into UsageRollup; a retention cron prunes raw events past RETENTION_DAYS (rollups are kept forever as history).
  • Warn emails — breaching a warn-mode quota emits usage/quota.warned; sendQuotaWarnedEmail delivers the notice through the injected email surface.
  • DashboardUsageDashboard renders per-metric current-period usage.
  • Stripe Meters — the rollup reports metered totals via billing's reportOrgMeterUsage.

Models it adds

ModelPurpose
UsageEventAppend-only usage stream (metric, quantity, optional idempotency key).
UsageRollupOne row per (org, metric, day) — the aggregated read model, kept forever.

Adds the marker-wrapped Organization.usageEvents / usageRollups relations, and vendors components/ui/chart.tsx (the Recharts wrapper) for the dashboard.

Env it needs

None. Adds the recharts dependency.

Composition

  • requires: ["billing", "flags", "jobs"] — quota limits resolve through flags' checkQuota; metered totals push through billing's reportOrgMeterUsage; the rollup/retention crons and the usage/quota.warned event run on jobs.
  • email is a soft consumer seam: the quota-warned email is delivered through an injected email surface (usage doesn't require email).
  • admin reads a per-metric summary through the same source as the dashboard.

What pruning removes

Leaving usage out drops features/usage, config/usage.ts, the usage settings page, the UsageEvent and UsageRollup models, the Organization usage relations, the rollup/retention jobs, and components/ui/chart.tsx (plus the recharts dependency). No feature requires usage, so removing it affects only usage itself.

On this page