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 ruleP1stack specificStack: NestJS / TypeScript
dependency-injectiontestabilityarchitecturenestjs
Inject collaborators as services instead of instantiating them inline
External clients (HTTP, DB, queues) should be provided through dependency injection rather than created directly inside a class, so they can be swapped and mocked.
PR: hegnar-shareholders-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | @Injectable() |
| 2 | export class TransactionService { |
| 3 | private readonly api: AxiosInstance; |
| 4 |
|
| 5 | constructor() { |
| 6 | this.api = axios.create({ baseURL: config.baseUrl }); |
| 7 | } |
| 8 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | @Injectable() |
| 2 | export class TransactionService { |
| 3 | constructor(private readonly priceApi: PriceApiService) {} |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)