# AudioForge Development Startup Script # Starts PostgreSQL/Redis, initializes DB, then starts backend and frontend param( [switch]$SkipServices = $false, [switch]$Help = $false ) $Colors = @{ Red = "Red" Green = "Green" Yellow = "Yellow" Blue = "Cyan" Cyan = "Cyan" } function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue } function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green } function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow } function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red } if ($Help) { Write-Host @" AudioForge Development Startup Script Usage: .\scripts\dev_start.ps1 [-SkipServices] [-Help] Options: -SkipServices Skip starting PostgreSQL/Redis (assume they're already running) -Help Show this help message This script will: 1. Start PostgreSQL and Redis (if not skipped) 2. Wait for services to be ready 3. Initialize the database 4. Start backend server in background 5. Start frontend server in background "@ exit 0 } $ProjectRoot = Split-Path -Parent $PSScriptRoot Set-Location $ProjectRoot # Step 1: Start PostgreSQL and Redis if (-not $SkipServices) { Write-Info "Starting PostgreSQL and Redis..." # Check if Docker is available and running try { $null = docker ps 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { Write-Error "Docker Desktop is not running!" Write-Warning "Please start Docker Desktop and try again" Write-Info "You can skip this step with -SkipServices if services are already running" exit 1 } } catch { Write-Error "Cannot connect to Docker daemon!" Write-Warning "Please start Docker Desktop and try again" Write-Info "You can skip this step with -SkipServices if services are already running" exit 1 } # Start only postgres and redis services Write-Info "Starting PostgreSQL and Redis containers..." docker-compose up -d postgres redis if ($LASTEXITCODE -ne 0) { Write-Error "Failed to start services!" Write-Info "Make sure Docker Desktop is running" exit 1 } Write-Info "Waiting for PostgreSQL to be ready..." $maxAttempts = 30 $attempt = 0 $postgresReady = $false while ($attempt -lt $maxAttempts -and -not $postgresReady) { try { $null = docker exec audioforge-postgres pg_isready -U postgres 2>&1 if ($LASTEXITCODE -eq 0) { $postgresReady = $true Write-Success "PostgreSQL is ready!" } } catch { # Continue waiting } if (-not $postgresReady) { Start-Sleep -Seconds 1 $attempt++ Write-Host "." -NoNewline } } Write-Host "" if (-not $postgresReady) { Write-Error "PostgreSQL failed to start within timeout!" exit 1 } Write-Info "Waiting for Redis to be ready..." Start-Sleep -Seconds 2 try { $null = docker exec audioforge-redis redis-cli ping 2>&1 if ($LASTEXITCODE -eq 0) { Write-Success "Redis is ready!" } } catch { Write-Warning "Redis health check failed, but continuing..." } } else { Write-Info "Skipping service startup (assuming PostgreSQL/Redis are running)" } # Step 2: Setup Backend Environment Write-Info "Setting up backend environment..." Set-Location "$ProjectRoot\backend" # Check for Python 3.11 venv first (for ML support), then fall back to regular venv $venvPath = if (Test-Path ".venv311") { ".venv311" } elseif (Test-Path ".venv") { ".venv" } else { $null } if ($null -eq $venvPath) { Write-Warning "Virtual environment not found! Creating .venv..." python -m venv .venv $venvPath = ".venv" & "$venvPath\Scripts\Activate.ps1" pip install -e ".[dev]" } else { Write-Info "Using virtual environment: $venvPath" # Activate venv for subsequent commands & "$venvPath\Scripts\Activate.ps1" } # Step 3: Initialize Database Write-Info "Initializing database..." # Check if .env exists if (-not (Test-Path ".env")) { Write-Warning ".env file not found! Running setup_env.py..." Set-Location $ProjectRoot python scripts/setup_env.py Set-Location "$ProjectRoot\backend" } # Use venv's Python explicitly for database initialization & "$venvPath\Scripts\python.exe" scripts/init_db.py if ($LASTEXITCODE -ne 0) { Write-Error "Database initialization failed!" Write-Info "Make sure PostgreSQL is running and DATABASE_URL is correct in backend/.env" exit 1 } Write-Success "Database initialized successfully!" # Step 4: Start Backend Write-Info "Starting backend server..." # Start backend in new window $backendJob = Start-Process powershell -ArgumentList @( "-NoExit", "-Command", "cd '$ProjectRoot\backend'; `$venv = if (Test-Path .venv311) { '.venv311' } elseif (Test-Path .venv) { '.venv' } else { `$null }; if (`$venv) { & `"`$venv\Scripts\Activate.ps1`" }; uvicorn app.main:app --reload" ) -PassThru Write-Success "Backend starting in new window (PID: $($backendJob.Id))" Write-Info "Backend will be available at http://localhost:8000" # Step 5: Start Frontend Write-Info "Starting frontend server..." Set-Location "$ProjectRoot\frontend" # Check if node_modules exists if (-not (Test-Path "node_modules")) { Write-Warning "Frontend dependencies not installed! Installing..." pnpm install } # Ensure .env.local exists if (-not (Test-Path ".env.local")) { Write-Info "Creating frontend .env.local..." "NEXT_PUBLIC_API_URL=http://localhost:8000" | Out-File -FilePath ".env.local" -Encoding UTF8 } # Start frontend in new window $frontendJob = Start-Process powershell -ArgumentList @( "-NoExit", "-Command", "cd '$ProjectRoot\frontend'; pnpm dev" ) -PassThru Write-Success "Frontend starting in new window (PID: $($frontendJob.Id))" Write-Info "Frontend will be available at http://localhost:3000" # Wait a bit for services to start Write-Info "Waiting for services to initialize..." Start-Sleep -Seconds 5 # Final status Write-Host "" Write-Host "================================================================" -ForegroundColor Green Write-Host " " -ForegroundColor Green Write-Host " Development Environment Started! " -ForegroundColor Green Write-Host " " -ForegroundColor Green Write-Host "================================================================" -ForegroundColor Green Write-Host "" Write-Success "Backend: http://localhost:8000" Write-Success "Frontend: http://localhost:3000" Write-Success "API Docs: http://localhost:8000/docs" Write-Host "" Write-Info "Backend and Frontend are running in separate PowerShell windows" Write-Info "Close those windows to stop the servers" Write-Host "" Write-Info "To stop PostgreSQL/Redis: docker-compose down" Write-Host ""