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).
Read environment variables through a central config module
Don't sprinkle `process.env.X` reads through the codebase — funnel all env access through one typed config object so parsing, defaults, and validation live in one place.
Bad example
| 1 | // server.ts |
| 2 | if (AppConfig.useRedisBuckets && process.env.ENABLE_AUTO_BACKFILL === 'true') { |
| 3 | await runBackfill(); |
| 4 | } |
| 5 |
|
| 6 | // elsewhere.ts |
| 7 | const retries = Number(process.env.MAX_RETRIES); // re-parsed, no default, untyped |
Explanation (EN)
Raw process.env reads are scattered and inconsistent: string comparisons, ad-hoc parsing, no single source of defaults or validation. One feature ends up half in AppConfig and half in raw env.
Objašnjenje (HR)
Sirovi process.env pozivi su raspršeni i nedosljedni: usporedbe stringova, improvizirano parsiranje, bez jedinstvenog izvora zadanih vrijednosti ili validacije. Jedna značajka završi pola u AppConfigu, pola u sirovom env-u.
Good example
| 1 | // config.ts |
| 2 | export const AppConfig = { |
| 3 | useRedisBuckets: process.env.USE_REDIS_BUCKETS === 'true', |
| 4 | enableAutoBackfill: process.env.ENABLE_AUTO_BACKFILL === 'true', |
| 5 | maxRetries: Number(process.env.MAX_RETRIES ?? '3'), |
| 6 | }; |
| 7 |
|
| 8 | // server.ts |
| 9 | if (AppConfig.useRedisBuckets && AppConfig.enableAutoBackfill) { |
| 10 | await runBackfill(); |
| 11 | } |
Explanation (EN)
All env parsing, defaults and typing live in AppConfig. The rest of the code reads typed, validated config and never touches process.env directly.
Objašnjenje (HR)
Sve parsiranje env-a, zadane vrijednosti i tipiziranje žive u AppConfigu. Ostatak koda čita tipiziranu, validiranu konfiguraciju i nikad ne dira process.env izravno.
Exceptions / Tradeoffs (EN)
Bootstrap code that must read an env var before the config module itself is initialized (e.g. choosing which config file to load).
Iznimke / Tradeoffi (HR)
Bootstrap kod koji mora pročitati env varijablu prije inicijalizacije samog config modula (npr. odabir koje konfiguracijske datoteke učitati).