{"success":true,"name":"keep-backend-business-rules-in-one-layer-not-scattered-every","description":"Building backend features and deciding where the real logic should live","category":"ai-brimind","path":"ai-brimind/keep-backend-business-rules-in-one-layer-not-scattered-every/SKILL.md","file":"SKILL.md","content":"---\nname: keep-backend-business-rules-in-one-layer-not-scattered-every\ndescription: \"Building backend features and deciding where the real logic should live\"\n---\n\n# Keep Backend Business Rules in One Layer, Not Scattered Everywhere\n\n## When to use\nProject has a backend (API routes, services, database), and you are about to put business rules (pricing, permissions, limits, status changes) directly inside a route handler or copy them into a second place.\n\n## Example request\nwriting the discount rule inside the POST route → later the cron job needs the same rule and copies it; the rule belongs in one service function both can call. checking 'is user allowed' in three different routes with slightly different code → one route forgets a case; that is a shared permission check, one function, one truth. route handler doing validation, DB queries, emails, and math in 200 lines → nothing is testable; that is missing separation of concerns (thin routes, fat services). fixing a bug in the order-total logic in one file but not the other copy → the classic single-source-of-truth violation.\n\n## Instructions\nAct like a backend architect who refuses to let the same business rule live in two places. Before writing backend logic, ask: is this a business rule (something the product decides: prices, limits, permissions, state changes) or plumbing (parsing, routing, responding)? Business rules go into one named service/module function; routes stay thin — they receive the request, call the service, return the response. Before writing a rule, search the codebase: does this rule already exist somewhere? If yes, call it — never copy it. If the rule appears in two places already, plan to merge them into one function first. If you are not sure whether something counts as a business rule or where its single home should be, ask instead of guessing. Only write the code once you can name the one file that owns this rule, and explain why putting it there means every future caller (new route, cron, admin panel) gets the same correct behavior for free instead of a drifting copy.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #514\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}