{"success":true,"name":"keep-layers-in-their-lanes-each-one-validates-none-trusts-bl","description":"Building across frontend, API, and DB with logic and trust leaking between layers","category":"ai-brimind","path":"ai-brimind/keep-layers-in-their-lanes-each-one-validates-none-trusts-bl/SKILL.md","file":"SKILL.md","content":"---\nname: keep-layers-in-their-lanes-each-one-validates-none-trusts-bl\ndescription: \"Building across frontend, API, and DB with logic and trust leaking between layers\"\n---\n\n# Keep Layers in Their Lanes: Each One Validates, None Trusts Blindly\n\n## When to use\nBuilding across frontend, API, and DB with logic and trust leaking between layers\n\n## Example request\nPrice calculated in the frontend and sent to the API → any user can send price: 0 from the browser console; the concept is never trusting the client (server recomputes, client only displays). Validation done only in the form → direct API calls bypass it entirely; the concept is the backend as the real gate (frontend validation is UX, backend validation is security). Route handler contains 80 lines of DB queries and business rules → nothing is reusable or testable; the concept is route → service → data-access layering. DB accepts bookings with end before start → the last line of defense (schema constraints, required fields, unique indexes) was never set; the concept is defense in depth.\n\n## Instructions\nAct as a border guard for every layer of the stack, enforcing two rules: each layer does its own job, and no layer trusts incoming data it didn't verify. Structure the lanes: (1) FRONTEND — displays data and collects input; it validates forms for user experience (instant feedback), but holds NO authoritative business logic: prices, permissions, and totals are computed by the server, the client only renders them; anything a browser sends can be forged; (2) API/ROUTE LAYER — thin: it parses the request, validates the payload against the contract (shape, types, required fields — reject bad input with the standard error before any logic runs), checks authentication and authorization on EVERY protected route (never assume 'the UI hides that button' protects anything), then delegates; (3) SERVICE/LOGIC LAYER — where business rules live, written as plain functions independent of HTTP, so they're testable and reusable across routes, crons, and scripts; (4) DATA LAYER — the only place that touches the DB, plus the DB's own constraints as the final wall: required fields, types, unique indexes, and sane rules enforced in the schema, because every code path can have a bug but the schema catches them all. When you find logic in the wrong lane, move it during the feature work rather than duplicating it. The payoff of lanes plus boundary validation is exactly 'fewer errors, works first shot': bad data is stopped at the first border with a clear message, instead of traveling three layers deep and exploding somewhere unrelated.\n\n## Metadata\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #175\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}