version: '3.8'

services:
  # PostgreSQL Database
  postgres:
    image: postgres:16
    container_name: aicouncil-db
    environment:
      POSTGRES_DB: aicouncil
      POSTGRES_USER: aicouncil
      POSTGRES_PASSWORD: ${DB_PASSWORD:-aicouncil123}
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./config/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
      - ./config/initial_data.sql:/docker-entrypoint-initdb.d/02-data.sql
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U aicouncil"]
      interval: 5s
      timeout: 5s
      retries: 5

  # FastAPI Backend
  api:
    build:
      context: ./api
      dockerfile: Dockerfile
    container_name: aicouncil-api
    environment:
      DATABASE_URL: postgresql://aicouncil:${DB_PASSWORD:-aicouncil123}@postgres:5432/aicouncil
      JWT_SECRET: ${JWT_SECRET:-change-me-in-production}
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  # React Frontend
  web:
    build:
      context: ./web
      dockerfile: Dockerfile
    container_name: aicouncil-web
    ports:
      - "3000:80"
    depends_on:
      - api
    restart: unless-stopped

volumes:
  pgdata:
