Skip to main content

Full Environment Setup Guide

Complete guide for setting up and running the Payroll Pipeline SaaS application locally on Windows.

Prerequisites

Required Software

  1. Node.js + npm
  2. Python
  3. Google Cloud SDK (gcloud)

Service Account Credentials

  • Option 1: Place credentials.json in the project root directory
  • Option 2: Use Application Default Credentials (ADC)
    • Run: gcloud auth application-default login
    • Credentials will be stored in your user profile

One-Time Setup

1. Place Credentials File (if using service account JSON)

Place your Google Cloud service account JSON file in the project root:
payroll-pipeline-cbs/
  credentials.json  <-- Place your service account JSON here
  ...
Note: The credentials.json file is typically gitignored for security. If you don’t have one, the backend will attempt to use Application Default Credentials.

2. Environment Variables

The scripts will automatically set required environment variables, but you can override them:
  • GCP_PROJECT_ID: Defaults to payroll-bi-gauntlet if not set
  • GOOGLE_APPLICATION_CREDENTIALS: Set automatically if credentials.json exists in project root
  • GCP_REGION: Defaults to us-central1 (for Vertex AI)
  • VERTEX_MODEL: Optional (code handles defaults)
To set custom values, create a .env file in the project root or set them in your PowerShell session before running scripts.

Commands

Bootstrap Virtual Environment

First-time setup - Creates Python virtual environment and installs dependencies:
powershell -ExecutionPolicy Bypass -File .\scripts\bootstrap-venv.ps1
What it does:
  • Creates ./venv directory if it doesn’t exist
  • Activates virtual environment
  • Upgrades pip
  • Installs dependencies from requirements-api.txt
  • Validates imports (fastapi, uvicorn, google.cloud.bigquery, vertexai)
Expected output:
[BOOTSTRAP] Virtual environment created successfully
[BOOTSTRAP] Dependencies installed successfully
[BOOTSTRAP] ✓ fastapi imported successfully
[BOOTSTRAP] ✓ uvicorn imported successfully
[BOOTSTRAP] ✓ google.cloud.bigquery imported successfully
[BOOTSTRAP] Venv bootstrap complete and dependencies validated.

Start Backend

Option 1: Using .bat file (recommended)
.\start-backend.bat
Option 2: Using PowerShell directly
powershell -ExecutionPolicy Bypass -File .\scripts\start-backend.ps1
What it does:
  • Checks for virtual environment (prompts to bootstrap if missing)
  • Activates virtual environment
  • Sets environment variables:
    • BACKEND_ENV=local
    • GCP_PROJECT_ID=payroll-bi-gauntlet (if not set)
    • GOOGLE_APPLICATION_CREDENTIALS (if credentials.json exists)
    • GCP_REGION=us-central1 (if not set)
  • Starts FastAPI/uvicorn server on http://localhost:8000
Expected output:
[BACKEND] Starting backend server...
[BACKEND] Environment Summary:
  PROJECT: payroll-bi-gauntlet
  CREDS: C:\Projects\payroll-pipeline-cbs\credentials.json
  REGION: us-central1
[BACKEND] Starting uvicorn server...
INFO:     Uvicorn running on http://0.0.0.0:8000
Access points:

Start Frontend

Option 1: Using .bat file (recommended)
.\start-frontend.bat
Option 2: Using PowerShell directly
powershell -ExecutionPolicy Bypass -File .\scripts\start-frontend.ps1
What it does:
  • Changes to ./dashboard directory
  • Runs npm install if node_modules doesn’t exist
  • Starts Next.js dev server on http://localhost:3000
Expected output:
[FRONTEND] Starting Next.js dev server...
  ▲ Next.js 14.2.33
  - Local:        http://localhost:3000
Access points:

Start Full Stack (Both Services)

Option 1: Using .bat file (recommended)
.\start-full-stack.bat
Option 2: Using PowerShell directly
powershell -ExecutionPolicy Bypass -File .\scripts\run-full-stack.ps1
What it does:
  • Bootstraps venv if missing
  • Starts backend in a new PowerShell window
  • Starts frontend in another new PowerShell window
  • Polls health endpoints to verify services are running
  • Prints status summary
Expected output:
[FULL-STACK] Starting full-stack application...
[FULL-STACK] ✅ Backend is running on http://localhost:8000
[FULL-STACK] ✅ Frontend is running on http://localhost:3000
Note: Each service runs in its own window. Close the windows or press Ctrl+C in each to stop.

Run Diagnostics

Generate a diagnostic report of your environment:
powershell -ExecutionPolicy Bypass -File .\scripts\diagnose-backend.ps1
What it does:
  • Checks Python and Node versions
  • Verifies virtual environment
  • Lists environment variables
  • Validates credentials file
  • Tests Python package imports
  • Checks backend health endpoint
  • Writes report to ./diagnostics/diagnostic-report.md
