The 4-Layer Separation Principle
At Codemuji, every single web application adheres to four non-negotiable architectural boundaries:
1. Layer 1: Domain Models — Pure TypeScript interfaces and types representing business entities. Zero external dependencies.
2. Layer 2: State Management — Redux Toolkit or Zustand slices that orchestrate application state lifecycles and asynchronous thunks.
3. Layer 3: Infrastructure / API Repositories — HTTP transport clients that serialize, deserialize, and validate server responses.
4. Layer 4: Presentation / UI — Pure React components and hooks focused exclusively on layout, aesthetics, and accessibility.
If your React component imports Axios, fetch, or raw SQL queries, your architectural boundaries are already breached.
The Cost of Leaking API Contracts into UI Components
When a backend API schema changes, poorly architected frontends break across dozens of individual component files. By channeling all network requests through Infrastructure Repositories that map raw payloads into canonical Domain Models, backend changes are resolved in a single file without altering presentation code.