version: '3.8'

services:
  # ─── MySQL Database ───────────────────────────────────
  db:
    image: mysql:8.0
    container_name: eventify_db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-eventify_secret}
      MYSQL_DATABASE: ${DB_NAME:-eventify_db}
      MYSQL_USER: ${DB_USER:-eventify}
      MYSQL_PASSWORD: ${DB_PASSWORD:-eventify_secret}
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./backend/src/database/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - eventify_net
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ─── Backend API ─────────────────────────────────────
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: eventify_api
    restart: unless-stopped
    env_file: ./backend/.env
    environment:
      DB_HOST: db
      NODE_ENV: production
    ports:
      - "5000:5000"
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - ./backend/uploads:/app/uploads
      - ./backend/tickets:/app/tickets
    networks:
      - eventify_net

  # ─── Frontend ─────────────────────────────────────────
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: eventify_web
    restart: unless-stopped
    ports:
      - "3000:80"
    depends_on:
      - backend
    networks:
      - eventify_net

  # ─── Nginx Reverse Proxy ─────────────────────────────
  nginx:
    image: nginx:alpine
    container_name: eventify_nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/ssl:/etc/nginx/ssl:ro
    depends_on:
      - backend
      - frontend
    networks:
      - eventify_net

volumes:
  mysql_data:

networks:
  eventify_net:
    driver: bridge
