Table of Contents
- What this playbook gives you (and why it works)
- Prompt Templates (UI, DB, auth, payments)
- UI prompt (Next.js + React + Tailwind)
- DB prompt (MongoDB models + queries)
- Auth prompt (magic link + Google OAuth)
- Payments prompt (Stripe OR Lemon Squeezy)
- AI bug fixing prompts (fast, surgical)
- AI refactor prompts (clarity without surprises)
- AI UI prompts (micro-interactions that convert)
- The “Triangle” Prompt (context → spec → constraints)
- From vague to precise (before/after)
- A full Triangle example
- Guardrails: security, performance, readability
- Workflow that keeps you fast (and sane)
- When not to use AI (and what to do instead)
- FAQ
- Wrap-up

Do not index
Do not index
If you want AI to help you ship a real SaaS faster, use structured prompts—not vibes. Feed context, give a clear spec, and set hard constraints (tests, performance budgets, security checks).
Then iterate in small, reviewable chunks. Copy the templates below, paste them into your AI tool, and get moving.
Want the full stack build (Next.js, auth, DB, emails, subscriptions) so your prompts translate to a working app? Join CodeFast.
What this playbook gives you (and why it works)
- Proven prompt skeletons for UI, DB, auth, and payments—the core of most SaaS apps.
- AI bug-fixing prompts, AI refactor prompts, and AI UI prompts that reduce back-and-forth.
- The Triangle Prompt framework you can reuse everywhere: Context → Spec → Constraints.
- A guardrail checklist for security, performance, and readability.
- When not to use AI (and what to do instead).
Use this as a library. Replace the bracketed parts, paste, run, review, ship.
Prompt Templates (UI, DB, auth, payments)
Tip: Keep prompts under 400–600 words, attach or paste the relevant code, and ask for a diff. You want small patches you can review, not a 3,000-line mystery.
UI prompt (Next.js + React + Tailwind)
Goal: Build a clean, minimal page that converts.
You are my AI pair-programmer. Work in Next.js (App Router), React Server Components where sensible, and Tailwind.
CONTEXT:
- Project: [SaaS name]
- Page: [e.g., /pricing]
- Current files: [list or paste snippets]
- Design tone: clean, focused, fast to first action
SPEC:
- Build a [hero + 3 benefits + pricing tiers + FAQ accordion]
- Mobile-first, responsive container, semantic HTML
- Add test IDs where meaningful (data-testid)
CONSTRAINTS:
- Keep components small and composable
- Avoid inline styles; use Tailwind utilities
- Export a single `<PricingPage />` and child components
- Return a unified patch/diff touching only these files: [file1, file2]
- Add an accessibility pass: proper headings, labels, alt text
Follow-up prompts:
- “Reduce CLS and improve first contentful paint.”
- “Extract pricing tier to
<TierCard />
with props and prop types.”
- “Add an empty-state for zero features—no console warnings.”
DB prompt (MongoDB models + queries)
Goal: A pragmatic data model that’s easy to evolve.
You are my AI pair-programmer. Use MongoDB with Mongoose.
CONTEXT:
- Feature: [e.g., Projects and Tasks in a tiny SaaS]
- Scale: low volume to start, simple analytics later
SPEC:
- Create Mongoose schemas + models for:
- User { email, role, subscriptionStatus, provider, currentPeriodEnd }
- Project { ownerId, name, createdAt }
- Task { projectId, title, status, dueAt, createdAt }
- Add basic indexes and a query to fetch:
- "All active tasks for a user’s current project" with pagination
CONSTRAINTS:
- Validate required fields; minimal enums for status
- Add lean() where returning read-only
- Avoid N+1 queries; show the aggregation or join pattern you choose
- Return a patch/diff for /lib/db/* only
Follow-up prompts:
- “Add soft-delete (deletedAt) and ensure queries exclude deleted.”
- “Introduce optimistic concurrency for updates on Task.”
Auth prompt (magic link + Google OAuth)
Goal: Reliable login with minimal friction.
You are my AI pair-programmer. We need auth with magic link + Google OAuth.
CONTEXT:
- Next.js App Router
- Email provider: [e.g., Resend]
- Session: JWT in HttpOnly cookie
SPEC:
- Implement "Sign in with email" (magic link) and "Continue with Google"
- Store user { userId, email, provider }
- After first login: redirect to /dashboard and run onboarding
CONSTRAINTS:
- Secure cookie flags (HttpOnly, Secure, SameSite)
- CSRF protection on POST routes
- Rate-limit magic link requests by IP + email
- Return handlers, routes, and a single `useAuth()` hook
- Provide test flow: local dev + dummy values
Follow-up prompts:
- “Add a
requireActiveSubscription
middleware for protected routes.”
- “Return explicit error codes for auth failures and throttle responses.”
Payments prompt (Stripe OR Lemon Squeezy)
Goal: Subscriptions that actually charge people.
You are my AI pair-programmer. Add subscriptions.
CONTEXT:
- Plans: Starter $[x]/mo, Pro $[y]/mo, annual with 2 months free
- Provider: [Stripe Billing | Lemon Squeezy]
- User has fields: subscriptionStatus, planId, currentPeriodEnd
SPEC:
- Create a pricing page with 2 tiers + annual toggle
- Implement hosted checkout first (fastest path)
- Webhook: on payment succeeded → set user active + currentPeriodEnd
- Webhook: on cancellation/failed payment → set past_due or canceled
- Self-serve: [Stripe Portal | LS customer management flow]
CONSTRAINTS:
- Verify webhook signatures; idempotency on event processing
- Keep business logic in /lib/billing/*
- Add a minimal receipts email and trial-ending email
- Return a patch/diff for pricing + billing only
Follow-up prompts:
- “Add coupons and test proration on upgrade.”
- “Instrument dunning/retries and log all billing events for 30–60 days.”
Want the end-to-end flow wired for you (auth → DB → email → subscriptions → launch)? Start now.
AI bug fixing prompts (fast, surgical)
Use these when a single test or endpoint is failing.
You are my AI debugger. Work only in the files shown.
CONTEXT:
- Failing test: [paste test + failure trace]
- Code under test: [paste relevant snippet]
- Expected behavior: [1–2 lines]
TASK:
- Explain root cause in 2–3 bullets
- Provide a minimal diff that fixes the bug
- List side effects + what to retest
CONSTRAINTS:
- No new dependencies
- Keep the patch under 30 lines
- Maintain existing public API
AI refactor prompts (clarity without surprises)
Use when code works but hurts to read.
You are my AI refactor partner.
CONTEXT:
- File(s): [paths]
- Pain points: [duplication, long function, mixed concerns]
TASK:
- Improve naming, extract pure functions, remove dead code
- Keep behavior identical (add a small test if missing)
CONSTRAINTS:
- Max patch 100 lines, explain changes in bullets
- No new runtime deps
- Add JSDoc for exported functions
AI UI prompts (micro-interactions that convert)
Great for polishing quickly without yak-shaving.
You are my UI polish partner.
CONTEXT:
- Component: [e.g., Pricing CTA section]
- Audience: first-time visitors, mobile heavy
TASK:
- Add a subtle scroll-based fade-in
- Improve button focus/hover states with Tailwind
- Ensure accessible contrast and focus rings
CONSTRAINTS:
- Avoid layout shift
- Keep animations under 200ms
- Return only the component diff + a short test for styles via test IDs
The “Triangle” Prompt (context → spec → constraints)
Most prompts fail because they’re missing one side of the triangle. Fix that, and your “AI coding prompts for SaaS” start printing shippable code.
- Context: What exists? What stack, files, routes, users?
- Spec: What must change? What is the outcome in plain language?
- Constraints: What must not change? Limits, tests, budgets, APIs.
From vague to precise (before/after)
Prompt | Why it fails / wins |
“Build a pricing page for my app.” | No context, no spec, no constraints → generic output and rework. |
Triangle: “Next.js App Router, Tailwind. Files: /app/pricing/page.tsx (empty). Spec: 2 tiers (Starter $9, Pro $29), annual toggle, FAQ accordion, test IDs. Constraints: mobile-first, semantic HTML, return a single diff under 120 lines.” | Model knows the map. Output becomes reviewable and close to done. |
A full Triangle example
CONTEXT:
- Next.js App Router. Empty /app/pricing/page.tsx.
- Tailwind installed. Layout already wraps children.
SPEC:
- Add hero, 3 benefits, 2 pricing tiers, FAQ accordion.
- Annual toggle with computed prices (+ yearly saving note).
- CTA button triggers hosted checkout (placeholder function).
CONSTRAINTS:
- Accessible headings/labels; no inline styles.
- Keep components small; export <PricingPage /> default.
- Return a unified diff under 150 lines; no extra files.
Pro move: Save your best Triangle prompts as snippets. You’ll reuse them a lot.
Guardrails: security, performance, readability
Add this “guardrail block” to the end of any prompt:
- Security: Validate input, sanitize output, never log secrets, use HttpOnly cookies, CSRF on mutations, verify webhook signatures.
- Performance: Avoid N+1, use pagination, cache obvious reads, keep bundle small, avoid layout shift.
- Readability: Small components, clear names, JSDoc on exports, strict TypeScript types, no new deps unless justified.
- Testing: Include or update a minimal test for the change.
- Diff discipline: Single, reviewable patch; list any risks.
You’ll be shocked how many issues disappear when you force these rules into the prompt.
Workflow that keeps you fast (and sane)
- One feature = one branch = one prompt thread. Keep history tidy.
- Always ask for a diff. “Return a unified patch touching only X.”
- Two-pass approach: first generate → then “audit your patch vs constraints.”
- Local tests first. Don’t trust green text from the model.
- Name your prompts. Save reusable ones as snippets (UI, DB, auth, payments, AI bug fixing prompts, AI refactor prompts, AI UI prompts).
When you’re ready to turn these into a full, money-making app, Join CodeFast and follow the build alongside your prompts.
When not to use AI (and what to do instead)
- Critical secrets or compliance-sensitive code. Hand-write, review, and document.
- Migrations that risk data loss. Design on paper, write explicit steps, test against copies.
- Unknown domains. Read docs first; then prompt with a clear spec.
- Tiny tasks under 10–20 lines. Just code it faster than you can explain.
- High-stakes architecture decisions. Brainstorm with AI if you want, but decide after sketching trade-offs yourself.
Rule of thumb: Use AI for well-scoped changes with a fast feedback loop. Use your brain for irreversible moves.
FAQ
What’s the best way to structure AI coding prompts for SaaS?
Use the Triangle Prompt: context, spec, constraints. Attach the exact files or snippets you’re touching. Ask for a single diff.
How do I use AI for bug fixing without breaking other parts?
Paste the failing test + stack trace + the code under test. Ask for the root cause, a minimal patch, and what to retest. Keep the patch under a size limit.
Can AI design my pricing page and write the code?
Yes—if you provide the structure and guardrails. Give the sections, the tier details, and accessibility constraints. Then review the diff and test.
When should I ask AI to refactor?
When readability or duplication slows you down. Set constraints: no behavior changes, no new deps, explain changes in bullets, cap the patch size.
What about security and performance?
Bake them into your prompt: validate inputs, verify webhooks, avoid N+1, paginate, and keep components small. Ask the model to self-audit the patch against those checks.
How do I avoid endless back-and-forth?
Smaller scope, clearer constraints, and always request a diff. If you feel drift, restate the Triangle in the next message.
Wrap-up
- Structure beats wordy prompts. Context, spec, constraints—always.
- Ask for diffs and tests. Review like a pro.
- Keep your stack simple (Next.js, MongoDB, auth, payments), and your prompts will sing.
- When you want to turn these patterns into a real, paid app, Join CodeFast Now.