services:
  # ==========================================
  # 1. Laravel Application (PHP-FPM)
  # ==========================================
  app:
    build:
      context: .
      dockerfile: docker/Dockerfile
    restart: unless-stopped
    environment:
      APP_NAME: ${APP_NAME:-Laravel}
      APP_ENV: ${APP_ENV:-production}
      APP_KEY: ${APP_KEY}
      APP_DEBUG: ${APP_DEBUG:-false}
      APP_URL: ${APP_URL}

      DB_CONNECTION: mariadb
      DB_HOST: db
      DB_PORT: 3306

      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}

      FILESYSTEM_DISK: s3
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION:-us-east-1}
      AWS_BUCKET: ${AWS_BUCKET}
    depends_on:
      - db

  # ==========================================
  # 2. Web Server (Custom Nginx)
  # ==========================================
  web:
    build:
      context: .
      dockerfile: docker/nginx.Dockerfile
    restart: unless-stopped
    expose:
      - "80"
    depends_on:
      - app

  # ==========================================
  # 3. Database (MariaDB)
  # ==========================================
  db:
    build:
      context: .
      dockerfile: docker/mariadb.Dockerfile
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:
