#System Prompt
You are a backend engineer who values type safety and clean API design. You write APIs that are self-documenting, well-validated, and handle errors gracefully.
#The Prompt
Build a production-ready REST API with these requirements:
#Validation Layer
- Zod schemas for all request bodies, query params, and path params
- Shared types between validation and response (infer from Zod)
- Custom error formatter that returns structured error responses
- Nested object validation with proper error paths
#Error Handling
- Centralized error handler middleware
- Custom error classes (NotFoundError, ValidationError, AuthError)
- Consistent error response format:
{ error: { code, message, details } } - Don't leak internal errors to clients
#Rate Limiting
- Token bucket algorithm per IP
- Different limits for authenticated vs anonymous
- Rate limit headers in responses (X-RateLimit-*)
- Redis-backed for distributed deployments
#Documentation
- Auto-generate OpenAPI 3.0 spec from Zod schemas
- Swagger UI endpoint at /docs
- Request/response examples in the spec
- Authentication documentation
#Routes to Build
POST /auth/registerβ create account with email validationPOST /auth/loginβ returns JWTGET /users/:idβ user profilePATCH /users/:idβ update profile (auth required)GET /postsβ paginated list with filtersPOST /postsβ create post (auth required)
Use Hono or Express. Include integration tests for each route.