Skip to main content

Mobile App Architecture

Overview

The ADHD Simple mobile app is a React Native application built with Expo, designed to provide patients with an intuitive interface for managing ADHD medications and prescriptions. The app follows an offline-first architecture with robust sync capabilities.

Tech Stack

Core Framework

UI & Design

Key Dependencies

Shared Services Integration

The mobile app uses a centralized ADHD-simple-shared-services repository for all backend operations:
  • Database Schema: packages/supabase/migrations/
  • Edge Functions: packages/supabase/functions/ (45+ functions)
  • Configuration: packages/supabase/config.toml

Architecture Benefits

  • βœ… Single source of truth for database schema
  • βœ… Shared business logic between clinical and mobile apps
  • βœ… Centralized Edge Function management
  • βœ… Consistent data models across platforms

Development Workflow

Order Storage & Mobile Sync Architecture

System Overview

The app implements a dual-storage system for orders with mobile sync functionality to ensure offline capability and data consistency:

Local Storage Structure

Draft Orders (Pre-submission)

Live Orders (Post-submission)

Mobile Sync Flow

1. Draft Order Creation

2. Order Submission

3. Live Data Sync

Key Benefits

  • πŸ“± Offline Support: Draft orders work without internet
  • πŸ”„ Real-time Sync: Live orders always show current server state
  • πŸ—‘οΈ Clean Separation: Drafts deleted after submission (no duplication)
  • ⚑ Performance: Local caching with smart sync
  • πŸ”’ Data Consistency: Single source of truth for submitted orders

Technical Implementation

Storage Services

  • LocalOrderService.ts - Draft order management
  • OrderSyncService.ts - Server submission logic
  • SyncService.ts - Mobile sync coordination
  • LocalDatabase.ts - Live order caching

Edge Functions

  • submit-order - Processes order submission
  • assign-order-number - Generates proper order numbers
  • mobile-application-patient-sync - Syncs live data

Database Views

  • order_details_unified - Combines order_requests + prescription_orders
  • Provides consistent interface for mobile app

Payment Storage & Receipt System

Payment Architecture

The app uses a multi-table payment system with Stripe integration to handle transactions and generate detailed receipts:

Payment Tables Structure

payment_intents - Stripe Payment Tracking

order_payments - Final Payment Records

order_line_items - Receipt Line Items

Payment Flow & Receipt Generation

1. Payment Processing

2. Webhook Processing

Key Features

βœ… Itemized Receipts - Full breakdown via order_line_items
βœ… Stripe Integration - Secure payment processing with webhooks
βœ… Payment Tracking - Complete audit trail from intent to confirmation
βœ… Dynamic Generation - No stored receipt files, built from live data
βœ… Multi-Currency - Supports GBP, USD, EUR
βœ… Member Pricing - Different rates for subscribers

Technical Implementation

Payment Services

  • StripeService.ts - Payment intent creation and processing
  • OrderSyncService.ts - Payment-order linking
  • PaymentForm.tsx - Frontend payment interface

Edge Functions

  • create-payment-intent - Generates Stripe payment intents
  • stripe-webhook-handler - Processes payment confirmations
  • update-order-payment - Links payments to orders

Local Storage

  • Payment methods cached in AsyncStorage for saved cards
  • Payment records stored locally for offline receipt access
  • Stripe customer ID synced across devices

Project Structure

Configuration

App Configuration (app.json)

Available Scripts

Deployment

EAS Update

The app uses EAS Update for seamless global distribution:

Distribution Options

Core Features

Cross-Platform Support

  • πŸ“± iOS and Android native apps
  • 🌐 Web browser support
  • πŸ“Ί Responsive design for all screen sizes

Technical Features

  • ⚑ File-based routing with Expo Router
  • 🎭 Smooth animations with Reanimated and Moti
  • 🎨 Consistent design system
  • πŸ”„ Real-time sync with offline support
  • πŸ” Secure authentication and data handling

User Experience

  • 🏠 Intuitive tab-based navigation
  • πŸ”” Push notification support
  • πŸ’³ Secure payment processing
  • πŸ“¦ Order tracking and management
  • βš™οΈ Comprehensive settings management