version: '3.8'

services:
  # FastAPI Application
  api:
    build: .
    container_name: transporter-api
    ports:
      - "8000:8000"
    env_file:
      - .env
    depends_on:
      - mysql
      - redis
    volumes:
      - ./uploads:/app/uploads
    networks:
      - transporter-network
    restart: unless-stopped

  # MySQL Database
  mysql:
    image: mysql:8.0
    container_name: transporter-mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-transporter}
      MYSQL_USER: ${MYSQL_USER:-transporter}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-transporterpassword}
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    networks:
      - transporter-network
    restart: unless-stopped

  # phpMyAdmin (http://localhost:${PHPMYADMIN_PORT:-8080})
  # With Docker MySQL: default PMA_HOST=mysql — run: docker compose up -d mysql phpmyadmin
  # With MySQL on your Mac: set PMA_HOST=host.docker.internal in .env, then: docker compose up -d phpmyadmin
  phpmyadmin:
    image: phpmyadmin:5
    container_name: transporter-phpmyadmin
    environment:
      PMA_HOST: ${PMA_HOST:-mysql}
      PMA_PORT: ${PMA_PORT:-3306}
      UPLOAD_LIMIT: 64M
    ports:
      - "${PHPMYADMIN_PORT:-8080}:80"
    networks:
      - transporter-network
    restart: unless-stopped

  # Redis for Caching and Sessions
  redis:
    image: redis:7-alpine
    container_name: transporter-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes
    networks:
      - transporter-network
    restart: unless-stopped

  # Celery Worker (for background tasks)
  celery-worker:
    build: .
    container_name: transporter-celery-worker
    command: celery -A app.tasks.celery_app worker --loglevel=info
    env_file:
      - .env
    depends_on:
      - mysql
      - redis
    networks:
      - transporter-network
    restart: unless-stopped

  # Celery Beat (for scheduled tasks)
  celery-beat:
    build: .
    container_name: transporter-celery-beat
    command: celery -A app.tasks.celery_app beat --loglevel=info
    env_file:
      - .env
    depends_on:
      - mysql
      - redis
    networks:
      - transporter-network
    restart: unless-stopped

volumes:
  mysql_data:
  redis_data:

networks:
  transporter-network:
    driver: bridge
