Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Share one type across the client/server boundary instead of redefining it
Define a payload type once and import it on both sides; duplicated client and server types silently drift apart.
Bad example
| 1 | // client/interfaces/portfolio.ts |
| 2 | interface Portfolio { value: number; dailyChange: number; } |
| 3 | // server/services/portfolio.ts |
| 4 | interface Portfolio { value: number | null; dailyChange: number | null; } |
Explanation (EN)
Independent copies of one wire contract can disagree silently.
Objašnjenje (HR)
Good example
| 1 | // shared/portfolio.ts |
| 2 | export interface Portfolio { value: number | null; dailyChange: number | null; } |
| 3 | // both client and server import from shared/portfolio |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Share or generate the wire contract when client and server intentionally speak the same schema, and test actual serialization.
Exceptions / Tradeoffs (EN)
Type sharing is not runtime validation or coordinated deployment. Domain models can differ from transport DTOs, and independently deployed versions need compatibility handling. Avoid importing server-only code into client bundles.