version: '3.9'

services:
  postgres:
    image: postgres:16-alpine
    container_name: elo_postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-elo_dev}
      POSTGRES_USER: ${POSTGRES_USER:-elo}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-elo_dev_password}
    ports:
      - '5432:5432'
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-elo} -d ${POSTGRES_DB:-elo_dev}']
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: elo_redis
    restart: unless-stopped
    command: redis-server --requirepass ${REDIS_PASSWORD:-elo_redis_dev}
    ports:
      - '6379:6379'
    volumes:
      - redis_data:/data
    healthcheck:
      test: ['CMD', 'redis-cli', '--pass', '${REDIS_PASSWORD:-elo_redis_dev}', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5

  api:
    build:
      context: ./services/api
      dockerfile: Dockerfile
      target: development
    container_name: elo_api
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      NODE_ENV: development
      DATABASE_URL: postgresql://${POSTGRES_USER:-elo}:${POSTGRES_PASSWORD:-elo_dev_password}@postgres:5432/${POSTGRES_DB:-elo_dev}
      REDIS_URL: redis://:${REDIS_PASSWORD:-elo_redis_dev}@redis:6379
    env_file:
      - .env
    ports:
      - '3000:3000'
    volumes:
      - ./services/api:/app
      - /app/node_modules
    command: npm run start:dev

  admin_web:
    build:
      context: ./apps/admin_web
      dockerfile: Dockerfile
      target: development
    container_name: elo_admin
    restart: unless-stopped
    depends_on:
      - api
    environment:
      NEXT_PUBLIC_API_URL: http://localhost:3000
    ports:
      - '3001:3001'
    volumes:
      - ./apps/admin_web:/app
      - /app/node_modules
      - /app/.next

volumes:
  postgres_data:
  redis_data:
