services:
  # Spring Boot Backend
  backend:
    build: ./backend
    ports:
      - "8080:8080"
    environment:
      - SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/gallery # Example DB connection
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=password
      - SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT=org.hibernate.dialect.MySQLDialect
    volumes:
      - ./backend/uploads:/app/uploads
    depends_on:
      db:
        condition: service_healthy
    networks:
      - app-network

  # React Frontend
  frontend:
    build: ./frontend
    ports:
      - "3000:80" # Map host port 3000 to container port 80 (nginx)
    depends_on:
      - backend
    networks:
      - app-network

  # Database (Example: MySQL)
  db:
    image: mysql:8.0
    command: --default-authentication-plugin=mysql_native_password --lower_case_table_names=1
    volumes:
      - db_data:/var/lib/mysql
      - ./backend/sql:/docker-entrypoint-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: gallery
    ports:
      - "3307:3306"
    networks:
      - app-network
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      timeout: 20s
      retries: 10

volumes:
  db_data:

networks:
  app-network:
    driver: bridge