State Management

Decision matrix for choosing the correct state management tool. Using the wrong tool is a code review blocker.

Decision Matrix

Data TypeToolLocation
Server entities (CRUD)React Queryfrontend/src/lib/queries/
Global auth/preferencesZustand + localStoragefrontend/src/store/
URL-shareable UI stateURL state hooksfrontend/src/hooks/url-state/
Form fieldsreact-hook-form + ZodInline in form components
Transient UI (tooltips, dropdowns)useStateComponent-local

Anti-Patterns (NEVER)

  • useState for server data — use React Query Pattern
  • useContext for global state — use Zustand
  • Raw useSearchParams — use URL State Management hooks
  • Inline useMutation in components — define in lib/queries/

Zustand Stores

Three stores in frontend/src/store/:

StorePurpose
auth.tsCurrent user, JWT token, login state
projects.tsActive project selection
workflow.tsWorkflow engine UI state

All stores use localStorage persistence for session survival.

Context Providers

Limited to two specialized cases:

ProviderPurpose
FormBuilderContext.tsxForm Builder drag-and-drop state
ResponsibilityFilterContext.tsxCross-component filter coordination

React Query Client Config

defaultOptions: {
  queries: {
    staleTime: 5 * 60 * 1000,     // 5 minutes
    gcTime: 10 * 60 * 1000,       // 10 minutes garbage collection
    refetchOnWindowFocus: false,
  },
}

See Also