# Docker Compose - Entorno de desarrollo local
# Levanta todos los servicios necesarios con un solo comando:
#   docker compose up -d

services:
  # ============================================================
  # PostgreSQL 16 - Base de datos principal
  # ============================================================
  postgres:
    image: pgvector/pgvector:pg16
    container_name: chatapp-postgres
    restart: unless-stopped
    ports:
      - "127.0.0.1:5432:5432"
    environment:
      POSTGRES_USER: chatapp
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-chatapp_dev_password_2024}
      POSTGRES_DB: chatapp
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./backend/libs/database/init:/docker-entrypoint-initdb.d
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U chatapp"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - chatapp-net
    security_opt:
      - no-new-privileges:true

  # ============================================================
  # Redis 7 - Cache + Pub/Sub + Job Queues
  # ============================================================
  redis:
    image: redis:7-alpine
    container_name: chatapp-redis
    restart: unless-stopped
    ports:
      - "127.0.0.1:6379:6379"
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - chatapp-net
    security_opt:
      - no-new-privileges:true

  # ============================================================
  # MinIO - Almacenamiento de archivos compatible S3
  # ============================================================
  minio:
    image: minio/minio:latest
    container_name: chatapp-minio
    restart: unless-stopped
    ports:
      - "127.0.0.1:9000:9000"
      - "127.0.0.1:9001:9001"
    environment:
      MINIO_ROOT_USER: chatapp
      MINIO_ROOT_PASSWORD: ${MINIO_PASSWORD:-chatapp_dev_password_2024}
    command: server /data --console-address ":9001"
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 10s
      timeout: 5s
      retries: 3
    networks:
      - chatapp-net
    security_opt:
      - no-new-privileges:true

  # ============================================================
  # Meilisearch - Busqueda full-text
  # ============================================================
  meilisearch:
    image: getmeili/meilisearch:v1.12
    container_name: chatapp-meilisearch
    restart: unless-stopped
    ports:
      - "127.0.0.1:7700:7700"
    environment:
      MEILI_MASTER_KEY: ${MEILI_MASTER_KEY:-chatapp_meili_dev_key_2024}
      MEILI_ENV: development
    volumes:
      - meili_data:/meili_data
    networks:
      - chatapp-net
    security_opt:
      - no-new-privileges:true

  # ============================================================
  # Mailhog - Testing de emails (SMTP catch)
  # ============================================================
  mailhog:
    image: mailhog/mailhog:latest
    container_name: chatapp-mailhog
    restart: unless-stopped
    ports:
      - "127.0.0.1:1025:1025"
      - "127.0.0.1:8025:8025"
    networks:
      - chatapp-net
    security_opt:
      - no-new-privileges:true

networks:
  chatapp-net:
    driver: bridge

volumes:
  postgres_data:
  redis_data:
  minio_data:
  meili_data: