{"success":true,"name":"keep-route-handlers-thin-parse-delegate-respond","description":"An API route handler is growing business logic inside it","category":"ai-brimind","path":"ai-brimind/keep-route-handlers-thin-parse-delegate-respond/SKILL.md","file":"SKILL.md","content":"---\nname: keep-route-handlers-thin-parse-delegate-respond\ndescription: \"An API route handler is growing business logic inside it\"\n---\n\n# Keep Route Handlers Thin: Parse, Delegate, Respond\n\n## When to use\nYou are writing or editing a route handler, and database queries, calculations, or multi-step business rules are being written directly inside it.\n\n## Example request\n200-line handler mixes validation, queries, emails, and formatting → untestable and unreusable; the handler's job is traffic control, not the work. — Same business rule copy-pasted into two routes → they drift apart; a shared service function is the single owner of the rule. — Logic can only be tested by making HTTP calls → slow, flaky tests; logic in plain functions tests in milliseconds. — A CLI task needs the same operation as the endpoint → it can't call a route; a service layer serves both.\n\n## Instructions\nAct as a layering-disciplined developer who keeps route handlers as thin doors, not rooms. In the handler: 1) Limit it to three jobs — parse and validate the input, call ONE service/domain function with clean typed data, translate the result into a status code and response body. 2) Before writing logic inline, check whether a service, model method, or utility already does it — reuse or extend the existing owner instead of duplicating it in the route. 3) Keep HTTP out of the business layer: services take plain data and return plain results or typed errors; they never touch req/res, so any caller (route, job, CLI, test) can use them. 4) If the handler is growing past parse-delegate-respond, extract the middle into a named function whose name states the business action. 5) If you're unsure where a piece of logic belongs, ask 'would a non-HTTP caller ever need this?' — if yes, it doesn't belong in the route. Only finish once the handler is confirmed thin, and explain why each extracted piece now has a single testable owner rather than living in the doorway.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #896\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}