Mobile State & Local Persistence
Relevant source files
The following files were used as context for generating this wiki page:
- artifacts/mobile/context/AppContext.tsx
- artifacts/mobile/context/VeraMemoryContext.tsx
- artifacts/mobile/app/data-controls.tsx
- attached_assets/Pasted-Build-granular-saved-data-controls-for-the-React-Native_1774841501598.txt
- replit.md
- attached_assets/Pasted-Make-a-truth-alignment-pass-across-the-current-React-Na_1774837201847.txt
The Hospice Roadmap mobile application utilizes a decentralized state management architecture primarily driven by React Context API and local persistence via AsyncStorage. This system is designed to provide offline-first access to critical hospice guidance while maintaining a "living profile" of the user's journey. Local persistence ensures that sensitive data—such as patient profiles, symptom logs, and caregiver journals—remain on the device, only being transmitted to server-backed services like Ragna (the AI companion) when explicitly required for personalized guidance.
The architecture emphasizes granular data control, allowing users to manage and clear specific categories of information (e.g., clearing "Goals of Care" while retaining "Patient Profile" details). This approach balances the need for deep personalization with privacy and data hygiene.
Sources: replit.md, attached_assets/Pasted-Build-granular-saved-data-controls-for-the-React-Native_1774841501598.txt
State Management Architecture
The application state is partitioned into several specialized Context Providers. This modularity ensures that components only subscribe to the data they need, improving performance and maintainability.
Core Context Providers
| Provider | Responsibility | Primary Data Structures |
|---|---|---|
AppContext | Global user state and preferences | User, patientProfile, savedResources, savedProviders |
SymptomContext | Daily symptom tracking logs | entries (Symptom logs) |
JournalContext | Caregiver journal entries | entries (Journal logs) |
RemindersContext | Medication and appointment alerts | reminders, notificationId |
VeraMemoryContext | Local AI personality and history | memories, livingProfile, recentTiles |
Sources: replit.md, artifacts/mobile/context/AppContext.tsx, attached_assets/Pasted-Build-granular-saved-data-controls-for-the-React-Native_1774841501598.txt
Data Flow & Interaction
The following diagram illustrates how user interactions trigger state updates and local persistence.
The application tracks meaningful events (symptom check-ins, journal writes, profile updates) as rolling observations. These are used to synthesize the "living profile" which is then passed as context to the AI companion.
Sources: replit.md
Local Persistence Implementation
Hospice Roadmap uses AsyncStorage as its primary storage engine for all device-level data. Key-value pairs are used to store serialized JSON objects representing different modules of the application.
Key Storage Keys
@hospice_user_v1: Main user profile and app status.@ragna_learning_v1: Tracks app activity observations for AI learning.@hospice_symptoms_v1: Collection of daily symptom check-ins.@hospice_journal_v1: Caregiver journal entries.ragna_client_id: Persistent device-level identifier for server-side conversation scoping.
Sources: replit.md, attached_assets/Pasted-Make-a-focused-security-pass-on-the-Ragna-conversation-_1774838250254.txt
Privacy & Data Sanitization
A "truth alignment" pass ensures that user-facing copy accurately reflects these storage practices. For instance, onboarding notes clarify that information is stored on the device and only sent securely to generate AI responses when using Ragna.
Sources: attached_assets/Pasted-Make-a-truth-alignment-pass-across-the-current-React-Na_1774837201847.txt
Granular Data Controls
The application provides a "Manage Saved Data" interface (data-controls.tsx) that allows users to selectively purge locally stored information. This is implemented via specialized "clear" helpers exposed through the various Context Providers.
Data Clearing Logic
The system distinguishes between clearing specific fields and performing a full reset. For example, clearing the "Patient Profile" preserves the user's role and journey stage while removing clinical details.
Clear Helper Functions
| Function | Affected Data | Preserved Data |
|---|---|---|
clearPatientProfile | patientName, diagnosis, medications, equipment | role, journeyStage, userId, onboardingComplete |
clearGoalsOfCare | patientProfile.goalsOfCare | Rest of patientProfile |
clearReminders | All reminders list | None (also cancels scheduled notifications) |
clearMemories | memories, livingProfile, recentTiles | None |
Sources: artifacts/mobile/context/AppContext.tsx:88-112, attached_assets/Pasted-Build-granular-saved-data-controls-for-the-React-Native_1774841501598.txt
AI Context and Memory Persistence
The VeraMemoryContext (legacy naming for Ragna) handles the persistence of local memories and "living profile" synthesis. This context is critical for the AI's ability to provide personalized guidance without requiring a continuous server-side session for all user history.
Memory Synthesis Sequence
The synthesis occurs silently after three significant events and a 2-hour cooldown period.
Summary
The Mobile State & Local Persistence system in Hospice Roadmap prioritizes local-first storage using AsyncStorage and provides users with granular control over their data. By partitioning state across specialized React Contexts and implementing category-specific clearing logic, the application ensures high technical performance, strong privacy standards, and a deeply personalized user experience powered by its local "living profile" architecture.