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
architecturesingletonservicesconsistency
Implement stateless service/provider classes as singletons or static, consistently
When a service or provider class is never meant to have multiple instances, make it a singleton or a static class, and apply the same pattern across all such classes.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | export class ArticleBoxProvider { /* instance methods */ } |
| 2 | const provider = new ArticleBoxProvider(); // new instance everywhere |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | class ArticleBoxProvider { /* methods */ } |
| 2 | export const articleBoxProvider = new ArticleBoxProvider(); // single shared instance |
Explanation (EN)
Objašnjenje (HR)