services:
  postgres:
    image: postgres:16-alpine
    container_name: lector-postgres
    restart: unless-stopped
    user: "70:70"
    environment:
      POSTGRES_DB: lector
      POSTGRES_USER: lector
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - lector_pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U lector -d lector"]
      interval: 5s
      timeout: 5s
      retries: 10

  morpheus-api:
    build: ./morpheus-api
    image: morpheus-api:latest
    container_name: morpheus-api
    restart: unless-stopped

  lector:
    build: .
    image: lector-app:latest
    container_name: lector-app
    restart: unless-stopped
    ports:
      - "5001:5000"
    volumes:
      - lector_data:/app/data
    environment:
      - NODE_ENV=production
      - PORT=5000
      - MORPHOLOGY_DB_PATH=/app/data/morphology.db
      - MORPHEUS_API_URL=http://morpheus-api:5100
      - AUTH_ENABLED=true
      - SESSION_SECRET=1aeb65479e241a751af302bfa25dfa517101c73e7d6c9ffa367a803cb9d8ffb6
      - DATABASE_URL=postgresql://lector:${POSTGRES_PASSWORD}@postgres:5432/lector
      - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
      - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
      - APP_URL=https://classicslens.com
      - GOOGLE_REDIRECT_URI=https://classicslens.com/api/auth/google/callback
      - RESEND_API_KEY=${RESEND_API_KEY}
      - STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
      - STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}
      - STRIPE_WEBHOOK_SECRET=${STRIPE_WEBHOOK_SECRET}
      - STRIPE_PRO_PRICE_ID=${STRIPE_PRO_PRICE_ID}
      - STRIPE_INSTRUCTOR_PRICE_ID=${STRIPE_INSTRUCTOR_PRICE_ID}
      - STRIPE_ACADEMIC_PRICE_ID=${STRIPE_ACADEMIC_PRICE_ID}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - CRISP_WEBSITE_ID=${CRISP_WEBSITE_ID}
    depends_on:
      morpheus-api:
        condition: service_started
      postgres:
        condition: service_healthy

volumes:
  lector_data:
    name: lector_data
  lector_pg_data:
    name: lector_pg_data
