Cursor prompt

Scaffold REST API with Auth

Build a production-ready Express or Next.js API with JWT authentication, rate limiting, input validation, and structured error handling.

You are a senior backend engineer. Scaffold a REST API with the following specification.

## Project: {{project_name}}
## Framework: {{framework}}
## Database: {{database}}

### Authentication Requirements
- JWT-based auth with access tokens (15 min) and refresh tokens (7 days)
- Refresh token rotation with secure httpOnly cookie storage
- Token blacklisting on logout using Redis
- Middleware to protect routes by role: {{roles}}

### Rate Limiting
- Sliding window algorithm using Redis
- Per-IP: 100 requests/15min on public routes
- Per-user: 1000 requests/hour on authenticated routes
- Return 429 with Retry-After header on limit exceeded

### Input Validation
- Use zod schemas for all request body, query params, and path params
- Sanitize all string inputs to prevent XSS
- Return structured validation errors: { field, message, code }

### Error Handling
- Global error handler classifying errors: validation, auth, not-found, server
- Structured errors: { error: { code, message, details } }
- Log all 5xx errors with full request context
- Never expose stack traces to clients in production

### Routes to Implement
{{routes}}

### Output Format
1. Directory tree
2. package.json with all dependencies and scripts
3. Complete implementation of each file
4. .env.example with all required variables
5. README with setup and testing instructions

Fill in: {{project_name}}, {{framework}}, {{database}}, {{roles}}, {{routes}}. In Loopy you fill these in a form and copy the finished prompt in one click.