Component and State Architecture
Good React architecture makes change predictable by aligning ownership, data flow, async boundaries, failure boundaries, and runtime boundaries.
Architecture starts with ownership
Local UI state should usually stay local. Lift it only when coordination genuinely requires a common owner.
State categories are architectural boundaries
Do not duplicate one fact into several owners merely because different screens need it.
Feature-oriented structure
Grouping by feature can make ownership visible:
features/
checkout/
components/
hooks/
data/
state/
tests/
search/
components/
hooks/
data/
Literal directory trees are useful here because the structure itself is the subject. The principle matters more than the exact folder names: related code should evolve behind an explicit feature boundary.
Separate domain logic from rendering
export function calculateOrderTotal(lines, discount) {
return applyDiscount(sumLines(lines), discount);
}
Pure domain rules should not require React to test or reuse them.
Component boundaries should have a reason
Useful responsibilities include:
- reusable semantic primitive;
- local interaction owner;
- feature orchestrator;
- provider boundary;
- third-party adapter;
- async/loading/failure boundary.
Avoid both a 2,000-line component and dozens of wrappers with no architectural meaning.
Custom Hooks package behavior, not shared state
const { draft, updateQuantity, submit } = useCheckoutDraft(orderId);
A custom Hook can reuse a stateful/synchronization process. Separate Hook calls still have separate state unless they subscribe to a shared owner.
Context distributes dependencies
Context is useful when a dependency belongs to a subtree and explicit prop threading would obscure the API.
For reducer architectures, separate state and dispatch Contexts when that clarifies dependencies or update surfaces.
URL and server state have different contracts
A search filter that belongs in /search?q=react&page=3 should not exist only as hidden component state. Remote data should not be copied into ad-hoc global client state unless the client truly becomes its owner.
Async, failure, and priority boundaries should match UX
Place these around meaningful user experiences, not arbitrary file boundaries.
Server/client architecture
A 'use client' boundary is a module-graph decision, not merely a rendering label. Keep server-only dependencies outside the client graph and pass only serializable data needed by the interactive region.
Architecture review loop
A maintainable architecture makes ownership visible, keeps dependencies directional, and lets each boundary change for a clear reason.