version: '3.8'

services:
  # PostgreSQL Database
  postgres:
    image: postgres:15-alpine
    container_name: cloneweb-postgres
    environment:
      POSTGRES_DB: cloneweb
      POSTGRES_USER: cloneweb_user
      POSTGRES_PASSWORD: cloneweb_password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./services/database/init:/docker-entrypoint-initdb.d
    networks:
      - cloneweb-network

  # Redis for caching and job queues
  redis:
    image: redis:7-alpine
    container_name: cloneweb-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - cloneweb-network

  # MinIO for S3-compatible storage (development)
  minio:
    image: minio/minio:latest
    container_name: cloneweb-minio
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: cloneweb_access_key
      MINIO_ROOT_PASSWORD: cloneweb_secret_key
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio_data:/data
    networks:
      - cloneweb-network

  # API Gateway
  api-gateway:
    build:
      context: .
      dockerfile: services/api-gateway/Dockerfile
    container_name: cloneweb-api-gateway
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: development
      DATABASE_URL: postgresql://cloneweb_user:cloneweb_password@postgres:5432/cloneweb
      REDIS_URL: redis://redis:6379
      MINIO_ENDPOINT: minio:9000
      MINIO_ACCESS_KEY: cloneweb_access_key
      MINIO_SECRET_KEY: cloneweb_secret_key
    depends_on:
      - postgres
      - redis
      - minio
    networks:
      - cloneweb-network
    volumes:
      - ./services/api-gateway:/app
      - /app/node_modules
      - ./cloned-sites:/app/cloned-sites
      - /root/Desktop/Clonados:/root/Desktop/Clonados

  # Crawler Service
  crawler-service:
    build:
      context: .
      dockerfile: services/crawler/Dockerfile
    container_name: cloneweb-crawler
    environment:
      NODE_ENV: development
      DATABASE_URL: postgresql://cloneweb_user:cloneweb_password@postgres:5432/cloneweb
      REDIS_URL: redis://redis:6379
    depends_on:
      - postgres
      - redis
    networks:
      - cloneweb-network
    volumes:
      - ./services/crawler:/app
      - /app/node_modules
      - ./cloned-sites:/app/cloned-sites
      - /root/Desktop/Clonados:/root/Desktop/Clonados

volumes:
  postgres_data:
  redis_data:
  minio_data:

networks:
  cloneweb-network:
    driver: bridge