Skip to main content

Mobile App Setup

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

Prerequisitesโ€‹

RequirementVersion
Node.js18+
npm9+
Expo CLILatest
Expo Go appiOS/Android

Quick Startโ€‹

1. Install Dependenciesโ€‹

cd mobile
npm install

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.

3. Start Backend APIโ€‹

In a separate terminal:

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

4. Launch Mobile Appโ€‹

cd mobile
npx expo start

5. Connect Your Deviceโ€‹

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

Project Structureโ€‹

mobile/
โ”œโ”€โ”€ App.tsx # App entry with ThemeProvider
โ”œโ”€โ”€ app.json # Expo configuration
โ”œโ”€โ”€ package.json # Dependencies
โ”œโ”€โ”€ tsconfig.json # TypeScript config
โ”‚
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ components/
โ”‚ โ”‚ โ”œโ”€โ”€ ImageCapture.tsx # Camera & gallery interface
โ”‚ โ”‚ โ”œโ”€โ”€ IngredientCard.tsx # Expandable ingredient details
โ”‚ โ”‚ โ”œโ”€โ”€ ProfileSelector.tsx # User profile & 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
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ context/
โ”‚ โ”‚ โ””โ”€โ”€ ThemeContext.tsx # Dark/Light theme state
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ 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

Development Commandsโ€‹

Start Development Serverโ€‹

npx expo start

Clear Cacheโ€‹

npx expo start --clear

Run with Tunnel (Network Issues)โ€‹

npx expo start --tunnel

Type Checkingโ€‹

npx tsc --noEmit

Dependenciesโ€‹

PackagePurpose
expoDevelopment framework
expo-cameraCamera access
expo-image-pickerGallery selection
expo-status-barStatus bar styling
expo-file-systemFile operations
react-native-safe-area-contextSafe area handling
axiosHTTP client

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

Camera not workingโ€‹

  1. Grant camera permission when prompted
  2. iOS: Settings > Expo Go > Camera
  3. Android: Settings > Apps > Expo Go > Permissions

OCR not extracting textโ€‹

  1. Ensure good lighting
  2. Hold camera steady
  3. Frame the ingredient list clearly
  4. Try selecting a clearer image from gallery

App crashes on launchโ€‹

  1. Clear Expo Go cache: shake device > "Reload"
  2. Restart Expo development server
  3. Check terminal for error messages

Metro bundler issuesโ€‹

# Kill existing processes
npx expo start --clear

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

Network Configurationโ€‹

Same Network Requirementโ€‹

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

Firewall Settingsโ€‹

If connection fails, ensure port 8000 is allowed:

macOS:

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

# Allow Python/uvicorn through firewall
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /usr/bin/python3

Windows:

  1. Open Windows Defender Firewall
  2. Click "Allow an app through firewall"
  3. Add Python or uvicorn