# Control Center - Go + React + PostgreSQL Deployment
# ============================================================

services:
  # ── Backend Service (Go) ───────────────────────────────────────────────
  backend:
    build:
      context: ./go-backend
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      - DATABASE_URL=postgresql://controlcenter:controlcenter@db:5432/controlcenter?sslmode=disable
      - CORS_ORIGIN=http://localhost:3000
      - LOG_LEVEL=info
      - ENVIRONMENT=production
      - PORT=8080
      - GATEWAY_URL=http://host.docker.internal:18789/api/agents
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    networks:
      - control-center-network
    restart: unless-stopped

  # ── Frontend Service (React) ───────────────────────────────────────────
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "3000:80"
    depends_on:
      - backend
    environment:
      - VITE_API_URL=http://localhost:8080
    networks:
      - control-center-network
    restart: unless-stopped

  # ── Database Service (PostgreSQL 16) ───────────────────────────────────
  db:
    image: postgres:16-alpine
    container_name: control-center-db
    environment:
      - POSTGRES_USER=controlcenter
      - POSTGRES_PASSWORD=controlcenter
      - POSTGRES_DB=controlcenter
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U controlcenter -d controlcenter"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    networks:
      - control-center-network
    restart: unless-stopped

networks:
  control-center-network:
    driver: bridge

volumes:
  postgres-data:
