services:
  # Backend Laravel Service
  backend:
    build:
      context: ./laravel/laravel
      dockerfile: Dockerfile
      args:
        user: www-data
        uid: 1000
    container_name: swapdex-backend
    restart: unless-stopped
    working_dir: /var/www/html
    dns:
      - 8.8.8.8
      - 1.1.1.1
    volumes:
      - ./laravel/laravel:/var/www/html
    networks:
      - swapdex-network
    depends_on:
      - mysql
      - redis

  # Frontend React Service
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: swapdex-frontend
    restart: unless-stopped
    ports:
      - "3001:3000"
    volumes:
      - ./frontend:/app
      - /app/node_modules
    networks:
      - swapdex-network

  # Nginx Service
  nginx:
    image: nginx:alpine
    container_name: swapdex-nginx
    restart: unless-stopped
    ports:
      - "8081:80"
    volumes:
      - ./laravel/laravel:/var/www/html
      - ./laravel/laravel/docker/nginx:/etc/nginx/conf.d/
    networks:
      - swapdex-network
    depends_on:
      - backend
      - frontend

  # MySQL Service
  mysql:
    image: mariadb:latest
    container_name: swapdex-mysql
    restart: unless-stopped
    tty: true
    command:
      - "--skip-log-bin"
    expose:
      - 3306
    environment:
      MYSQL_ROOT_HOST: "%"
      MYSQL_DATABASE: swapdex
      MYSQL_USER: swapdex
      MYSQL_PASSWORD: swapdex123
      MYSQL_ROOT_PASSWORD: root
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    volumes:
      - ./laravel/laravel/docker/mysql:/docker-entrypoint-initdb.d
      - mysql-data:/var/lib/mysql
    networks:
      - swapdex-network

  # Redis Service
  redis:
    image: redis:alpine
    container_name: swapdex-redis
    restart: unless-stopped
    ports:
      - "6389:6379"
    volumes:
      - redis-data:/data
    networks:
      - swapdex-network

  # phpMyAdmin Service
  phpmyadmin:
    image: phpmyadmin:latest
    container_name: swapdex-phpmyadmin
    restart: unless-stopped
    ports:
      - "8082:80"
    environment:
      PMA_HOST: mysql
      MYSQL_ROOT_PASSWORD: "root"
      UPLOAD_LIMIT: 3000M
      MAX_EXECUTION_TIME: 6000
    links:
      - "mysql:db"
    networks:
      - swapdex-network
    depends_on:
      - mysql

networks:
  swapdex-network:
    driver: bridge

volumes:
  mysql-data:
    driver: local
  redis-data:
    driver: local 
