Diagrams
Diagrams
Source-grounded visual maps of what the software is doing. Each diagram explains what you are seeing, how it was verified, and what remains uncertain — and links back to the functionality and warnings it relates to.
Diagrams never claim behaviour that has not been traced to source. Inferred or unverified paths are labelled in the diagram itself.
Understand the whole app
Fast visual entry points for Stoppr.
Stoppr application overview
How the Flutter client relates to Firebase, purchases, local state, and external AI/food APIs.
Parts — what each one is
Each part explains why it appears, where it lives in the repository, and which files to read.
Stoppr mobile client
Verified from sourceFlutter iOS/Android app the user installs and opens.
Related functionality: Application startup
lib//
- lib/
main.dart
- Entry point
lib/main.dartCold-start bootstrap and first navigation decisions.
Canonical purpose: Cold-start bootstrap: dotenv, RevenueCat, Firebase, analytics, notifications, Superwall, deep links, and startup routing into onboarding, paywall, or MainScaffold.
Firebase
Verified from sourceAuth identity, Firestore documents, Storage, Messaging, Crashlytics.
Related functionality: Firebase authentication Calorie nutrition tracking
cloud/
- lib/
firebase_options.dart
- Configuration
lib/firebase_options.dartBuilds FirebaseOptions from EnvConfig key names.
Canonical purpose: Env-backed DefaultFirebaseOptions for Android/iOS only; missing keys assert at startup.
RevenueCat + Superwall
Verified from sourceStore purchases and paywall presentation that decide premium access.
Related functionality: Subscription access gating Main paywall
lib/core/subscription, lib/core/superwall/
- lib/
- core/
- subscription/
subscription_service.dart
- superwall/
superwall_purchase_controller.dart
- subscription/
- core/
- Primary implementation
lib/core/subscription/subscription_service.dartisPaidSubscriber decides access from Superwall/RevenueCat.
Canonical purpose: Paid-access decisions from Superwall subscription status and RevenueCat CustomerInfo. Firestore subscription fields are not the entitlement source of truth.
- Integration adapter
lib/core/superwall/superwall_purchase_controller.dartMaps Superwall purchase requests onto RevenueCat.
Canonical purpose: Maps Superwall purchase/restore actions to RevenueCat and syncs subscription status back to Superwall.
Local device state
Verified from sourceSharedPreferences, HomeWidget bridge, and local caches for fast daily loops.
Related functionality: Sugar streak tracking Home screen widgets
device/
- lib/
- core/
- streak/
streak_service.dart
- streak/
- core/
- Primary implementation
lib/core/streak/streak_service.dartWrites streak values locally and to the widget bridge.
Canonical purpose: Streak persistence (SharedPreferences + Firestore) and home_widget sync. iOS app group id is still group.YOUR_BUNDLE_ID.shared.
External AI / food APIs
Verified from sourceGroq, OpenAI, Edamam, and Spoonacular called for scanning, chatbot, and recipes.
Related functionality: Sugar food scanning Melinda chatbot assistant Recipe discovery
external/
- lib/
- core/
- config/
env_config.dart
- config/
- core/
- Configuration
lib/core/config/env_config.dartExposes API key environment variable names used by those features.
Canonical purpose: Typed accessors for environment variable NAMES used by Firebase, purchases, AI, and analytics. Never commit values.
Connections — why they connect
Each connection names the concrete mechanism linking its two parts. The mechanism is the proof the relationship passed the explainability gate.
Stoppr mobile client depends on Firebase
Verified from source Solid lineThe client authenticates users and reads/writes profile, onboarding, community, and nutrition documents through Firebase SDKs.
Related functionality: Firebase authentication
- Caller
lib/core/auth/auth_service.dartPerforms Firebase Auth sign-in and profile side effects.
Canonical purpose: Firebase Auth (Google, Apple, email) plus RevenueCat/Mixpanel identity sync and users/{uid} profile writes. Google OAuth fallbacks are placeholders when env is missing.
Stoppr mobile client depends on RevenueCat + Superwall
Verified from source Solid lineStartup routing and feature gates call SubscriptionService / Superwall to know whether the user is paid.
Related functionality: Subscription access gating
- Callee
lib/core/subscription/subscription_service.dartReturns paid/free based on Superwall and RevenueCat.
Canonical purpose: Paid-access decisions from Superwall subscription status and RevenueCat CustomerInfo. Firestore subscription fields are not the entitlement source of truth.
Stoppr mobile client stores in Local device state
Verified from source Solid lineDaily habit state such as streaks and onboarding progress is stored on-device and mirrored to widgets.
Related functionality: Sugar streak tracking Startup routing
- Primary implementation
lib/features/onboarding/data/services/onboarding_progress_service.dartPersists onboarding resume keys in SharedPreferences.
Canonical purpose: SharedPreferences + Firestore resume checkpoints and onboarding_completed for startup routing.
Stoppr mobile client sends to External AI / food APIs
Verified from source Solid lineFood scan, Rate My Plate, chatbot, and recipe search send requests to configured external APIs.
Related functionality: Sugar food scanning Melinda chatbot assistant Recipe discovery
- Caller
lib/features/app/presentation/screens/chatbot/chatbot_screen.dartIssues Groq/OpenAI requests for Melinda responses.
Canonical purpose: Melinda CBT assistant using Groq chat/transcription and OpenAI speech, with daily API interaction limits.
RevenueCat + Superwall writes Firebase
Inferred from source Dashed lineAfter purchase sync, subscription mirror fields are written to the user Firestore document for analytics/display.
Basis for the inference: Purchase controller contains Firestore update helpers traced at class level; every write site was not line-enumerated.
Related functionality: Main paywall
- Caller
lib/core/superwall/superwall_purchase_controller.dartPersists subscription mirror fields after RevenueCat sync.
Canonical purpose: Maps Superwall purchase/restore actions to RevenueCat and syncs subscription status back to Superwall.
Uncertain: Exact field set per product type not exhaustively listed.
Understand the main product flows
Onboarding, auth, and subscription paths.
Onboarding and authentication flow
Welcome to auth to questionnaire/profile to pre-paywall to MainScaffold.
Parts — what each one is
Each part explains why it appears, where it lives in the repository, and which files to read.
Welcome + early onboarding
Verified from sourcePlays welcome video and early intro screens that offer auth or skip.
Related functionality: Onboarding introduction
lib/features/onboarding/presentation/screens/
- lib/
- features/
- onboarding/
- presentation/
- screens/
welcome_video_screen.dart
- screens/
- presentation/
- onboarding/
- features/
- Entry point
lib/features/onboarding/presentation/screens/welcome_video_screen.dartFirst visible onboarding surface after splash routing.
Auth providers
Verified from sourceGoogle, Apple, email, or anonymous Firebase sign-in creating an AppUser.
Related functionality: Firebase authentication Guest anonymous access
lib/core/auth/
- lib/
- core/
- auth/
auth_service.dart
- auth/
- core/
- Primary implementation
lib/core/auth/auth_service.dartImplements provider sign-in methods and auth state listener.
Canonical purpose: Firebase Auth (Google, Apple, email) plus RevenueCat/Mixpanel identity sync and users/{uid} profile writes. Google OAuth fallbacks are placeholders when env is missing.
Questionnaire + profile
Verified from sourceCollects questionnaire answers, profile, symptoms, goals, and nutrition setup with resume checkpoints.
Related functionality: Onboarding questionnaire Onboarding profile and goals Onboarding personalized analysis
lib/features/onboarding/
- lib/
- features/
- onboarding/
- data/
- services/
onboarding_progress_service.dart
- services/
- data/
- onboarding/
- features/
- Primary implementation
lib/features/onboarding/data/services/onboarding_progress_service.dartPersists and restores the current onboarding screen.
Canonical purpose: SharedPreferences + Firestore resume checkpoints and onboarding_completed for startup routing.
Pre-paywall
Verified from sourceFinal commercial gate before MainScaffold for unpaid users.
Related functionality: Main paywall
lib/features/onboarding/presentation/screens/
- lib/
- features/
- onboarding/
- presentation/
- screens/
pre_paywall.dart
- screens/
- presentation/
- onboarding/
- features/
- Primary implementation
lib/features/onboarding/presentation/screens/pre_paywall.dartRegisters Superwall placements and handles purchase success.
Canonical purpose: Primary paywall UI and Superwall placement registration. Many placement IDs remain INSERT_YOUR_* placeholders.
MainScaffold
Verified from sourcePost-onboarding app shell with bottom navigation.
Related functionality: Main navigation
lib/features/app/presentation/screens/
- lib/
- features/
- app/
- presentation/
- screens/
main_scaffold.dart
- screens/
- presentation/
- app/
- features/
- Primary implementation
lib/features/app/presentation/screens/main_scaffold.dartHosts the signed-in / paid user experience.
Canonical purpose: Bottom-tab shell hosting Home, Learn, Rewire, Community, and Profile with initialIndex deep-link entry.
Connections — why they connect
Each connection names the concrete mechanism linking its two parts. The mechanism is the proof the relationship passed the explainability gate.
Welcome + early onboarding routes to Auth providers
Verified from source Solid lineEarly onboarding screens route the user into Google/Apple/email sign-in or allow skipping toward later anonymous creation.
Related functionality: Onboarding introduction Firebase authentication
- Caller
lib/features/onboarding/presentation/screens/onboarding_page.dartInvokes AuthCubit Google/Apple sign-in handlers.
Auth providers routes to Questionnaire + profile
Inferred from source Dashed lineAfter identity exists (or skip), navigation continues into questionnaire, profile, and personalization screens.
Basis for the inference: Order derived from Navigator calls across onboarding screens rather than one central route table.
Related functionality: Onboarding questionnaire
- Primary implementation
lib/features/onboarding/presentation/screens/questionnaire_screen.dartCollects and persists questionnaire answers.
Uncertain: Exact branch when questionnaire answers are missing uses a shorter path.
Questionnaire + profile routes to Pre-paywall
Verified from source Solid lineCompleted personalization and benefits screens navigate to PrePaywallScreen.
Related functionality: Main paywall
- Callee
lib/features/onboarding/presentation/screens/pre_paywall.dartReceives users at the commercial gate.
Canonical purpose: Primary paywall UI and Superwall placement registration. Many placement IDs remain INSERT_YOUR_* placeholders.
Pre-paywall routes to MainScaffold
Verified from source Solid lineSuccessful purchase handling or an already-paid check navigates to MainScaffold.
Related functionality: Main paywall Main navigation
- Caller
lib/core/subscription/post_purchase_handler.dartRuns post-purchase updates then navigates onward.
Subscription and paywall flow
Superwall UI to purchase controller to RevenueCat to access gate, with post-purchase handling.
Parts — what each one is
Each part explains why it appears, where it lives in the repository, and which files to read.
Superwall paywall UI
Verified from sourcePresents campaigns registered by placement IDs from PrePaywall and feature screens.
Related functionality: Main paywall Soft paywalls and quotas
lib/features/onboarding, lib/features/app/
- lib/
- features/
- onboarding/
- presentation/
- screens/
pre_paywall.dart
- screens/
- presentation/
- onboarding/
- features/
- Caller
lib/features/onboarding/presentation/screens/pre_paywall.dartRegisters primary gift/standard placements (often placeholders).
Canonical purpose: Primary paywall UI and Superwall placement registration. Many placement IDs remain INSERT_YOUR_* placeholders.
Uncertain: Dashboard campaign mapping not verified.
SuperwallPurchaseController
Verified from sourceReceives Superwall purchase/restore requests and executes them via RevenueCat.
Related functionality: Subscription access gating
lib/core/superwall/
- lib/
- core/
- superwall/
superwall_purchase_controller.dart
- superwall/
- core/
- Primary implementation
lib/core/superwall/superwall_purchase_controller.dartImplements PurchaseController purchase/restore and status sync.
Canonical purpose: Maps Superwall purchase/restore actions to RevenueCat and syncs subscription status back to Superwall.
RevenueCat
Verified from sourceTalks to App Store / Play Billing and exposes CustomerInfo entitlements.
Related functionality: Subscription access gating
purchases_flutter/
- lib/
main.dart
- Entry point
lib/main.dartEarly Purchases.configure using platform API key names.
Canonical purpose: Cold-start bootstrap: dotenv, RevenueCat, Firebase, analytics, notifications, Superwall, deep links, and startup routing into onboarding, paywall, or MainScaffold.
SubscriptionService gate
Verified from sourceAnswers isPaidSubscriber for routing and feature checks.
Related functionality: Subscription access gating Startup routing
lib/core/subscription/
- lib/
- core/
- subscription/
subscription_service.dart
- subscription/
- core/
- Primary implementation
lib/core/subscription/subscription_service.dartCombines Superwall status and RevenueCat CustomerInfo; ignores Firestore for grants.
Canonical purpose: Paid-access decisions from Superwall subscription status and RevenueCat CustomerInfo. Firestore subscription fields are not the entitlement source of truth.
PostPurchaseHandler
Verified from sourceAfter success, updates user state and navigates to congratulations / main.
Related functionality: Main paywall
lib/core/subscription/
- lib/
- core/
- subscription/
post_purchase_handler.dart
- subscription/
- core/
- Primary implementation
lib/core/subscription/post_purchase_handler.dartCoordinates post-purchase side effects and navigation.
Connections — why they connect
Each connection names the concrete mechanism linking its two parts. The mechanism is the proof the relationship passed the explainability gate.
Superwall paywall UI delegates to SuperwallPurchaseController
Inferred from source Dashed lineSuperwall UI delegates store purchase and restore actions to SuperwallPurchaseController when configured.
Basis for the inference: iOS configure path passes purchaseController; Android early configure does not, so delegation is platform-dependent.
Related functionality: Main paywall
- Callee
lib/core/superwall/superwall_purchase_controller.dartImplements the PurchaseController callbacks Superwall invokes.
Canonical purpose: Maps Superwall purchase/restore actions to RevenueCat and syncs subscription status back to Superwall.
Uncertain: Android path may not attach the controller.
SuperwallPurchaseController calls RevenueCat
Verified from source Solid lineThe controller calls RevenueCat product lookup, purchase, and restore APIs.
Related functionality: Subscription access gating
- Caller
lib/core/superwall/superwall_purchase_controller.dartInvokes Purchases.purchaseStoreProduct / restorePurchases.
Canonical purpose: Maps Superwall purchase/restore actions to RevenueCat and syncs subscription status back to Superwall.
RevenueCat returns to SubscriptionService gate
Verified from source Solid lineSubscriptionService reads CustomerInfo (and Superwall status) to decide paid access.
Related functionality: Subscription access gating
- Callee
lib/core/subscription/subscription_service.dartisPaidSubscriber inspects entitlements/subscriptions.
Canonical purpose: Paid-access decisions from Superwall subscription status and RevenueCat CustomerInfo. Firestore subscription fields are not the entitlement source of truth.
SuperwallPurchaseController emits PostPurchaseHandler
Inferred from source Dashed linePaywall success handling invokes PostPurchaseHandler to finalize onboarding-side effects.
Basis for the inference: PrePaywall calls PostPurchaseHandler on success; controller sync also updates status — success orchestration spans both.
Related functionality: Main paywall
- Callee
lib/core/subscription/post_purchase_handler.darthandlePostPurchase runs after a successful purchase path.
Uncertain: Exact ordering of Firestore writes vs navigation not single-step traced.
Understand the technical system
Where data and entitlements live.
Persistence and storage map
Feature writers to Firestore, SharedPreferences, HomeWidget, and Firebase Storage.
Parts — what each one is
Each part explains why it appears, where it lives in the repository, and which files to read.
Feature repositories
Verified from sourceDomain code that reads and writes user, community, nutrition, and challenge data.
Related functionality: Calorie nutrition tracking Community forum Twenty-eight day challenge
lib/features, lib/core/
- lib/
- features/
- nutrition/
- data/
- repositories/
nutrition_repository.dart
- repositories/
- data/
- nutrition/
- features/
- Primary implementation
lib/features/nutrition/data/repositories/nutrition_repository.dartRepresentative Firestore writer for food logs and goals.
Canonical purpose: Nutrition Firestore hub for food_logs, daily_summaries, goals, body metrics, and workouts.
Cloud Firestore
Verified from sourcePrimary shared database for users, community, accountability, and quotas.
Related functionality: Firebase authentication Community forum Accountability partners
cloud/
firestore.rules
- Validation
firestore.rulesServer-side rules governing client access to collections.
Canonical purpose: Server-side Firestore access rules for users, community, accountability, and related collections.
SharedPreferences
Verified from sourceFast local keys for onboarding resume, streaks, fasting, and notification prefs.
Related functionality: Startup routing Sugar streak tracking Fasting tracker
device/
- lib/
- features/
- onboarding/
- data/
- services/
onboarding_progress_service.dart
- services/
- data/
- onboarding/
- features/
- Storage
lib/features/onboarding/data/services/onboarding_progress_service.dartOwns onboarding_* preference keys used at startup.
Canonical purpose: SharedPreferences + Firestore resume checkpoints and onboarding_completed for startup routing.
HomeWidget bridge
Verified from sourcePushes selected values to iOS/Android home screen widgets.
Related functionality: Home screen widgets
lib/core/streak, ios/StreakWidget, android providers/
- lib/
- core/
- streak/
streak_service.dart
- streak/
- core/
- Integration adapter
lib/core/streak/streak_service.dartSets app group id and updates widget data.
Canonical purpose: Streak persistence (SharedPreferences + Firestore) and home_widget sync. iOS app group id is still group.YOUR_BUNDLE_ID.shared.
Uncertain: App group placeholder blocks real iOS sync.
Firebase Storage
Verified from sourceOptional remote store for food images via LocalFoodImageService.
Related functionality: Sugar food scanning
cloud/
- lib/
- core/
- services/
local_food_image_service.dart
- services/
- core/
- Primary implementation
lib/core/services/local_food_image_service.dartCaches images locally and can upload/fallback to Storage.
Connections — why they connect
Each connection names the concrete mechanism linking its two parts. The mechanism is the proof the relationship passed the explainability gate.
Feature repositories writes Cloud Firestore
Verified from source Solid lineRepositories write user, community, nutrition, and challenge documents to Firestore.
Related functionality: Calorie nutrition tracking Community forum
- Caller
lib/features/community/data/repositories/community_repository.dartWrites community_posts and comments.
Canonical purpose: Community posts/comments Firestore repository for the forum surface.
Feature repositories stores in SharedPreferences
Verified from source Solid lineOnboarding, streak, fasting, and similar features store resume/fast state in SharedPreferences.
Related functionality: Startup routing Fasting tracker
- Caller
lib/features/fasting/data/repositories/fasting_repository.dartPersists fasting_logs_v1 locally only.
Canonical purpose: Local-only fasting logs and active timer cache in SharedPreferences.
SharedPreferences sends to HomeWidget bridge
Inferred from source Dashed lineStreak and accountability services push values through HomeWidget into native widgets.
Basis for the inference: Flutter update calls verified; native Swift/Kotlin read path inferred from suiteName/providers.
Related functionality: Home screen widgets Sugar streak tracking
- Caller
lib/core/accountability/accountability_widget_service.dartUpdates accountability widget payloads.
Uncertain: Placeholder app group may prevent iOS delivery.
Feature repositories writes Firebase Storage
Inferred from source Dashed lineLocalFoodImageService can upload cached food images to Firebase Storage as a fallback/remote path.
Basis for the inference: Service responsibilities traced; every upload call site not enumerated.
Related functionality: Sugar food scanning
- Caller
lib/core/services/local_food_image_service.dartImplements upload/fallback for food images.
Uncertain: When upload vs local-only is chosen may depend on runtime flags.
Understand uncertainty
Configuration landmines and unverified edges.
Risk and uncertainty map
Verified configuration landmines that can break auth, paywalls, widgets, or quota soft-gates.
Parts — what each one is
Each part explains why it appears, where it lives in the repository, and which files to read.
Superwall placement placeholders
Verified from sourceMany registerPlacement calls still use INSERT_YOUR_* strings instead of real IDs.
Related functionality: Main paywall Soft paywalls and quotas
lib/features, lib/core/
- lib/
- features/
- onboarding/
- presentation/
- screens/
pre_paywall.dart
- screens/
- presentation/
- onboarding/
- features/
- Primary implementation
lib/features/onboarding/presentation/screens/pre_paywall.dartContains primary INSERT_YOUR_* placement registrations.
Canonical purpose: Primary paywall UI and Superwall placement registration. Many placement IDs remain INSERT_YOUR_* placeholders.
⚠ Warnings: Superwall placement IDs are placeholders
Android Superwall wiring
Verified from sourceAndroid configure path does not attach SuperwallPurchaseController like iOS.
Related functionality: Subscription access gating
lib/main.dart/
- lib/
main.dart
- Entry point
lib/main.dartEarly Android Superwall.configure omits purchaseController.
Canonical purpose: Cold-start bootstrap: dotenv, RevenueCat, Firebase, analytics, notifications, Superwall, deep links, and startup routing into onboarding, paywall, or MainScaffold.
⚠ Warnings: Android Superwall purchase controller wiring is incomplete
Uncertain: Runtime purchase impact not executed.
OAuth / env fallbacks
Verified from sourceMissing env values fall back to placeholder OAuth client IDs; main loads .env while repo has .env.local.
Related functionality: Firebase authentication Application startup
lib/core/auth, lib/core/config/
- lib/
- core/
- auth/
auth_service.dart
- auth/
- core/
- Primary implementation
lib/core/auth/auth_service.dartEmbeds INSERT_YOUR_* Google client ID fallbacks.
Canonical purpose: Firebase Auth (Google, Apple, email) plus RevenueCat/Mixpanel identity sync and users/{uid} profile writes. Google OAuth fallbacks are placeholders when env is missing.
⚠ Warnings: Google OAuth client ID fallbacks Repository has .env.local but main loads .env
Widget app group placeholder
Verified from sourceHome widgets reference group.YOUR_BUNDLE_ID.shared until a real group is configured.
Related functionality: Home screen widgets
lib/core/streak, ios entitlements/
- lib/
- core/
- streak/
streak_service.dart
- streak/
- core/
- Configuration
lib/core/streak/streak_service.dartDefines the placeholder app group constant.
Canonical purpose: Streak persistence (SharedPreferences + Firestore) and home_widget sync. iOS app group id is still group.YOUR_BUNDLE_ID.shared.
⚠ Warnings: iOS widget app group ID is a placeholder
Disabled quota flags
Verified from sourceFeatureQuota soft-paywalls exist but QUOTA_SYSTEM_ENABLED is false on major screens.
Related functionality: Soft paywalls and quotas
feature screens/
- lib/
- features/
- learn/
- presentation/
- screens/
learn_video_list_screen.dart
- screens/
- presentation/
- learn/
- features/
- Primary implementation
lib/features/learn/presentation/screens/learn_video_list_screen.dartHard-codes QUOTA_SYSTEM_ENABLED = false.
Connections — why they connect
Each connection names the concrete mechanism linking its two parts. The mechanism is the proof the relationship passed the explainability gate.
Android Superwall wiring configures Superwall placement placeholders
Verified from source Solid lineAndroid Superwall configuration controls whether placement-driven purchases can reach SuperwallPurchaseController.
Related functionality: Main paywall Subscription access gating
- Configuration
lib/main.dartPlatform branch decides whether purchaseController is passed to Superwall.configure.
Canonical purpose: Cold-start bootstrap: dotenv, RevenueCat, Firebase, analytics, notifications, Superwall, deep links, and startup routing into onboarding, paywall, or MainScaffold.
Disabled quota flags configures Superwall placement placeholders
Verified from source Solid lineQUOTA_SYSTEM_ENABLED flags configure whether feature screens invoke quota checks that lead to soft Superwall placements.
Related functionality: Soft paywalls and quotas
- Configuration
lib/features/app/presentation/screens/chatbot/chatbot_screen.dartLocal flag disables quota path before placement registration.
Canonical purpose: Melinda CBT assistant using Groq chat/transcription and OpenAI speech, with daily API interaction limits.