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 ruleP2stack specificStack: typescript
service-designencapsulationconfig
Keep service config inside the class, not at module scope
Store a service's configuration (such as its base API URL) as a private property of the class rather than instantiating it at module level.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | const api: string = process.env.API_WS_ENVIRONMENT; |
| 2 | export default class WsForumService { /* uses api */ } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | export default class WsForumService { |
| 2 | private static api = process.env.API_WS_ENVIRONMENT; |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)