Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s
1.3 KiB
1.3 KiB
| name | description |
|---|---|
| adding-an-api-route | Use when adding a new Next.js API route to this project. Keeps routes thin and logic in the right layer instead of inline in the route file. |
Adding a new API route
- Check
study-app-implementation-plan.md's Section 9 file tree first. If this route is already named there, follow that path and method exactly rather than inventing a different shape. - Create the route file under
src/app/api/<resource>/route.ts, orsrc/app/api/<resource>/[id]/route.tsfor a single-resource endpoint. - The route handler does exactly three things: validate the request body
(reuse a Zod schema from
lib/validation/if one already exists for this shape, write one if it doesn't), call one function in the matchingservices/<resource>Service.ts, and return aNextResponse. No Prisma calls and no business logic directly in the route file. - If the logic doesn't fit an existing service file, add a new exported
function to the closest matching one. Only create a new
services/<resource>Service.tsif this is genuinely a new resource, don't bolt unrelated logic onto an existing service to avoid creating a file. - Run
npm run lintbefore considering the route done. A failingmax-linesorfilename-caseerror means something is in the wrong place, not that the rule needs an exception.