Skip to main content

Domain, Data, and State Foundations

Why this chapter matters

Many frontend problems blamed on state management are actually domain modeling problems. The UI does not know what a record means, who owns it, how fresh it must be, which user can change it, or what should happen when two sources disagree.

A frontend architect needs a clear model for domain concepts, data ownership, and state placement before choosing libraries.

The state placement model

State typeBelongs inExamplesCommon mistake
Addressable navigation stateURLfilters, selected tab, pagination, shareable searchhiding it in component state
Server-owned dataserver/cache layeruser profile, report rows, permissions, product inventorycopying it into local state and letting it drift
Client interaction statecomponent or UI storeopen menu, focused row, draft panel expandedpushing transient UI details into global state
Durable local workIndexedDB or local durable storeoffline drafts, queued commands, uploaded files pending synctreating local storage as a database without migrations
Derived statecomputed selectorstotals, grouped rows, filtered visible itemsstoring duplicate values that become inconsistent
Cross-session preferencecontrolled preference storetheme, density, saved viewmixing preferences with authorization or product truth
Experiment stateexperiment platformvariant assignment, exposure eventchanging behavior without observability or rollback

Good architecture makes the state location obvious from the state's job.

Domain vocabulary before component vocabulary

For each important surface, write down domain nouns and verbs before designing components.

Example for a SaaS reporting dashboard:

Domain conceptMeaning
ReportA saved definition of metrics, dimensions, filters, and permissions
Report runA concrete execution of a report definition over a time range
FilterA user-controlled constraint on report output
SegmentA reusable audience or business grouping
ExportA side-effecting operation that creates a downloadable artifact
PermissionA policy decision about who can view, edit, run, or export

Now components can map to product reality instead of inventing their own language.

Ownership questions

Before implementation, answer:

  • Which backend or BFF owns the canonical record?
  • Which fields are safe for the browser to see?
  • Which fields are editable by this user?
  • Which changes are optimistic and which require confirmation?
  • Which state must survive refresh, tab close, or offline use?
  • Which state is shareable through URL?
  • Which state is personal preference rather than product truth?
  • Which state needs audit?

Data lifecycle

requested
-> loading
-> available
-> stale
-> refreshing
-> mutation pending
-> confirmed, rejected, conflicted, or rolled back

The UI should not collapse these into one vague "loading" or "error" state. Different lifecycle states require different copy, controls, telemetry, and recovery.

Cache and freshness baseline

Document freshness by user harm:

DataFreshness expectationUser harm if stale
Static marketing contentminutes to dayslow, unless legal/compliance text
Dashboard analyticsseconds to hours depending on domainmedium; wrong decisions or confusion
Permissionsimmediate or near-immediatehigh; access leak or blocked work
Inventory/pricedomain-specific, often stricthigh; purchase or trust failure
Notificationsnear-real-time if action-drivingmedium to high
AI/RAG contextsource freshness must be visiblehigh if generated output drives decisions

Freshness is a product decision with technical consequences.

State anti-patterns

  • Storing server data in a global client store because it is convenient.
  • Putting shareable workflow state only in memory.
  • Using URL state for secrets or sensitive filters.
  • Duplicating derived state until it disagrees with source state.
  • Treating optimistic UI as success before the server accepts the mutation.
  • Letting each component invent its own empty, loading, and error semantics.
  • Choosing a state library before defining state categories.

Review checklist

  • Domain nouns and verbs are written in product language.
  • Canonical owners are named for each data source.
  • URL, server, client, local durable, derived, and preference state are separated.
  • Freshness expectations are tied to user harm.
  • Mutation states include pending, confirmed, rejected, conflicted, and rollback behavior.
  • Sensitive data is not stored in URL, logs, or local storage.
  • Empty/error/loading states are specific to the lifecycle state.
  • Tests cover stale response ordering and mutation recovery where relevant.

Exercises

  1. Pick a complex route and classify every piece of state using the state placement model.
  2. Write a domain vocabulary table before sketching components.
  3. Define freshness expectations for five data types and rank user harm if stale.
  4. Replace a generic loading/error model with a full data lifecycle matrix.

Source lens

This foundation connects local distributed-systems material, database consistency concepts, browser storage guidance, and frontend architecture practice. It prepares you for Part III rendering/data architecture and Part V system design.