Generate robust Next.js API routes with Zod validation, error handling, rate limiting, and TypeScript types.
Create a Next.js App Router API route at app/api/[endpoint]/route.ts. Requirements:
- Export async GET/POST/PUT/DELETE handler functions
- Use Zod schemas for request body and query parameter validation
- Implement proper error handling with try/catch and typed error responses
- Return consistent JSON response shape: { data, error, message }
- Add proper HTTP status codes (200, 201, 400, 401, 403, 404, 500)
- Include request body type inference from Zod schema
- Add rate limiting check if this is a public endpoint
- Use NextRequest and NextResponse from next/server
- Log errors to console with context (route, method, timestamp)
- Handle edge cases: empty body, malformed JSON, missing fields
- Follow existing API patterns in this project's codebaseGenerate optimized .cursorrules files tailored to your project's tech stack, conventions, and team preferences. Covers TypeScript, Python, Rust, Go, and more.
Leverage Cursor's Agent mode to build complete features end-to-end. Handles file creation, terminal commands, dependency installation, and multi-file edits in one flow.
Generate complete React components with TypeScript types, props interface, stories, and unit tests in one prompt.
Design database tables with proper types, constraints, indexes, and migration files for PostgreSQL/Supabase.
Generate FastAPI endpoints with Pydantic request/response models, dependency injection, and async database operations.
Generate thorough unit test suites with edge cases, mocking, and coverage for any function or module.