Mobile App Setup
The AI Ingredient Scanner mobile app is built with React Native and Expo, supporting both iOS and Android.
Prerequisitesโ
| Requirement | Version |
|---|---|
| Node.js | 18+ |
| npm | 9+ |
| Expo CLI | Latest |
| Expo Go app | iOS/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โ
- Install Expo Go from App Store (iOS) or Play Store (Android)
- Scan the QR code displayed in terminal
- 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โ
| Package | Purpose |
|---|---|
expo | Development framework |
expo-camera | Camera access |
expo-image-picker | Gallery selection |
expo-status-bar | Status bar styling |
expo-file-system | File operations |
react-native-safe-area-context | Safe area handling |
axios | HTTP client |
Troubleshootingโ
"Cannot connect to server"โ
- Verify backend is running:
curl http://YOUR_IP:8000/health - Ensure phone and computer are on same WiFi network
- Check IP address in
api.ts - Temporarily disable firewall
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
- Hold camera steady
- Frame the ingredient list clearly
- Try selecting a clearer image from gallery
App crashes on launchโ
- Clear Expo Go cache: shake device > "Reload"
- Restart Expo development server
- 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:
- Open Windows Defender Firewall
- Click "Allow an app through firewall"
- Add Python or uvicorn