State Management
Relevant source files
The following files were used as context for generating this wiki page:- apps/frontend/hooks/use-enrichment-wizard.ts
- apps/frontend/lib/context/status-cache.tsx
- apps/frontend/components/common/resume_previewer_context.tsx
- apps/frontend/components/builder/resume-builder.tsx
- apps/frontend/app/(default)/settings/page.tsx
- apps/frontend/app/(default)/tailor/page.tsx
- AGENTS.md
Introduction
The frontend of Resume Matcher employs a hybrid state management strategy, combining local component state, React Context for global or shared state, and the useReducer hook for complex, multi-step logic. This approach provides flexibility, allowing simple state to be managed locally with useState while more complex, cross-component state is handled by dedicated providers.
State persistence is achieved primarily through the browser's localStorage, ensuring that user settings, drafts, and language preferences are retained across sessions. This document details the key state management patterns, contexts, and hooks used throughout the application.
Global Application State (Context API)
The application leverages the React Context API to provide shared state to different parts of the component tree without prop drilling.
Key Context Providers
| Context Provider | Purpose | Consumed Via |
|---|---|---|
LanguageProvider | Manages UI and content language settings, persisting them to localStorage. | useLanguage() |
StatusCacheProvider | Caches and periodically refreshes global system status (LLM health, DB stats). | useStatusCache() |
ResumePreviewProvider | Temporarily holds tailored resume data to pass between the /tailor and /builder pages. | useResumePreview() |
Sources: apps/frontend/app/(default)/settings/page.tsx:81, apps/frontend/lib/context/status-cache.tsx, apps/frontend/components/common/resume_previewer_context.tsx
StatusCacheProvider
This provider maintains a cached version of the system's status, fetched from the backend. It reduces redundant API calls and provides optimistic UI updates.
The diagram below illustrates the caching and refresh mechanism.
This flow shows how the provider fetches data, caches it, and allows for both optimistic updates and manual refreshes.
Sources: apps/frontend/lib/context/status-cache.tsx:28-49, 52-58
ResumePreviewProvider
This context acts as a temporary data bridge. When a user generates a tailored resume on the /tailor page, the resulting data is stored in this context. The user is then redirected to the /builder page, which reads the data from the context to populate the editor.
The following diagram shows this data handoff flow.
LanguageProvider
The LanguageProvider manages two distinct language settings: one for the UI and one for AI-generated content. These settings are configured on the Settings page and are persisted in localStorage.
| localStorage Key | Purpose | Managed By |
|---|---|---|
resume_matcher_ui_language | Stores the selected language for the user interface. | setUiLanguage |
resume_matcher_content_language | Stores the language for LLM-generated content. | setContentLanguage |
Sources: AGENTS.md, apps/frontend/app/(default)/settings/page.tsx:81-90, 396-460
Complex Component State (useReducer)
For features involving multiple steps and complex state transitions, the useReducer hook is employed to create a predictable state machine.
useEnrichmentWizard
The AI-powered resume enrichment feature is managed by the useEnrichmentWizard hook. This hook uses a reducer to handle the flow from analysis to applying enhancements.
The state machine for the wizard is defined by WizardStep:
| Step | Description |
|---|---|
idle | The wizard is not active. |
analyzing | The AI is analyzing the resume for weaknesses. |
questions | The user is presented with questions to provide more context. |
generating | The AI is generating new bullet points based on answers. |
preview | The user can preview the suggested enhancements. |
applying | The enhancements are being saved to the resume. |
complete | The process is finished successfully. |
error | An error occurred at some stage. |
no-improvements | The AI found no areas for improvement. |
Sources: apps/frontend/hooks/use-enrichment-wizard.ts:14-25, 59-138
The diagram below visualizes the state transitions within the enrichment wizard.
Local Component State and Persistence
Many components, especially complex ones like the ResumeBuilder, manage their own state using useState and persist it to localStorage for better user experience.
Resume Builder State
The ResumeBuilder component is the core of the resume editing experience and manages a significant amount of local state.
Key State Variables
resumeData: The mainResumeDataobject being edited.templateSettings: Formatting controls like margins, fonts, and spacing.hasUnsavedChanges: A boolean flag that tracks if theresumeDatadiffers from the last saved version. This is used to prompt the user before they leave the page.activeTab: Manages the currently visible tab (Resume, Cover Letter, etc.).isSaving,isDownloading: Loading state flags for asynchronous operations.
Sources: apps/frontend/components/builder/resume-builder.tsx:61-80
State Persistence with localStorage
The builder uses localStorage to save drafts and user preferences, allowing for recovery after a browser refresh.
localStorage Key | Constant | Purpose |
|---|---|---|
resume_builder_draft | STORAGE_KEY | Automatically saves the current resumeData object whenever it's updated. |
resume_builder_settings | SETTINGS_STORAGE_KEY | Persists the user's chosen template formatting settings. |
Sources: apps/frontend/components/builder/resume-builder.tsx:48-49, 140-142, 280-283
Data Loading Priority
When the ResumeBuilder component mounts, it loads resume data according to a specific priority order to ensure the most relevant data is displayed.
This flow ensures that a saved resume from the server is prioritized, followed by data from the tailoring process, a local draft, and finally, default data.
Sources: apps/frontend/components/builder/resume-builder.tsx:176-238
Conclusion
The state management in Resume Matcher is pragmatic and feature-driven. It effectively uses React's built-in hooks (useState, useContext, useReducer) to manage state at different scopes. Global concerns like language and system status are handled by context providers. Complex, self-contained logic like the enrichment wizard is encapsulated in a useReducer state machine. Finally, heavy-duty components like the ResumeBuilder manage their own state locally, using localStorage to provide a robust and persistent user experience. This layered approach keeps state management concerns separated and scales well with the application's complexity.