Wizard Draft Repository
Component Detail
Description
Persists and retrieves partial wizard answers locally using shared preferences or Hive, enabling pause-and-resume without data loss. Each draft is keyed by wizard type and user ID. Automatic expiry after 30 days prevents stale drafts accumulating.
wizard-draft-repository
Summaries
The Wizard Draft Repository protects users from losing progress when interrupted during multi-step workflows such as activity logging. In real-world mobile usage, interruptions are frequent — phone calls, notifications, app switching — and losing form progress creates significant frustration that drives abandonment. By automatically persisting each step's answers locally and restoring them on re-entry, this component directly increases wizard completion rates. The automatic 30-day draft expiry prevents stale data accumulating on user devices, reducing storage complaints and privacy concerns.
For workflows tied to compliance reporting or activity tracking, higher completion rates translate directly to better data quality and stronger operational outcomes for the organization.
This is a low-complexity shared data persistence component with no external dependencies, making it one of the safest items to schedule early. It is a direct dependency of the Wizard State Manager and must be delivered and tested before wizard state management development begins. Testing must cover the full draft lifecycle: save, load, delete on wizard completion, and automatic expiry after 30 days. Edge cases include concurrent drafts for multiple wizard types under the same user ID, draft restoration after app reinstall, and expiry triggering on app launch.
The storage backend choice — SharedPreferences versus Hive — must be decided before implementation starts, as it affects the storage interface contract and any future migration path for schema changes.
The Wizard Draft Repository persists `WizardDraft` objects keyed by a `(wizardId, userId)` composite key using either SharedPreferences or Hive, with the storage backend abstracted behind the repository interface to allow future migration. Interfaces: `saveDraft(wizardId, userId, stepIndex, answers)`, `loadDraft(wizardId, userId): WizardDraft?`, `deleteDraft(wizardId, userId)`, `listActiveDrafts(userId): List
`loadDraft` returns nullable — callers must handle the null case by defaulting to a fresh wizard start. Unit tests should mock the storage backend to validate expiry logic independently of platform-specific storage APIs.
Responsibilities
- Save draft wizard state on each step transition
- Load most recent draft for a given wizard type and user
- Delete draft on successful wizard completion
- Expire drafts older than 30 days automatically
Interfaces
saveDraft(wizardId, userId, stepIndex, answers)
loadDraft(wizardId, userId): WizardDraft?
deleteDraft(wizardId, userId)
listActiveDrafts(userId): List<WizardDraft>
purgeExpiredDrafts()