#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")/.." echo "Starting Planarchy..." # 1. Start Docker services echo " Starting PostgreSQL + Redis..." docker compose up -d postgres redis sleep 2 # 2. Wait for PostgreSQL to be healthy echo " Waiting for PostgreSQL..." for i in {1..30}; do if docker exec planarchy-postgres-1 pg_isready -U planarchy -q 2>/dev/null; then break fi sleep 1 done # 3. Regenerate Prisma client echo " Generating Prisma client..." pnpm --filter @planarchy/db exec prisma generate --no-hints 2>/dev/null # 4. Clear stale Next.js cache rm -rf apps/web/.next # 5. Start Next.js dev server echo " Starting Next.js on port 3100..." nohup pnpm --filter @planarchy/web dev > /tmp/planarchy-dev.log 2>&1 & echo $! > /tmp/planarchy-dev.pid # 6. Wait for server to be ready echo " Waiting for server..." for i in {1..30}; do if curl -sf http://localhost:3100/api/health > /dev/null 2>&1; then echo "" echo "Planarchy is running!" curl -s http://localhost:3100/api/ready | python3 -m json.tool 2>/dev/null || curl -s http://localhost:3100/api/ready echo "" echo " URL: http://localhost:3100" echo " Logs: tail -f /tmp/planarchy-dev.log" echo " PID: $(cat /tmp/planarchy-dev.pid)" exit 0 fi sleep 1 done echo "ERROR: Server failed to start within 30 seconds" echo "Check logs: tail -50 /tmp/planarchy-dev.log" exit 1