Use when:
  • Troubleshooting setup issues
  • Verifying environment configuration
  • Before reporting bugs

Test Users

After starting the backend, you can use these test credentials:
EmailPasswordRole
aaronbundy681@gmail.comadmin123CEO/Admin
aaronbundy@test.comadmin123Admin
test@example.comadmin123Agent
Note: If users don’t exist, seed them:
python scripts/seed_user.py

Troubleshooting

Backend Not Starting

Error: venv not found
  • Solution: Run .\scripts\bootstrap-venv.ps1 first
Error: ModuleNotFoundError: No module named 'fastapi'
  • Solution:
    1. Activate venv: .\venv\Scripts\activate.ps1
    2. Install dependencies: pip install -r requirements-api.txt
Error: BigQuery client not available
  • Solution:
    1. Verify GCP_PROJECT_ID is set (defaults to payroll-bi-gauntlet)
    2. Ensure credentials.json exists OR run gcloud auth application-default login
    3. Check that service account has BigQuery permissions
Error: Port 8000 already in use
  • Solution:
    # Find process using port 8000
    netstat -ano | findstr :8000
    # Kill process (replace PID)
    taskkill /PID <PID> /F
    
Error: Failed to activate virtual environment
  • Solution:
    1. Check PowerShell execution policy: Get-ExecutionPolicy
    2. If Restricted, run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    3. Or use the .bat files which bypass execution policy

Frontend Not Starting

Error: npm: command not found
  • Solution:
    1. Verify Node.js is installed: node -v
    2. Restart terminal after installing Node.js
    3. Verify npm is in PATH: npm -v
Error: Port 3000 already in use
  • Solution:
    # Find process using port 3000
    netstat -ano | findstr :3000
    # Kill process
    taskkill /PID <PID> /F
    
Error: npm install fails
  • Solution:
    1. Clear npm cache: npm cache clean --force
    2. Delete node_modules and package-lock.json
    3. Run npm install again
Error: Build errors or TypeScript errors
  • Solution:
    1. Check Node.js version (should be 18.x or later)
    2. Run npm run build to see detailed errors
    3. Check dashboard/tsconfig.json configuration

Vertex AI / BigQuery Permission Issues

Error: 403 Forbidden or Permission denied
  • Solution:
    1. Verify service account has required permissions:
      • BigQuery Data Viewer
      • BigQuery Job User
      • Vertex AI User (if using AI features)
    2. Check that GCP_PROJECT_ID matches your project
    3. Verify credentials file is valid JSON
Error: Vertex AI initialization failed
  • Solution:
    1. Check GCP_REGION is set (defaults to us-central1)
    2. Verify project has Vertex AI API enabled
    3. Check service account has Vertex AI permissions
Error: Project not found
  • Solution:
    1. Verify GCP_PROJECT_ID=payroll-bi-gauntlet (or your actual project ID)
    2. Check that project exists in GCP Console
    3. Verify you have access to the project

Environment Variable Issues

Issue: Backend uses wrong project ID
  • Solution: Set GCP_PROJECT_ID before starting:
    $env:GCP_PROJECT_ID = "your-project-id"
    .\start-backend.bat
    
Issue: Credentials not found
  • Solution:
    1. Place credentials.json in project root, OR
    2. Run gcloud auth application-default login

Quick Reference

TaskCommand
Bootstrap venv.\scripts\bootstrap-venv.ps1
Start backend.\start-backend.bat
Start frontend.\start-frontend.bat
Start both.\start-full-stack.bat
Run diagnostics.\scripts\diagnose-backend.ps1
Seed test userspython scripts/seed_user.py

File Structure

payroll-pipeline-cbs/
├── scripts/
│   ├── bootstrap-venv.ps1      # Create and setup venv
│   ├── start-backend.ps1        # Start backend server
│   ├── start-frontend.ps1       # Start frontend server
│   ├── run-full-stack.ps1       # Start both services
│   └── diagnose-backend.ps1     # Run diagnostics
├── start-backend.bat            # Backend launcher
├── start-frontend.bat           # Frontend launcher
├── start-full-stack.bat         # Full-stack launcher
├── credentials.json             # GCP service account (gitignored)
├── requirements-api.txt          # Python dependencies
├── venv/                        # Python virtual environment
├── api/                         # FastAPI backend
└── dashboard/                   # Next.js frontend

Additional Resources

  • API Documentation: http://localhost:8000/docs (when backend is running)
  • Makefile Commands: See Makefile for additional development commands
  • Local Development Guide: See LOCAL_DEVELOPMENT_GUIDE.md

Last Updated: 2025-12-21