State Management
Tracera uses a layered approach to state management, choosing the right tool for each type of state.Architecture
| State Type | Tool | Scope |
|---|---|---|
| Auth state | React Context | Global — available to all components |
| UI state | Zustand | Client-side — persists across navigations |
| Server state | Server Components | Page-level — fetched at render time |
| Form state | React hooks | Component-level — local to forms |
Auth Context
Authentication state is provided via React Context, initialized server-side:initialUser is fetched server-side in the root layout via getSession(), avoiding a loading state on initial page load.
Zustand Store
Client-side application state uses Zustand for its simplicity and performance:- No provider wrapper needed (unlike Redux)
- Minimal boilerplate
- Built-in support for middleware (persist, devtools)
- React 19 compatible
Server-Side Data Fetching
Server Components fetch data directly without client-side state:serverFetch() helper handles:
- Forwarding cookies for authentication
- Configuring the correct backend URL (different in Docker vs local)
- Error handling