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
- Expo - Development platform and deployment
- React Native - Cross-platform mobile framework
- TypeScript - Type safety and development experience
- Expo Router - File-based routing system
UI & Design
- React Native Reanimated - Smooth animations
- Moti - Declarative animations
- Lucide React Native - Icon system
- React Native Gesture Handler - Touch interactions
Key Dependencies
- Expo Linear Gradient - Gradient backgrounds
- Date-fns - Date manipulation
- AsyncStorage - Local data persistence
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 managementOrderSyncService.ts- Server submission logicSyncService.ts- Mobile sync coordinationLocalDatabase.ts- Live order caching
Edge Functions
submit-order- Processes order submissionassign-order-number- Generates proper order numbersmobile-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 viaorder_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 processingOrderSyncService.ts- Payment-order linkingPaymentForm.tsx- Frontend payment interface
Edge Functions
create-payment-intent- Generates Stripe payment intentsstripe-webhook-handler- Processes payment confirmationsupdate-order-payment- Links payments to orders
Local Storage
- Payment methods cached in
AsyncStoragefor 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
| Method | Best For | Global Access | Setup Required |
|---|---|---|---|
| 🔗 EAS Update | Quick sharing, testing | ✅ Yes | Expo account |
| 📱 Expo Go | Development, demos | ✅ Yes | None |
| 🏪 App Stores | Production release | ✅ Yes | Developer accounts |
| 🌐 Web Deploy | Browser access | ✅ Yes | Hosting service |
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