Register Riverpod providers for data layer
epic-scenario-based-follow-up-prompts-foundation-task-010 — Create Riverpod providers (using riverpod) that expose ScenarioRuleRepository, PromptHistoryRepository, and PushNotificationDispatcher to the rest of the application. Wire them with correct scoping — chapter-scoped providers should invalidate when the active chapter changes via the existing active-chapter-state provider. Export a barrel file so dependent components (rule engine, scheduler, configuration manager) can import a single path.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Follow the existing Riverpod provider patterns in the project. Use ref.watch(activeChapterStateProvider) inside the scenarioRuleRepositoryProvider factory so that when the chapter state changes, the provider is automatically invalidated and rebuilt. If using riverpod_generator, annotate with @Riverpod(keepAlive: false) to allow disposal on chapter change. The barrel file pattern (providers.dart re-exporting all provider symbols) is important for maintaining a clean import graph — downstream consumers should never import individual repository provider files directly.
Keep provider definitions thin — no business logic in the provider factory, only wiring of dependencies from other providers.
Testing Requirements
Unit tests using flutter_test with a ProviderContainer. Test: (1) scenarioRuleRepositoryProvider resolves without error, (2) after simulating an active-chapter change, the provider returns a fresh instance (verify via identity check or a mock factory call count), (3) barrel file exports are all accessible from a single import in a test file. Use overrideWithValue on dependent providers to isolate the chapter-state simulation. No widget tests needed for this task.
Supabase RLS policies for chapter-scoped rule access may interact unexpectedly with service-role keys used by the Edge Function, potentially blocking backend reads or leaking cross-chapter data.
Mitigation & Contingency
Mitigation: Write and review RLS policies in isolation with automated policy tests before merging; define a dedicated service-role bypass policy scoped to the edge function's Postgres role.
Contingency: If RLS blocks the edge function, temporarily use a bypass policy with audit logging while a permanent fix is implemented; escalate to a Supabase security review.
FCM device tokens become invalid when users reinstall the app or revoke permissions; stale tokens cause silent delivery failures that are hard to detect without explicit error handling.
Mitigation & Contingency
Mitigation: Implement token invalidation handling in PushNotificationDispatcher that removes stale tokens from the database on FCM 404/410 responses; log all delivery failures with structured output.
Contingency: If token hygiene proves unreliable, add a periodic token refresh job that re-registers all active users' tokens via the FCM registration endpoint.