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).
Prefer API contract fixes over client-side metadata backfills
When the UI needs data that the API could reasonably return, improve the API contract instead of layering extra client fetches as the default solution.
Bad example
| 1 | const missingInstrumentIds = getMissingInstrumentIds(transactions, instruments); |
| 2 | const fetchedTickers = missingInstrumentIds.length |
| 3 | ? await fetchPortfolioTickers({ insrefs: missingInstrumentIds }) |
| 4 | : []; |
| 5 |
|
| 6 | const rows = transactions.map(transaction => |
| 7 | mapPortfolioTransactionToStockItem(transaction, instrumentMap.get(transaction.instrumentId)) |
| 8 | ); |
Explanation (EN)
The frontend is compensating for an incomplete API contract with extra fetches and merge logic. That increases coupling and hides a backend data-shape gap.
Objašnjenje (HR)
Frontend kompenzira nepotpun API contract dodatnim fetchovima i merge logikom. To povecava spregu i skriva rupu u backend data shapeu.
Good example
| 1 | // backend /transactions/recent returns instrument display metadata |
| 2 | interface RecentTransaction { |
| 3 | instrumentId: number; |
| 4 | name: string; |
| 5 | fullname: string; |
| 6 | logoUrl: string; |
| 7 | } |
| 8 |
|
| 9 | const rows = payload.transactions.data.map(mapPortfolioRecentTransactionToStockItem); |
| 10 |
|
| 11 | // If a temporary frontend fallback is unavoidable, keep it local and add a TODO |
| 12 | // to remove it after the backend contract is enriched. |
Explanation (EN)
The API returns render-ready fields the UI genuinely needs, so the client stays simpler. Temporary workarounds are acceptable only when clearly marked for removal.
Objašnjenje (HR)
API vraca render-ready polja koja UI stvarno treba, pa klijent ostaje jednostavniji. Privremeni workaroundi su prihvatljivi samo kada su jasno oznaceni za uklanjanje.
Exceptions / Tradeoffs (EN)
Keep a temporary client fallback only when the backend change is blocked and the feature must ship; add a TODO that names the API contract to improve.
Iznimke / Tradeoffi (HR)
Zadrzi privremeni client fallback samo kada je backend promjena blokirana, a feature mora ici van; dodaj TODO koji imenuje API contract koji treba poboljsati.