Complete guide for setting up Chapters backend, web frontend, and mobile app.
- Docker Desktop (for database services)
- Node.js 18+ and npm (for frontend/mobile)
- Python 3.11+ and Poetry (for backend - if running locally)
- Expo CLI (for mobile development)
You have two options for running the backend:
This runs everything (PostgreSQL, Redis, and Backend API) in Docker containers.
# Start all services
docker-compose --profile full up
# Or run in detached mode
docker-compose --profile full up -dServices will be available at:
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- PostgreSQL: localhost:5432
- Redis: localhost:6379
To stop:
docker-compose down
# To reset everything (fresh start)
docker-compose down -vThis gives you hot-reload and easier debugging.
docker-compose up -d postgres redisWait ~10 seconds for services to be healthy:
docker psYou should see chapters-postgres and chapters-redis with status "healthy".
cd backend
# Install Poetry (if not installed)
pip install poetry
# Install dependencies
poetry install
# Or use pip directly
pip install -r requirements.txt # if you have oneThe backend/.env file is already set up for local development. Update if needed:
DATABASE_URL=postgresql://chapters:chapters@localhost:5432/chapters
REDIS_URL=redis://localhost:6379/0
SECRET_KEY=dev-secret-key-change-in-production
OPENAI_API_KEY=sk-your-key-here # Optional, for Muse AI features
DEBUG=truepoetry run alembic upgrade headpoetry run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Backend will be available at:
- API: http://localhost:8000
- Interactive Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
The web frontend is built with Next.js 14 and React.
cd frontend
npm installCreate frontend/.env.local (or use the example):
NEXT_PUBLIC_API_URL=http://localhost:8000npm run devFrontend will be available at: http://localhost:3000
npm run build
npm startThe mobile app is built with React Native and Expo.
cd mobile
npm installnpm install -g expo-cli
# Or use npx
npx expo --versionUpdate mobile/.env:
API_URL=http://localhost:8000
# For testing on physical device, use your computer's IP:
# API_URL=http://192.168.1.XXX:8000npm start
# Or
npx expo startiOS Simulator:
npm run ios
# Or press 'i' in the Expo terminalAndroid Emulator:
npm run android
# Or press 'a' in the Expo terminalPhysical Device:
- Install Expo Go app from App Store/Play Store
- Scan the QR code shown in terminal
- Make sure your device is on the same WiFi network
- Update
API_URLin.envto use your computer's local IP
Terminal 1 - Backend:
# Option A: Docker
docker-compose --profile full up
# Option B: Local
docker-compose up -d postgres redis
cd backend
poetry run uvicorn app.main:app --reloadTerminal 2 - Web Frontend:
cd frontend
npm run devTerminal 3 - Mobile App (Optional):
cd mobile
npm startVisit http://localhost:8000/docs - you should see the Swagger API documentation.
Try the health check endpoint:
curl http://localhost:8000/health- Go to http://localhost:3000
- Click "Start Your Book" to register
- Create an account
- You should be redirected to the Library
- Open Expo Go on your device
- Scan the QR code
- App should load and show the home screen
- Try registering/logging in
# Connect to PostgreSQL
docker exec -it chapters-postgres psql -U chapters -d chapters
# List tables
\dt
# View users
SELECT * FROM users;
# Exit
\q# Stop and remove volumes
docker-compose down -v
# Start fresh
docker-compose up -d postgres redis
# Run migrations
cd backend
poetry run alembic upgrade headcd backend
poetry run alembic revision --autogenerate -m "description of changes"
poetry run alembic upgrade headPostgreSQL (5432):
# Windows
netstat -ano | findstr :5432
taskkill /PID <PID> /F
# Mac/Linux
lsof -ti:5432 | xargs kill -9Backend (8000):
# Windows
netstat -ano | findstr :8000
taskkill /PID <PID> /F
# Mac/Linux
lsof -ti:8000 | xargs kill -9Frontend (3000):
# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F
# Mac/Linux
lsof -ti:3000 | xargs kill -9# Restart Docker Desktop
# Remove all containers and volumes
docker-compose down -v
# Rebuild containers
docker-compose build --no-cache
# View logs
docker-compose logs backend
docker logs chapters-postgres- Check if PostgreSQL is running:
docker ps - Check database connection:
docker logs chapters-postgres - Verify
.envfile has correctDATABASE_URL - Try resetting migrations:
poetry run alembic downgrade base && poetry run alembic upgrade head
# Clear Next.js cache
cd frontend
rm -rf .next
npm run dev- Make sure backend is running:
curl http://localhost:8000/health - If using physical device, update
API_URLto your computer's IP - Check firewall isn't blocking port 8000
- Restart Expo:
rin terminal or shake device and tap "Reload"
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://chapters:chapters@localhost:5432/chapters |
REDIS_URL |
Redis connection string | redis://localhost:6379/0 |
SECRET_KEY |
JWT secret key | dev-secret-key |
OPENAI_API_KEY |
OpenAI API key for Muse | Optional |
S3_BUCKET |
S3/R2 bucket for media | Optional |
DEBUG |
Enable debug mode | true |
| Variable | Description | Default |
|---|---|---|
NEXT_PUBLIC_API_URL |
Backend API URL | http://localhost:8000 |
| Variable | Description | Default |
|---|---|---|
API_URL |
Backend API URL | http://localhost:8000 |
# Build Docker image
docker build -t chapters-backend ./backend
# Run with production settings
docker run -p 8000:8000 \
-e DATABASE_URL=postgresql://... \
-e SECRET_KEY=... \
chapters-backendcd frontend
npm run build
npm startcd mobile
eas build --platform ios
eas build --platform android# Run tests
cd backend
poetry run pytest
# Format code
poetry run black .
# Type checking
poetry run mypy .
# Create admin user (if you have a script)
poetry run python scripts/create_admin.py# Type check
npm run type-check
# Lint
npm run lint
# Build
npm run build# Clear cache
npx expo start -c
# Run on specific device
npx expo run:ios --device "iPhone 14"
npx expo run:android --device emulator-5554- Backend Issues: Check
docker logs chapters-backendor backend console output - Frontend Issues: Check browser console (F12)
- Mobile Issues: Shake device → "Show Dev Menu" → "Debug Remote JS"
- Database Issues: Check
docker logs chapters-postgres
- ✅ Get all services running
- ✅ Create a test account
- ✅ Publish a test chapter
- ✅ Test on mobile device
- 🚀 Start building features!
Happy coding! 📖