loop

Moldi Monorepo

Unified repository for Moldi’s FastAPI backend and Expo mobile application.

Project Structure

loop/
├── apps/
│   ├── api/          # FastAPI backend (Python 3.11)
│   └── mobile/       # Expo + React Native mobile app  <-- the ONLY mobile project
├── packages/
│   └── shared/       # Shared types and utilities (empty for now)
├── pnpm-workspace.yaml
├── package.json      # Root workspace scripts (no app entry point, by design)
├── docker-compose.yml
├── .env
└── README.md

All mobile builds run from apps/mobile. The repository root has no app.json, eas.json, metro.config.js or native android//ios/ directories — it is a workspace container, not an application. A stale second Expo project used to live here; running eas build from the root now fails immediately rather than producing a build with the wrong version code and no Firebase or AppsFlyer wiring.

Prerequisites

Getting Started

1. Install Dependencies

# Install Node.js dependencies (all workspaces)
pnpm install

# Install Python dependencies for backend
pnpm install:api

2. Set Up Environment

# Copy environment template
cp .env.example .env

# Edit .env with your configuration
# At minimum, update these values:
# - JWT_SECRET (generate a secure random string)
# - CLOUDINARY_* (if using uploads)
# - EXPO_PUBLIC_API_BASE_URL (mobile's backend URL)

# Optional: host-only overrides (recommended for local CLI commands)
# Create a .env.local with values that should override .env on your machine.
# Example (use localhost when running Alembic locally):
# DATABASE_URL=postgresql+psycopg2://loop:loop@localhost:5432/loop
# REDIS_URL=redis://localhost:6379

3. Start Infrastructure

# Start PostgreSQL and Redis
pnpm docker:up

# Run database migrations
pnpm db:migrate

4. Start Development Servers

# Start both backend and mobile in parallel
pnpm dev

# Or start individually:
pnpm dev:api      # Backend only (http://localhost:8000)
pnpm dev:mobile   # Mobile only (Expo DevTools)

Available Scripts

Root Scripts

Backend Scripts (from apps/api)

cd apps/api
source .venv/bin/activate

# Development
uvicorn app.main:app --reload

# Database
alembic upgrade head
alembic revision --autogenerate -m "migration name"
alembic downgrade -1

# Testing
pytest

Mobile Scripts (from apps/mobile)

cd apps/mobile

# Development
pnpm start       # Start Expo DevTools
pnpm android     # Open on Android device
pnpm ios         # Open on iOS device

# Utilities
pnpm seed:messages  # Seed test messages
pnpm triage:android-launch  # Collect launch/crash diagnostics from adb
pnpm triage:ios-launch  # Collect launch/crash diagnostics from xcrun simctl

Architecture

Backend (apps/api)

Key Features:

Mobile (apps/mobile)

Key Features:

Monorepo Configuration

pnpm Workspaces

Defined in pnpm-workspace.yaml:

packages:
  - 'apps/*'
  - 'packages/*'

Dependencies are hoisted to root node_modules/ for efficiency.

Metro Configuration

Mobile app uses metro.config.js to resolve dependencies from monorepo root:

Docker Compose

Services:

Environment Variables

The backend reads .env and then .env.local (local overrides win). Use .env.local for host-only settings (e.g., localhost DB/Redis) while keeping Docker defaults in .env.

Backend Variables

See .env.example for full list. Key variables:

Mobile Variables

Note: Expo only exposes variables with EXPO_PUBLIC_ prefix to the app.

Troubleshooting

Backend won’t start

Mobile bundler errors

Mobile can’t connect to backend

Android Google Sign-In returns DEVELOPER_ERROR (Play closed testing)

Database migration errors

Migration from Separate Repos

This monorepo consolidates:

Git history was reset for simplicity. Old repositories remain at original paths for reference.

Development Workflow

Single Command Development

# Start everything
pnpm dev

This runs:

Individual Service Development

# Backend only
pnpm dev:api

# Mobile only
pnpm dev:mobile

Testing Mobile on Physical Device

  1. Start backend: pnpm dev:api
  2. Get your computer’s local IP: ifconfig | grep "inet "
  3. Update .env:
    EXPO_PUBLIC_API_BASE_URL=http://192.168.x.x:8000/api
    
  4. Start mobile: pnpm dev:mobile
  5. Scan QR code with Expo Go app

Contributing

  1. Create a feature branch
  2. Make your changes
  3. Test both backend and mobile
  4. Submit a pull request

License

This project is proprietary software. All rights reserved. See LICENSE for details.