param ( [int]$Port = 0 ) $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $gatewayDir = Join-Path (Split-Path -Parent $scriptDir) "gateway" if ($Port -le 0) { $envPort = $env:PORT -as [int] if ($envPort) { $Port = $envPort } else { $Port = 8765 } } Write-Host "Starting FastAPI Gateway local dev server on port $Port..." -ForegroundColor Cyan Push-Location $gatewayDir try { # Check if virtual environment exists, if not, bootstrap it if (-not (Test-Path ".venv")) { Write-Host "Python virtual environment not found. Bootstrapping gateway environment..." -ForegroundColor Yellow # Verify Python is installed if (-not (Get-Command python -ErrorAction SilentlyContinue)) { Write-Error "Python was not found on your PATH. Please install Python 3.11+ and try again." return } Write-Host "Creating virtual environment in $gatewayDir\.venv..." -ForegroundColor Yellow & python -m venv .venv if ($LASTEXITCODE -ne 0 -or -not (Test-Path ".venv")) { Write-Error "Failed to create Python virtual environment." return } Write-Host "Installing gateway dependencies (pip install -e '.[dev]')..." -ForegroundColor Yellow & .venv\Scripts\pip install -e ".[dev]" if ($LASTEXITCODE -ne 0) { Write-Error "Failed to install gateway dependencies." return } Write-Host "Bootstrap complete!" -ForegroundColor Green } & .venv\Scripts\uvicorn app.main:app --reload --port $Port } finally { Pop-Location }