TalentSync

AI resume builder and ATS optimizer for job seekers. Tailored resumes, outreach, and interview prep from one profile.

State management

Frontend state: auth session, UI stores, and server data.

  • Server state management with React Query
  • Local UI state with useState/useReducer
  • Authentication state via FastAPI cookies and SessionProvider
  • Custom hooks for API integration and UI state synchronization
  • Data fetching patterns, caching, and optimistic updates
  • Context providers, state persistence, and cross-component synchronization
  • Error handling, loading states, and debugging techniques

Repository layout#

The state management stack is organized around three pillars:

  • Providers: React Query client, session context, and developer tools
  • Services: Typed API clients and service abstractions
  • Hooks: React Query queries/mutations and custom reducers for wizard-like flows

Building blocks#

  • Providers
  • React Query client configured with default caching and retry policies
  • SessionProvider in session-provider.tsx for /api/v1/auth/me
  • Services
  • Centralized typed API client with clear error handling
  • Feature-specific service modules encapsulate endpoint logic
  • React Query Hooks
  • Queries for server state with explicit query keys
  • Mutations for writes with invalidation and notifications
  • Custom Hooks
  • Local state machines for complex UI flows
  • Utility hooks for UI state and notifications

How it fits together#

React Query holds server data. Auth is the FastAPI cookie session. Custom hooks hold wizard UI. Services wrap api-client.ts.

React query provider and defaults#

  • Creates a singleton QueryClient :
  • Stale time: 1 minute
  • Retry attempts: 2
  • Window focus refetch disabled
  • Wraps the app with SessionProvider for authentication state

Authentication state management#

Google OAuth on FastAPI. SessionProvider seeds from getSession() and re-fetches /api/v1/auth/me. NextAuth is gone.

API client and error handling#

  • Provides typed GET/POST/PUT/PATCH/DELETE helpers
  • Builds query strings and FormData support
  • Throws ApiError with status and structured messages
  • Centralizes error surface for hooks and services

Server state: dashboard and resumes#

  • useDashboard: fetches dashboard data with a fixed query key
  • useResume: fetches a single resume by id with lazy execution (enabled only when id exists)
  • useDeleteResume/useRenameResume/useUploadResume: mutations that invalidate dashboard queries and notify via toast

Local state: wizard flows#

  • Enrichment Wizard
  • Uses useReducer to manage multi-step state machine
  • Integrates with React Query mutations for analysis, enhancement, refinement, and application
  • Computes derived UI flags (canSubmitAnswers, canApplyEnhancements, counts)
  • Improvement Wizard
  • Similar reducer-driven flow for improving resumes
  • Emphasizes preview and applying changes

UI state utilities#

  • use-toast: centralized toast notifications with queue limits and dismissal
  • use-mobile: responsive breakpoint detection for UI adaptation

Data fetching patterns, caching, and invalidation#

  • Caching
  • Global staleTime of 1 minute; adjust per feature as needed
  • Automatic retries on failure
  • Fetching
  • Queries keyed by domain identifiers (e.g., [“dashboard”], [“resume”, id])
  • Lazy execution for id-dependent queries
  • Invalidation
  • Mutations invalidate related query keys to synchronize UI state
  • Notifications surfaced via toast

Optimistic updates#

  • Current hooks primarily reflect server state after mutations
  • To implement optimistic updates:
  • Pre-update cache in mutation.onMutate
  • Rollback on error via context returned by onMutate
  • Invalidate or update cache in onSuccess/onError
  • Recommended for actions like renaming or toggling visibility to reduce perceived latency

[No sources needed since this section provides general guidance]

Context providers and cross-component synchronization#

  • SessionProvider ensures authentication state is available across the app
  • QueryClientProvider enables cache sharing and synchronization across components
  • Custom hooks coordinate UI state and react to server-side changes via invalidation

Types and contracts#

  • Centralized exports of feature types enable consistent typing across services and hooks

Dependencies#

Performance#

  • Prefer granular query keys to minimize unnecessary refetches
  • Use enabled flags for id-dependent queries to avoid redundant requests
  • Tune staleTime per feature based on data volatility
  • Limit concurrent mutations and batch invalidations to reduce re-renders
  • Use devtools sparingly in production; initialIsOpen is disabled by default

[No sources needed since this section provides general guidance]

Troubleshooting#

  • Network and API errors
  • Inspect ApiError instances thrown by api-client
  • Surface messages via toast
  • React Query debugging
  • Enable devtools to inspect cache and query states
  • Verify query keys and invalidation triggers
  • Authentication issues
  • Confirm ts_access_token and matching JWT_SECRET / BACKEND_JWT_SECRET
  • Check /api/v1/auth/me and /refresh in the network tab