services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: timechat
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: timechat
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - internal

  api:
    build:
      context: ../
      dockerfile: apps/api/Dockerfile
    environment:
      DATABASE_URL: postgresql://timechat:${POSTGRES_PASSWORD}@postgres:5432/timechat
      TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}
      OPENAI_API_KEY: ${OPENAI_API_KEY}
      POLAR_ACCESS_TOKEN: ${POLAR_ACCESS_TOKEN}
      SMTP_URL: ${SMTP_URL}
      JWT_SECRET: ${JWT_SECRET}
    depends_on:
      - postgres
    networks:
      - internal
      - dokploy-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.timechat-api.rule=Host(`timechat.eventium.com`) && PathPrefix(`/api`)"
      - "traefik.http.routers.timechat-api.entrypoints=websecure"
      - "traefik.http.routers.timechat-api.tls.certresolver=letsencrypt"
      - "traefik.http.services.timechat-api.loadbalancer.server.port=3000"

  web:
    build:
      context: ../
      dockerfile: apps/web/Dockerfile
    environment:
      NEXT_PUBLIC_API_URL: https://timechat.eventium.com/api
    networks:
      - dokploy-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.timechat-web.rule=Host(`timechat.eventium.com`)"
      - "traefik.http.routers.timechat-web.entrypoints=websecure"
      - "traefik.http.routers.timechat-web.tls.certresolver=letsencrypt"
      - "traefik.http.services.timechat-web.loadbalancer.server.port=3003"

volumes:
  pgdata:

networks:
  internal:
  dokploy-network:
    external: true
