services:
  app:
    build: .
    restart: unless-stopped
    ports:
      - "5000:5000"
    volumes:
      - ./data:/app/data
      - ./duckdb:/app/duckdb:ro
    env_file: .env
    environment:
      - DATABASE_PATH=/app/data/app.db
      - SERVING_DUCKDB_PATH=/app/duckdb/analytics.duckdb
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  worker:
    build: .
    restart: unless-stopped
    command: python -m beanflows.worker
    volumes:
      - ./data:/app/data
    env_file: .env
    environment:
      - DATABASE_PATH=/app/data/app.db
    depends_on:
      - app

  scheduler:
    build: .
    restart: unless-stopped
    command: python -m beanflows.worker scheduler
    volumes:
      - ./data:/app/data
    env_file: .env
    environment:
      - DATABASE_PATH=/app/data/app.db
    depends_on:
      - app

  # Optional: Litestream for backups
  litestream:
    image: litestream/litestream:latest
    restart: unless-stopped
    command: replicate -config /etc/litestream.yml
    volumes:
      - ./data:/app/data
      - ./litestream.yml:/etc/litestream.yml:ro
    depends_on:
      - app

volumes:
