version: "3.9"

services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: altsignal
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: altsignal
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U altsignal"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - internal

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    networks:
      - internal

  api:
    build:
      context: ../
      dockerfile: apps/api/Dockerfile
    restart: unless-stopped
    environment:
      NODE_ENV: production
      PORT: 3000
      DATABASE_URL: postgresql://altsignal:${POSTGRES_PASSWORD}@postgres:5432/altsignal?schema=public
      REDIS_URL: redis://redis:6379
      JWT_SECRET: ${JWT_SECRET}
      TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}
      TELEGRAM_BOT_USERNAME: ${TELEGRAM_BOT_USERNAME}
      POLAR_ACCESS_TOKEN: ${POLAR_ACCESS_TOKEN}
      POLAR_WEBHOOK_SECRET: ${POLAR_WEBHOOK_SECRET}
      POLAR_PRO_PRODUCT_ID: ${POLAR_PRO_PRODUCT_ID}
      POLAR_PLUS_PRODUCT_ID: ${POLAR_PLUS_PRODUCT_ID}
      RESEND_API_KEY: ${RESEND_API_KEY}
      MAIL_FROM: ${MAIL_FROM:-AltSignal <noreply@signal.pulsaria.com>}
      WEB_BASE_URL: ${WEB_BASE_URL:-https://signal.pulsaria.com}
      WEB_ORIGIN: ${WEB_BASE_URL:-https://signal.pulsaria.com}
      HYPERLIQUID_WS_URL: wss://api.hyperliquid.xyz/ws
      HL_COINS: ${HL_COINS:-BTC,ETH,SOL,HYPE,WIF,DOGE,ARB}
      LIQ_THRESHOLD_USD: ${LIQ_THRESHOLD_USD:-100000}
      WHALE_THRESHOLD_USD: ${WHALE_THRESHOLD_USD:-250000}
      SMART_MONEY_MIN_USD: ${SMART_MONEY_MIN_USD:-50000}
      N8N_WAITLIST_WEBHOOK: ${N8N_WAITLIST_WEBHOOK:-}
      DISABLE_LISTENERS: ${DISABLE_LISTENERS:-false}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - internal
      - dokploy-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.altsignal-api.rule=Host(`${API_HOST:-signal.pulsaria.com}`) && (PathPrefix(`/v1`) || PathPrefix(`/docs`))"
      - "traefik.http.routers.altsignal-api.entrypoints=websecure"
      - "traefik.http.routers.altsignal-api.tls.certresolver=letsencrypt"
      - "traefik.http.services.altsignal-api.loadbalancer.server.port=3000"

  web:
    build:
      context: ../
      dockerfile: apps/web/Dockerfile
    restart: unless-stopped
    environment:
      NODE_ENV: production
      PORT: 3001
      HOSTNAME: 0.0.0.0
      NEXT_PUBLIC_API_URL: /api/proxy
      API_INTERNAL_URL: http://api:3000
    depends_on:
      - api
    networks:
      - internal
      - dokploy-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.altsignal-web.rule=Host(`${WEB_HOST:-signal.pulsaria.com}`)"
      - "traefik.http.routers.altsignal-web.entrypoints=websecure"
      - "traefik.http.routers.altsignal-web.tls.certresolver=letsencrypt"
      - "traefik.http.services.altsignal-web.loadbalancer.server.port=3001"

volumes:
  pgdata:
    driver: local

networks:
  internal:
    driver: bridge
  dokploy-network:
    external: true
