Mobile App Setup
The AI Ingredient Scanner mobile app is built with React Native and Expo, supporting both iOS and Android devices.
Prerequisites
| Requirement | Version | Purpose |
|---|---|---|
| Node.js | 18+ | JavaScript runtime |
| npm | 9+ | Package manager |
| Expo CLI | Latest | Development tools |
| Expo Go app | iOS/Android | Device 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
- 1Install Expo Go from App Store (iOS) or Play Store (Android)
- 2Scan the QR code displayed in terminal
- 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 iconDevelopment Commands
| Command | Purpose |
|---|---|
| npx expo start | Start development server |
| npx expo start --clear | Clear cache and start |
| npx expo start --tunnel | Run with tunnel (network issues) |
| npx tsc --noEmit | TypeScript type checking |
Dependencies
| Package | Purpose |
|---|---|
| expo | Development framework |
| expo-camera | Camera access |
| expo-image-picker | Gallery selection |
| expo-auth-session | OAuth authentication flow |
| firebase | Authentication & Firestore |
| @react-native-async-storage/async-storage | Local preferences storage |
| axios | HTTP 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"
- 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 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