Development Scripts

This directory contains scripts to help manage your development environment for the Customer Portal project.

Quick Start

Single command to start everything:

pnpm start:all
# or
pnpm dev:start  
# or
./scripts/dev.sh

This will:

  1. Check if Docker is running
  2. 🔍 Check if services are already running (skips if already up)
  3. 🐳 Start PostgreSQL and Redis containers (if needed)
  4. Wait for databases to be ready
  5. 🗄️ Start Prisma Studio (available at http://localhost:5555)
  6. 🚀 Start both frontend and backend in development mode

Available Commands

# Start everything (Docker + Databases + Frontend + Backend)
pnpm start:all          # Enhanced Node.js script with pretty output
pnpm start:simple       # Simple version using basic commands

# Individual service management
pnpm start:services     # Start only Docker services (PostgreSQL + Redis)
pnpm stop:services      # Stop Docker services
pnpm restart:services   # Restart Docker services

# Complete environment management  
pnpm restart:all        # Stop everything and restart
pnpm dev:restart        # Same as above using bash script

# Monitoring and debugging
pnpm logs              # Show Docker service logs
pnpm status            # Show Docker service status
pnpm dev:logs          # Show logs using bash script
pnpm dev:status        # Show status using bash script

# Database management
pnpm db:migrate        # Run database migrations
pnpm db:studio         # Open Prisma Studio
pnpm db:reset          # Reset database (careful!)

Direct Script Usage

# Using the bash script directly
./scripts/dev.sh start    # Start everything
./scripts/dev.sh stop     # Stop everything  
./scripts/dev.sh restart  # Restart everything
./scripts/dev.sh logs     # Show logs
./scripts/dev.sh status   # Show status

# Using the Node.js script directly
node scripts/dev-start.js

What Gets Started

When you run pnpm start:all, the following services start:

  1. PostgreSQL Database (port 5432)

    • Container: portal-postgres
    • Database: portal
    • User: app / Password: app
  2. Redis Cache (port 6379)

    • Container: portal-redis
  3. Backend (BFF) (port 4000)

    • NestJS application with hot reload
    • API available at http://localhost:4000
  4. Frontend (port 3000)

    • Next.js application with Turbopack
    • App available at http://localhost:3000
  5. Prisma Studio (port 5555)

    • Database management interface
    • Available at http://localhost:5555

Stopping Everything

# Stop everything
pnpm stop:services

# Or use the bash script
./scripts/dev.sh stop

# Or use Ctrl+C to stop the development servers
# (Docker services will keep running)

Troubleshooting

Docker Issues

  • "Docker is not running": Start Docker Desktop or Docker daemon
  • Port conflicts: Check if ports 3000, 4000, 5432, or 6379 are in use

Database Issues

  • Connection refused: Wait a moment for PostgreSQL to fully start
  • Migration errors: Run pnpm db:reset to reset the database

Development Server Issues

  • Port 3000/4000 in use: Kill existing processes or change ports
  • Module not found: Run pnpm install to install dependencies

General Issues

  • Run pnpm dev:status to check service health
  • Run pnpm dev:logs to see service logs
  • Try pnpm dev:restart for a fresh start

Features

  • 🚀 One command startup: Everything starts with a single command
  • 🔍 Smart detection: Checks if services are already running to avoid conflicts
  • Smart waiting: Scripts wait for databases to be ready before starting apps
  • 📋 Clear service URLs: Shows all running service URLs for easy access
  • 🎨 Pretty output: Colored, organized logging with emojis
  • 🔄 Easy restart: Quick restart commands for development iteration
  • 🐳 Docker health checks: Ensures services are actually ready, not just started
  • 💻 Cross-platform: Works on Linux, macOS, and Windows (WSL)

Tips

  • Use pnpm start:all for daily development
  • Use pnpm dev:restart when you need a fresh environment
  • Use pnpm dev:logs to debug service issues
  • Keep Docker running to avoid startup delays
  • The scripts automatically handle graceful shutdowns with Ctrl+C