#version: "3.8"

services:
  backend:
    build:
      context: .
      dockerfile: docker/backend/Dockerfile
    container_name: suivi_produit_backend
    restart: unless-stopped
    ports:
      - "${API_PORT:-8008}:8008"
    environment:
      - APP_ENV=${APP_ENV:-production}
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
      - DATABASE_URL=sqlite:///backend/data/suivi.db
    volumes:
      # Persistance données SQLite + raw JSON (bind mount host)
      - ./backend/data:/app/backend/data
      # Persistance logs
      - backend_logs:/app/backend/logs
      # Config backend (lecture/écriture pour sauvegarde depuis l'UI)
      - ./backend/config_backend.json:/app/backend/config_backend.json
      # Config frontend pour l'API
      - ./frontend/public/config_frontend.json:/app/backend/config_frontend.json
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8008/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    networks:
      - suivi_network

  frontend:
    build:
      context: .
      dockerfile: docker/frontend/Dockerfile
      args:
        - VITE_API_URL=/api
    container_name: suivi_produit_frontend
    restart: unless-stopped
    ports:
      - "${FRONTEND_PORT:-8080}:80"
    depends_on:
      backend:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost/health"]
      interval: 30s
      timeout: 5s
      retries: 3
    networks:
      - suivi_network

volumes:
  backend_data:
    name: suivi_produit_data
  backend_logs:
    name: suivi_produit_logs

networks:
  suivi_network:
    name: suivi_produit_network
    driver: bridge
