▶ CARTRIDGE

SaaS Starter Cartridge

A working Next.js 16 SaaS (sign-in, dashboard, Stripe subscriptions) your AI agent can extend without breaking auth or billing.

$49 · one-time

Plus sales tax or VAT where applicable, calculated at checkout.

Need more than one kit? The All-Access Bundle gets all 6 paid cartridges (Rules Mega Pack, Game Prototype, Discord Bot, SaaS Starter, Browser Extension, MCP Server) for $79 one-time, instead of $184 bought separately.

A small, complete SaaS app in Next.js 16 + React 19 + TypeScript (strict), set up for AI-assisted coding: Better Auth email and password sign-in (optional GitHub), a protected dashboard, Free and Pro plans with Stripe Checkout, the Stripe Customer Portal and a signed webhook handler that ignores duplicate and out-of-order events, Postgres through Drizzle ORM (an embedded Postgres, PGlite, for development, so it runs with no database or accounts), an example feature with plan limits, 25 tests plus an end-to-end smoke test that need no keys, Cursor, Claude Code and AGENTS.md rules for Next.js 16, auth and billing, and setup docs from first run to production. One-time purchase (sales tax or VAT added at checkout where applicable), instant download.

Requirements: Needs Node.js 22.13+ (24 LTS recommended). npm run dev, the tests and the build work with no database, Stripe or GitHub account. To take payments you need a Stripe account (test mode is free); for production, a Postgres database (Neon, Supabase or your own) and a host that runs Next.js, such as Vercel.

What's inside

FileCovers
src/app/Landing, pricing, sign-up, sign-in and a protected dashboard (server components + server actions); POST-only billing routes; the Stripe webhook route
src/lib/auth*.tsBetter Auth: email + password (10+ characters), optional GitHub sign-in, database sessions, getSession() / requireUser() helpers for every page and action
src/lib/billing.ts + plans.tsStripe Checkout (subscription mode), Customer Portal, signature-checked webhooks that skip duplicate and older events; Free/Pro limits in one file
src/db/ + drizzle/Drizzle ORM schema and SQL migrations for Postgres; PGlite (Postgres in WebAssembly) for dev and tests, any Postgres URL in production
src/lib/notes.tsExample feature to copy: user-scoped data, zod validation, a Free-plan limit
tests/ + scripts/smoke.mjs25 vitest tests (in-memory Postgres, fake signed Stripe events, user isolation) and an end-to-end smoke test of the production build. No keys needed
.cursor/rules/*.mdc5 Cursor rules: workflow (always on), Next.js 16 (async cookies/params, proxy.ts, no next lint), auth, billing, data
CLAUDE.md + AGENTS.mdThe same rules for Claude Code, Codex, OpenCode and other agents
docs/SETUP.md (first run, Stripe test mode with the Stripe CLI, GitHub sign-in, production), AGENT-PLAYBOOK.md (copy-paste prompts: your own feature, yearly plan, trial, password reset, admin page, failed payments, pre-launch review)
README.md + LICENSE.mdQuick start, scripts, and the license: use it for any number of your own apps, free or commercial

Peek inside

.cursor/rules/30-billing.mdc · One of the 5 Cursor rules, shown in full.

---
description: Stripe billing rules (checkout, portal, webhooks, plan limits)
globs: src/lib/billing.ts, src/lib/plans.ts, src/app/api/billing/**, src/app/api/stripe/**
alwaysApply: false
---
# Billing (Stripe)

- Flow: dashboard POSTs to `/api/billing/checkout` -> Stripe Checkout (subscription mode) -> Stripe sends `customer.subscription.*` webhooks -> `handleStripeEvent` updates the `subscription` table -> `planFor()` reads it.
- The success redirect proves nothing. Never grant Pro from a query string or the success page; only webhooks change subscription state.
- `handleStripeEvent` runs in one transaction, records the event id in `stripe_event` (duplicates are no-ops) and skips events older than the stored `lastEventAt`. Keep both properties when you change it, and add a test in `tests/billing.test.ts` with a fake event.
- A new event type: add it to `HANDLED_EVENTS`, handle it, test it, and tell the user to add it to the webhook endpoint in the Stripe Dashboard.
- Plan limits and which statuses count as Pro live only in `src/lib/plans.ts`.
- Test keys (`sk_test_...`) until launch. Never print or commit keys or `whsec_` secrets. Don't run Stripe CLI commands unless the user asks.

Stripe emails your receipt. Lost your download link? Email us with the receipt and we'll sort it out. Questions: support@agentcartridge.com