Rules Hub

Coding Rules Library

← Back to all rules
architecture ruleStack: general
architectureconfigurationdrymaintainabilityclean-code

Maintain a single source of truth for domain configuration

Centralize domain definitions (like lists or resources) into a single shared configuration to prevent duplication and inconsistency across environments.

PR: Feat/FCK-2286 - Create new Heirs Kapital list page #4161Created: Dec 7, 2025

Bad example

Old codets
1// config/site-a.ts
2const siteALists = [
3 { slug: 'top-400', name: 'Top 400' }
4];
5
6// config/site-b.ts (Duplicated definition)
7const siteBLists = [
8 { slug: 'top-400', name: 'Top 400' }
9];
10
11// logic.ts (Hardcoded business rules)
12function getListFeatures(slug: string) {
13 // Logic scattered and tied to magic strings
14 if (slug === 'top-400' || slug === 'heirs') {
15 return { showStats: true };
16 }
17 return {};
18}

Explanation (EN)

The list definitions are duplicated across multiple environment files, making them hard to keep in sync. Additionally, business logic relies on hardcoded strings (`slug === 'top-400'`) instead of configuration metadata.

Objašnjenje (HR)

Definicije lista su duplicirane kroz više datoteka za različita okruženja, što otežava njihovu sinkronizaciju. Dodatno, poslovna logika se oslanja na 'hardcodirane' stringove (`slug === 'top-400'`) umjesto na metapodatke iz konfiguracije.

Good example

New codets
1// config/shared-lists.ts
2export const SHARED_LISTS = [
3 {
4 slug: 'top-400',
5 name: 'Top 400',
6 features: { showStats: true, isJournalistBoost: true }
7 },
8 {
9 slug: 'heirs',
10 name: 'Heirs',
11 features: { showStats: true, isJournalistBoost: false }
12 }
13] as const;
14
15// logic.ts
16import { SHARED_LISTS } from './config/shared-lists';
17
18function getListFeatures(slug: string) {
19 // Logic is generic and driven by the central config
20 const list = SHARED_LISTS.find(l => l.slug === slug);
21 return list?.features || {};
22}

Explanation (EN)

A single shared configuration acts as the source of truth for all environments. The logic is now generic and declarative, reading properties like `features` directly from the config object instead of checking string literals.

Objašnjenje (HR)

Jedna zajednička konfiguracija služi kao izvor istine za sva okruženja. Logika je sada generička i deklarativna, te čita svojstva poput `features` izravno iz konfiguracijskog objekta umjesto provjere stringova.

Notes (EN)

In large monorepos, use a shared package or a common configuration folder that both 'apps' (environments) can import from.

Bilješke (HR)

U velikim monorepo projektima, koristite zajednički paket ili mapu s konfiguracijom iz koje oba 'app-a' (okruženja) mogu importirati podatke.