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).
Don't duplicate the same fields across response levels
Avoid repeating identical data at both top level and inside a nested object; expose each field in one authoritative place.
Bad example
| 1 | { |
| 2 | "id": 5325943, |
| 3 | "logoUrl": "https://cdn/logo/5325943", |
| 4 | "companyName": "Arctic Bioscience", |
| 5 | "instrument": { |
| 6 | "id": 5325943, |
| 7 | "logoUrl": "https://cdn/logo/5325943", |
| 8 | "name": "Arctic Bioscience", |
| 9 | "fullName": "ABS" |
| 10 | } |
| 11 | } |
Explanation (EN)
id, logoUrl and the company name appear both at the top level and inside `instrument`; only `fullName` is genuinely new. Clients can't tell which copy is authoritative and the payload is larger than needed.
Objašnjenje (HR)
id, logoUrl i naziv tvrtke pojavljuju se i na vrhu i unutar `instrument`; samo je `fullName` stvarno nov. Klijenti ne mogu znati koja je kopija mjerodavna, a payload je veći nego što treba.
Good example
| 1 | { |
| 2 | "id": 5325943, |
| 3 | "logoUrl": "https://cdn/logo/5325943", |
| 4 | "companyName": "Arctic Bioscience", |
| 5 | "fullName": "ABS" |
| 6 | } |
Explanation (EN)
Each field lives in exactly one place. The new `fullName` is added flat instead of nesting a near-duplicate instrument object.
Objašnjenje (HR)
Svako polje postoji točno na jednom mjestu. Novi `fullName` dodan je ravno umjesto ugnježđivanja gotovo duplog instrument objekta.
Exceptions / Tradeoffs (EN)
A nested object is justified when it represents a distinct, separately-fetchable resource clients need as a self-contained unit - not just to re-list fields already present at the top.
Iznimke / Tradeoffi (HR)
Ugnježđeni objekt je opravdan kad predstavlja zaseban resurs koji se dohvaća odvojeno i koji klijenti trebaju kao samostalnu cjelinu - a ne samo da bi ponovno nabrojio polja koja već postoje na vrhu.