version: '3.8'

services:
  # PHP Application
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: dewan_traders_app
    restart: unless-stopped
    working_dir: /var/www/html
    ports:
      - "5173:5173"
    volumes:
      - .:/var/www/html
      - ./docker/php/php.ini:/usr/local/etc/php/php.ini
    environment:
      - PHP_OPCACHE_ENABLE=1
    networks:
      - dewan_traders
    depends_on:
      - mysql

  # Nginx Web Server
  nginx:
    image: nginx:1.25-alpine
    container_name: dewan_traders_nginx
    restart: unless-stopped
    ports:
      - "8084:80"
      - "8083:443"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - ./docker/nginx/ssl:/etc/nginx/ssl
    networks:
      - dewan_traders
    depends_on:
      - app

  # MySQL Database
  mysql:
    image: mysql:8.0
    container_name: dewan_traders_mysql
    restart: unless-stopped
    ports:
      - "3307:3306"
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-secret}
    volumes:
      - mysql_data:/var/lib/mysql
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    networks:
      - dewan_traders

  # phpMyAdmin (Development UI for MySQL)
  phpmyadmin:
    image: phpmyadmin:latest
    container_name: dewan_traders_phpmyadmin
    restart: unless-stopped
    ports:
      - "8080:80"
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
    networks:
      - dewan_traders
    profiles:
      - dev

networks:
  dewan_traders:
    driver: bridge

volumes:
  mysql_data: