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 create barrel index files that nothing uses
Add a barrel (index.ts) only when it provides a real, used public entry point; otherwise import modules directly.
Bad example
| 1 | // feature/dto/index.ts |
| 2 | export * from './create-order.dto'; |
| 3 | export * from './order-response.dto'; |
| 4 |
|
| 5 | // ...but every consumer still imports directly: |
| 6 | import { CreateOrderDto } from 'feature/dto/create-order.dto'; |
Explanation (EN)
The barrel re-exports DTOs nobody imports through it. It adds an unused indirection layer and can defeat tree-shaking.
Objašnjenje (HR)
Barrel re-exporta DTO-ove kroz koje nitko ne uvozi. Dodaje neiskoristen sloj posredovanja i moze unistiti tree-shaking.
Good example
| 1 | // no index.ts; consumers import the module they need directly |
| 2 | import { CreateOrderDto } from 'feature/dto/create-order.dto'; |
| 3 | import { OrderResponseDto } from 'feature/dto/order-response.dto'; |
Explanation (EN)
Direct imports keep the dependency graph explicit and avoid maintaining a file that earns nothing.
Objašnjenje (HR)
Izravni uvozi cuvaju graf ovisnosti eksplicitnim i izbjegavaju odrzavanje datoteke koja nista ne donosi.
Notes (EN)
A barrel is justified for a published package's public API or when many external callers genuinely import from one entry point.
Bilješke (HR)
Barrel je opravdan za javni API objavljenog paketa ili kad mnogo vanjskih pozivatelja stvarno uvozi s jedne ulazne tocke.
Exceptions / Tradeoffs (EN)
Public package entry points and genuinely shared facades where a single import path is the intended contract.
Iznimke / Tradeoffi (HR)
Javne ulazne tocke paketa i stvarno dijeljene fasade gdje je jedna putanja uvoza namjeravani ugovor.