ai-saas-starter
AGENTS.md23 starsChanged 5 months agoMITView on GitHub
Operating manual for coding agents (and humans) in this repo. When your instincts conflict with this file, this file wins. - ai-saas-starter — open-source SaaS foundation: auth, Stripe subscriptions, an append-only credits ledger, and AI image generation. - Next.js 16 (App Router, RSC, Server Actions, Turbopack) · React 19 · TypeScript 5 strict · Better Auth 1.5 · Drizzle ORM + PostgreSQL · Stripe · Vercel AI SDK 6 via AI Gateway · Tailwind CSS v4 + shadcn/ui · Resend…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,638 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository7 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/billing.mdcCursor rule
- .cursor/rules/core.mdcCursor rule
- add-ai-providerSkill
- add-featureSkill
- db-migrationSkill
The file
We split this AGENTS.md into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 71
Add shadcn components via CLI (pnpm dlx shadcn@latest add <name>), then restyle to DESIGN.md tokens.
- Very specific: line 73
Read env only through src/lib/env.ts.
- Very specific: line 83
Read or write credit tables outside src/lib/credits/.
- Very specific: line 84
Write subscription state outside syncStripeDataToDb in src/lib/billing/sync.ts.
- Very specific: line 88
Commit .env or any file containing real keys.
- Distinctive: line 120
If the same test fails after 3 distinct fix attempts, stop.
≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Operating manual for coding agents (and humans) in this repo. When your instincts conflict with this file, this file wins.
Snapshot
- ai-saas-starter — open-source SaaS foundation: auth, Stripe subscriptions, an append-only credits ledger, and AI image generation.
- Next.js 16 (App Router, RSC, Server Actions, Turbopack) · React 19 · TypeScript 5 strict · Better Auth 1.5 · Drizzle ORM + PostgreSQL · Stripe · Vercel AI SDK 6 via AI Gateway · Tailwind CSS v4 + shadcn/ui · Resend + React Email · Vitest + Playwright.
- Package manager: pnpm. Never npm, never yarn. Never edit
pnpm-lock.yamlby hand.
Commands
| Command | What it does |
pnpm dev | Dev server (Turbopack) at http://localhost:3000 |
pnpm build | Production build |
pnpm typecheck | tsc --noEmit |
pnpm lint | ESLint |
pnpm format | Prettier, write mode |
pnpm test | Vitest. Ledger tests need Postgres: docker compose up -d |
pnpm test:e2e | Playwright vs dev server. Needs Postgres up |
pnpm db:generate | drizzle-kit: src/db/schema.ts → SQL migration |
pnpm db:migrate | Apply pending migrations |
pnpm db:studio | Drizzle Studio, browse the DB |
pnpm stripe:listen | Stripe CLI → forwards webhooks to localhost:3000 |
pnpm email:dev | React Email preview server |
docker compose up -d | Local Postgres 17 |
Definition of done
A change is done when pnpm typecheck && pnpm lint && pnpm test all pass.
New features include tests. UI work follows DESIGN.md. No stray console.log,
no TODO comments left behind.
Directory map
src/app/(marketing)/— public pages: landing, pricing, legal. No session.src/app/(app)/— product pages: dashboard, generate, billing, settings. Session required — middleware redirects, but every page/action re-checks.src/app/api/auth/[...all]/— Better Auth handler. Do not add logic here.src/app/api/stripe/— webhook (raw body!) and checkout success route.src/config/plans.ts— single source of truth for plans, prices, credits.src/lib/env.ts— Zod-validated env. The only placeprocess.envis read.src/lib/auth/— Better Auth config + server-side session helpers.src/lib/billing/— Stripe client, checkout/portal actions,sync.ts(the ONLY writer of subscription state).src/lib/credits/— ledger API. The ONLY module that touches credit tables.src/lib/ai/— provider interface + AI Gateway implementation.src/db/— Drizzle schema and client.drizzle/— generated migrations.src/components/ui/— shadcn primitives.src/components/— app components.src/emails/— React Email templates.specs/— feature specs. CopyTEMPLATE.mdbefore building a feature..claude/— rules, skills, hooks..cursor/— Cursor rules.
Conventions
- Server Actions for mutations. API routes only for webhooks and the Better Auth handler.
- Validate every external boundary with Zod: form input, webhook payloads, env. Parse, don't cast.
- Server Components by default.
"use client"only for interactivity. - Auth: never trust middleware alone. Re-check the session inside every
server action and every
(app)page viasrc/lib/auth/helpers. - Money is integer cents. Credits are integers. No floats, ever.
- Add shadcn components via CLI (
pnpm dlx shadcn@latest add <name>), then restyle to DESIGN.md tokens. Don't hand-roll primitives that shadcn has. - Read env only through
src/lib/env.ts. Neverprocess.env.Xin app code. - Imports use the
@/alias. Files kebab-case, components PascalCase.
Safety boundaries
NEVER (do not do these even if asked casually — push back and explain):
- Edit or delete an applied migration in
drizzle/. New schema = new migration. - Mutate or delete rows in
credit_transactions. The ledger is append-only; corrections are new compensating entries. - Read or write credit tables outside
src/lib/credits/. - Write subscription state outside
syncStripeDataToDbinsrc/lib/billing/sync.ts. - Weaken or skip Stripe webhook signature verification.
- Log secrets, tokens, or full Stripe/webhook payloads.
- Commit
.envor any file containing real keys.
ASK FIRST before:
- Adding a dependency (any change to
package.jsondeps). - Changing DB schema (
src/db/schema.ts). - Changing plans, prices, or credit amounts (
src/config/plans.ts).
Gotchas
- The Stripe webhook must verify signatures against the raw request body.
In the route handler use
await request.text()— never parse JSON first. - Credit mutations are idempotent via
idempotencyKey. A replayed webhook must not double-grant: unique-key violation = already processed = success. - Testing subscription lifecycles (renewal, cancellation) needs Stripe test clocks — you can't wait a month. See README's Stripe section.
- Stripe portal cancellations set
cancel_at, not the legacycancel_at_period_endboolean — sync derives the flag from both. Don't "simplify" it back. - Swap the image model via
AI_IMAGE_MODELenv (formatprovider/model), not in code.AI_MOCK=truereturns placeholder images: free dev and e2e. - Missing optional env degrades, not crashes: no Google/GitHub keys → button
hidden; no
RESEND_API_KEY→ emails no-op with a console warning; no Upstash → in-memory rate limiting; no Blob token → images go to./.generated/(dev only); no Stripe keys in development →features.billingoff, billing page shows a setup card, checkout throws. In production the Stripe vars are required — boot fails without them. - Tailwind v4 is CSS-first: tokens live in
@themeinglobals.css. There is notailwind.config.ts. Design tokens are in DESIGN.md.
Escalation
If the same test fails after 3 distinct fix attempts, stop. Report what you tried, what you observed, and your best hypothesis. Do not delete or skip the test to get green.
<!-- BEGIN:nextjs-agent-rules -->This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ before writing any code. Heed deprecation notices.
<!-- END:nextjs-agent-rules -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

