version: '3.9'

# =============================================================================
# RecreaHUB — docker-compose
# Usage:
#   docker compose up -d          — start all services
#   docker compose logs -f api    — stream API logs
#   docker compose down           — stop and remove containers
# =============================================================================

networks:
  recreahub_net:
    driver: bridge

volumes:
  mysql_data:

services:

  # ── Node.js API ─────────────────────────────────────────────────────────────
  api:
    build:
      context: .
      dockerfile: Dockerfile
    image: recreahub-api:latest
    container_name: recreahub-api
    restart: unless-stopped
    ports:
      - '3000:3000'
    env_file:
      - .env
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s
    networks:
      - recreahub_net

  # ── MySQL 8 ─────────────────────────────────────────────────────────────────
  db:
    image: mysql:8
    container_name: recreahub-db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE:      ${DB_NAME}
      MYSQL_USER:          ${DB_USER}
      MYSQL_PASSWORD:      ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', '-p${DB_ROOT_PASSWORD}']
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    networks:
      - recreahub_net
