Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Split server and client API boundaries
GETs go through api.server.ts; non-GETs go through the proxy + api.client.ts to keep boundaries explicit and auditable.
Bad example
| 1 | // Mixing GET and POST in the client |
| 2 | export async function fetchUser() { |
| 3 | return fetch("/api/user"); |
| 4 | } |
| 5 |
|
| 6 | export async function updateUser(body: UpdateUserBody) { |
| 7 | return fetch("/api/user", { method: "POST", body: JSON.stringify(body) }); |
| 8 | } |
Explanation (EN)
Mixing GETs and non-GETs in the same client layer blurs boundaries and makes auditing/SSR harder. It also bypasses the intended proxy route for non-GETs.
Objašnjenje (HR)
Miješanje GET i non-GET poziva u istom client sloju muti granice i otežava audit/SSR. Također zaobilazi predviđeni proxy za non-GET.
Good example
| 1 | // GET via server layer |
| 2 | import { getUser } from "@/utils/api.server"; |
| 3 |
|
| 4 | // non-GET via proxy client |
| 5 | import { updateUser } from "@/utils/api.client"; |
Explanation (EN)
Separating GET and non-GET paths keeps SSR clean and makes proxy usage explicit for mutations.
Objašnjenje (HR)
Razdvajanje GET i non-GET puteva drži SSR čistim i čini proxy eksplicitnim za mutacije.
Notes (EN)
Non-GET requests must go through src/app/api/proxy/[...catchAll]/route.ts via api.client.ts.
Bilješke (HR)
Non-GET zahtjevi moraju ići kroz src/app/api/proxy/[...catchAll]/route.ts preko api.client.ts.