Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: node
architecturevalidationlatencyapiseparation-of-concerns
Don't duplicate backend business-rule validation in the API gateway layer
Avoid an extra fetch from your BFF/Next API just to validate a rule the downstream backend will validate anyway; let the backend return the proper error code instead.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | // /api/create-reply |
| 2 | const thread = await fetchThread(threadId); // extra round trip |
| 3 | if (thread.closedAt) return res.status(403).end(); |
| 4 | await postReply(...); // backend validates this again |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // /api/create-reply |
| 2 | const result = await postReply(...); |
| 3 | if (!result.ok) return res.status(result.status).json(result.error); // trust backend rule |
Explanation (EN)
Objašnjenje (HR)