Next.js 15 Full-Stack SaaS: From Zero to One Vibe Coding Workspace Setup & Real-World Testing
Building a Next.js 15 Auth & Database System with 94% Automated Delivery Using AGENTS.md and MCP Protocol

Completion Score
Overall completion reached 94%. The AI excelled in scaffolding, type inference, and API route generation, automatically handling complex Prisma schema migrations. The main bottlenecks were fine-tuning UI details for specific business logic and handling complex edge cases, which required human intervention for verification.
Dimension breakdown
The AI perfectly follows the App Router standard directory structure and automatically generates all necessary type definition files.
Form validation and optimistic update logic are generated accurately, but occasional fine-tuning is required for responsive adaptation in complex dynamic layouts.
API endpoint structures are clear and type-safe, but manual optimization may be needed for handling concurrent transactions and complex query optimization.
Basic build scripts are robust, but manual details are required for advanced configuration of multi-environment variable management and CI/CD pipelines.
Human checkpoint
Before deployment, human developers must review the authentication logic in all API routes (ensuring unauthorized requests are rejected) and the compatibility of database migration scripts (ensuring no data loss).
Upgrade / downgrade path
If budget or hardware is limited, replace SQLite with a lightweight PostgreSQL container and reduce the number of Tailwind plugins to speed up builds. For scaling, introduce a Redis caching layer and upgrade to Vercel Enterprise for advanced monitoring.
When to use & prerequisites
Ideal for independent developers or small teams looking to rapidly prototype SaaS applications. Prerequisites include Node.js 20+, Cursor IDE, and basic Git knowledge. Best suited for workflows that require quick MVP validation and aim to minimize repetitive boilerplate coding.
Ready-to-copy configs
定义 AI 代理在 Next.js 15 项目中的核心职责、工作流及代码生成规范。
# AGENTS.md - Next.js 15 Vibe Coding Agent Protocol
## Role
You are an expert Senior Full-Stack Engineer specializing in Next.js 15 App Router, TypeScript, and Prisma. Your goal is to build a production-ready SaaS starter.
## Core Principles
1. **Type Safety First**: All data access must use TypeScript interfaces derived from Prisma schema.
2. **App Router Native**: Use Server Components by default. Use `useOptimistic` for UI state, never client-side data fetching unless necessary.
3. **Security**: Never expose secrets in code. Use `process.env` with strict validation.
4. **Atomic Commits**: Generate one logical feature per turn (e.g., "Create User Schema" then "Create Auth Route").
## Workflow
1. **Analyze**: Read `.cursor/rules/nextjs-app-router.mdc` for context.
2. **Plan**: Propose a file tree change before writing code.
3. **Execute**: Write code, run `npx prisma db push` if schema changes, and verify types.
4. **Verify**: Ensure all routes return 200 OK and handle errors gracefully.
## Constraints
- Do not use `createClient` in Server Components; use Prisma client directly.
- Use Tailwind CSS for all styling.
- Keep API routes under `app/api/`.
- Use SQLite for local dev, PostgreSQL for production (configurable via env).
## Tools
- `npx prisma generate`
- `npx prisma db push`
- `npm run dev`
- `npm run build`
## Output Format
Always provide code blocks with language tags. Explain changes in 1-2 sentences before the code block.规范 Next.js 15 App Router 的目录结构、组件模式及数据获取策略。
# Next.js 15 App Router Coding Rules
## Directory Structure
```
app/
├── (auth)/ # Route groups (login, register)
├── api/
│ ├── auth/
│ └── users/
├── layout.tsx # Root layout with providers
├── page.tsx # Home
└── globals.css
```
## Component Patterns
1. **Server Components**: Default for data fetching and static rendering.
2. **Client Components**: Only when interactivity is needed (use `'use client'`).
3. **Forms**: Use `react-hook-form` + `zod` for validation. Submit to `POST /api/...`.
4. **Loading States**: Use `loading.tsx` files in route folders.
## Data Fetching
- **Read**: `await prisma.user.findMany()` in Server Components.
- **Write**: `await prisma.$transaction([...])` for atomicity.
- **Caching**: Use `revalidatePath` after mutations.
## Styling
- Use Tailwind CSS utility classes exclusively.
- Use `cn()` from `clsx` for conditional class merging.
## Error Handling
- Wrap API routes in `try/catch`.
- Return `{ success: false, error: '...' }` for client consumption.
- Use `ErrorBoundary` for React components.
## Security
- Validate all inputs using Zod schemas.
- Sanitize output using DOMPurify if rendering user content.
- Rate limit API routes using `@upstash/ratelimit`.配置 Cursor 的 MCP (Model Context Protocol) 工具,连接本地数据库和文件服务。
{
"mcpServers": {
"prisma": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-prisma"],
"env": {
"DATABASE_URL": "${env:DATABASE_URL}"
}
},
"file-system": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-file-system"],
"env": {
"ALLOWED_PATHS": "/home/user/projects/nextjs-saas-vibe-starter"
}
},
"docker": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-docker"],
"env": {
"DOCKER_HOST": "unix:///var/run/docker.sock"
}
}
}
}AI Vibe Coding in 4 steps
- 1
Initialize Project Structure & Agent Protocol
Goal: Create a Next.js 15 project and deploy AGENTS.md and MCP configuration to activate the intelligent workflow.
PromptInitialize a Next.js 15 project with TypeScript and Tailwind CSS. Create AGENTS.md defining the role as a Senior Full-Stack Engineer and configure .cursor/mcp.json to enable Prisma and File System servers. Ensure the directory structure follows the App Router standard.Verify:
Run `ls -R` to verify directory structure and check if `AGENTS.md` and `.cursor/mcp.json` exist with correct content. - 2
Define Database Schema & Types
Goal: Establish the Prisma Schema and generate corresponding TypeScript type definitions.
PromptCreate a Prisma schema at `prisma/schema.prisma` with a `User` model containing `id`, `email`, `passwordHash`, and `createdAt`. Run `npx prisma generate` and verify that `User` type is exported in `types/index.ts`.Verify:
Run `npx prisma db push` to apply schema and check for any TypeScript errors in the generated types. - 3
Build Auth API & Form Components
Goal: Implement user registration/login API routes and frontend form interaction logic.
PromptCreate `app/api/auth/register/route.ts` and `app/api/auth/login/route.ts` using Zod for validation. Build a `RegisterForm` client component in `app/(auth)/register/page.tsx` that uses `react-hook-form` and submits to the API route with optimistic UI updates.Verify:
Test the registration flow by submitting a form with valid data and verifying the user is created in the database. - 4
Configure Build Scripts & Environment Variables
Goal: Set up environment variable templates and verify the build process.
PromptCreate `.env.example` with placeholders for `DATABASE_URL`, `NEXT_PUBLIC_APP_URL`, and `API_KEY`. Update `package.json` scripts to include `build` and `dev` commands, and verify the build succeeds without errors.Verify:
Run `npm run build` and ensure no errors are reported; check that `.env.example` contains all required variables.
Pitfalls & fixes
- Forgetting to import `'use client'` in Client components will cause runtime errors; ensure all interactive components are checked.
- Prisma migration failures are usually due to incorrect database connection string formats; ensure `DATABASE_URL` is configured correctly.
- CORS errors in API routes are common in development environments; ensure the `headers` middleware is correctly configured in `next.config.js`.
FAQ
How do I replace SQLite with PostgreSQL in a production environment?
Simply modify the `DATABASE_URL` in `.env` to a PostgreSQL connection string and run `npx prisma migrate dev` to automatically adjust the migrations.
Does AGENTS.md affect AI performance?
No, AGENTS.md serves only as a context prompt. The AI adjusts its generation strategy based on its content without significantly increasing inference time.
How do I handle loading states after form submission?
Use `react-hook-form`'s `handleSubmit` with a `loading` state variable, and disable the button during submission to display a loading indicator.


