Mobile App Setup

The AI Ingredient Scanner mobile app is built with React Native and Expo, supporting both iOS and Android devices.


Prerequisites

RequirementVersionPurpose
Node.js18+JavaScript runtime
npm9+Package manager
Expo CLILatestDevelopment tools
Expo Go appiOS/AndroidDevice testing

Quick Start

Step 1: Install Dependencies

cd mobile
npm install

Step 2: Configure API URL

Find your machine's IP address:

macOS
ipconfig getifaddr en0
Linux
hostname -I | awk '{print $1}'
Windows
ipconfig | findstr IPv4

Edit src/services/api.ts:

const API_BASE_URL = 'http://YOUR_IP_ADDRESS:8000';
Important

Do not use localhost - the mobile device cannot resolve it. Use your actual IP address.

Step 3: Start Backend API

In a separate terminal:

cd /path/to/IngredientScanner
source venv/bin/activate
uvicorn api:app --host 0.0.0.0 --port 8000

Step 4: Launch Mobile App

cd mobile
npx expo start

Step 5: Connect Your Device

  1. 1Install Expo Go from App Store (iOS) or Play Store (Android)
  2. 2Scan the QR code displayed in terminal
  3. 3App loads on your device

Project Structure

mobile/
ā”œā”€ā”€ App.tsx                     # App entry with Auth & Theme providers
ā”œā”€ā”€ app.json                    # Expo configuration
ā”œā”€ā”€ package.json                # Dependencies
ā”œā”€ā”€ tsconfig.json               # TypeScript config
│
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ components/
│   │   ā”œā”€ā”€ ImageCapture.tsx    # Camera & gallery interface
│   │   ā”œā”€ā”€ IngredientCard.tsx  # Expandable ingredient details
│   │   ā”œā”€ā”€ PrivacyPolicyModal.tsx # In-app privacy policy display
│   │   ā”œā”€ā”€ ProfileAvatar.tsx   # User avatar (photo or initial)
│   │   ā”œā”€ā”€ ProfileSelector.tsx # User profile, auth & theme settings
│   │   ā”œā”€ā”€ ResultsHeader.tsx   # Analysis summary header
│   │   ā”œā”€ā”€ RiskBadge.tsx       # Risk level indicator
│   │   ā”œā”€ā”€ SafetyBar.tsx       # Safety score bar
│   │   └── SafetyMeter.tsx     # Overall safety visualization
│   │
│   ā”œā”€ā”€ screens/
│   │   ā”œā”€ā”€ HomeScreen.tsx      # Main app screen
│   │   └── LoginScreen.tsx     # Authentication screen
│   │
│   ā”œā”€ā”€ context/
│   │   ā”œā”€ā”€ ThemeContext.tsx    # Dark/Light theme state
│   │   ā”œā”€ā”€ AuthContext.tsx     # Firebase authentication state
│   │   └── PreferencesContext.tsx # User preferences with Firestore sync
│   │
│   ā”œā”€ā”€ config/
│   │   └── firebase.ts         # Firebase configuration
│   │
│   ā”œā”€ā”€ services/
│   │   ā”œā”€ā”€ api.ts              # Backend API client
│   │   └── ocr.ts              # Image processing & OCR
│   │
│   └── types/
│       └── index.ts            # TypeScript definitions
│
└── assets/
    ā”œā”€ā”€ icon.png                # App icon
    ā”œā”€ā”€ splash-icon.png         # Splash screen
    ā”œā”€ā”€ adaptive-icon.png       # Android adaptive icon
    └── google-icon.png         # Google Sign-In button icon

Development Commands

CommandPurpose
npx expo startStart development server
npx expo start --clearClear cache and start
npx expo start --tunnelRun with tunnel (network issues)
npx tsc --noEmitTypeScript type checking

Dependencies

PackagePurpose
expoDevelopment framework
expo-cameraCamera access
expo-image-pickerGallery selection
expo-auth-sessionOAuth authentication flow
firebaseAuthentication & Firestore
@react-native-async-storage/async-storageLocal preferences storage
axiosHTTP client

Network Configuration

The mobile device must be on the same network as your development machine:

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│                    NETWORK SETUP                             │
│                                                              │
│    ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”         ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”                  │
│    │   Mobile    │  WiFi   │   Router    │                  │
│    │   Device    │◄───────►│  (Network)  │                  │
│    ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜         ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                  │
│                                   │                          │
│                              WiFi/Ethernet                   │
│                                   │                          │
│                            ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā–¼ā”€ā”€ā”€ā”€ā”€ā”€ā”                  │
│                            │    Dev      │                  │
│                            │   Machine   │                  │
│                            ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                  │
│                                   │                          │
│                              Port 8000                       │
│                                   │                          │
│                            ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā–¼ā”€ā”€ā”€ā”€ā”€ā”€ā”                  │
│                            │  FastAPI    │                  │
│                            │   Server    │                  │
│                            ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Firewall Settings

If connection fails, ensure port 8000 is allowed through your firewall.

macOS
# Check if firewall is enabled
sudo /usr/libexec/ApplicationFirewall/\
socketfilterfw --getglobalstate
Windows

Open Windows Defender Firewall → Allow an app through firewall → Add Python or uvicorn


Troubleshooting

"Cannot connect to server"
  1. Verify backend is running: curl http://YOUR_IP:8000/health
  2. Ensure phone and computer are on same WiFi network
  3. Check IP address in api.ts
  4. Temporarily disable firewall to test
Camera not working
  • Grant camera permission when prompted
  • iOS: Settings → Expo Go → Camera
  • Android: Settings → Apps → Expo Go → Permissions
OCR not extracting text
  • Ensure good lighting conditions
  • Hold camera steady
  • Frame the ingredient list clearly
  • Try selecting a clearer image from gallery
Metro bundler issues
# Kill existing processes and restart
npx expo start --clear

# Or manually kill
lsof -i :8081 | grep LISTEN | awk '{print $2}' | xargs kill -9

Related Documentation