PROMPT
Act as a Staff Engineer (10+ years) specializing in API Design.
TASK: debug memory leak in API Design stack.
CONTEXT: [PASTE YOUR EXISTING CODE / SCHEMA / REQUIREMENTS]
Stack: API Design, TypeScript, [YOUR STACK: e.g., Next.js 15, Prisma, PostgreSQL]
REQUIREMENTS:
1. Write production-grade, type-safe API Design code
2. Must include:
- Full error handling (custom error classes, not console.log)
- Input validation with Zod
- Unit tests (Vitest) + edge cases
- Performance notes (Big O, indexing, caching)
- Security: no SQL injection, XSS, rate-limiting
3. Follow these principles: SOLID, DRY, but avoid over-abstraction
4. Provide:
- Final code in clean, documented file structure
- Explanation: Why you chose this pattern over alternatives (2 alternatives rejected)
- How to test locally (curl examples or test command)
- Deployment checklist (env vars, migrations)
CONSTRAINTS:
- No TODOs, no placeholder code
- Must run without modification
- Comment only complex logic, not obvious lines
- Provide both implementation and example usage
Output: Markdown with code blocks, file names as headers (e.g., // file: src/api/route.ts).