version: '3.9'

services:
  app:
    build:
      context: ..
      dockerfile: docker/Dockerfile
    container_name: zufiti_app
    restart: unless-stopped
    env_file: ../.env
    ports:
      - "3000:3000"
    volumes:
      - uploads_data:/app/uploads
      - logs_data:/app/logs
    depends_on:
      db:
        condition: service_healthy
    networks:
      - zufiti_net
    deploy:
      resources:
        limits:
          memory: 512M

  db:
    image: mariadb:11.2
    container_name: zufiti_db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-rootpassword}
      MYSQL_DATABASE: ${DB_NAME:-zufiti}
      MYSQL_USER: ${DB_USER:-zufiti_user}
      MYSQL_PASSWORD: ${DB_PASSWORD:-your_strong_password}
    volumes:
      - db_data:/var/lib/mysql
      - ../database/migrations:/docker-entrypoint-initdb.d:ro
    ports:
      - "3306:3306"
    networks:
      - zufiti_net
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

  nginx:
    image: nginx:1.25-alpine
    container_name: zufiti_nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ../docker/nginx.conf:/etc/nginx/nginx.conf:ro
      - ../frontend:/var/www/html:ro
      - nginx_logs:/var/log/nginx
    depends_on:
      - app
    networks:
      - zufiti_net

volumes:
  db_data:
  uploads_data:
  logs_data:
  nginx_logs:

networks:
  zufiti_net:
    driver: bridge
