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

  platform-redis:
    image: redis:7-alpine
    restart: unless-stopped
    volumes:
      - platform-redis-data:/data
    command: redis-server --appendonly yes

  platform-minio:
    image: minio/minio:latest
    restart: unless-stopped
    volumes:
      - platform-storage:/data
    environment:
      MINIO_ROOT_USER: ${MINIO_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_PASSWORD}
    command: server /data --console-address ":9001"
    ports:
      - "9001:9001"
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 10s
      timeout: 5s
      retries: 5

  platform-backend:
    build: ./backend
    restart: unless-stopped
    ports:
      - "3201:3201"
    depends_on:
      platform-db:
        condition: service_healthy
      platform-redis:
        condition: service_started
      platform-minio:
        condition: service_started
    environment:
      PORT: 3201
      DATABASE_URL: postgresql://platform:${DB_PASSWORD}@platform-db:5432/platform
      REDIS_URL: redis://platform-redis:6379
      MINIO_ENDPOINT: platform-minio
      MINIO_PORT: "9000"
      MINIO_ACCESS_KEY: ${MINIO_USER}
      MINIO_SECRET_KEY: ${MINIO_PASSWORD}
      MINIO_BUCKET: platform
      MINIO_USE_SSL: "false"
      JWT_SECRET: ${JWT_SECRET}
      JWT_EXPIRES_IN: 7d
      TOSS_CLIENT_KEY: ${TOSS_CLIENT_KEY:-test_ck_placeholder}
      TOSS_SECRET_KEY: ${TOSS_SECRET_KEY:-test_sk_placeholder}
      BASE_URL: ${BASE_URL:-http://localhost:3200}
      WEBFLASH_INTERNAL_TOKEN: ${WEBFLASH_INTERNAL_TOKEN}
      NODE_ENV: production

  platform-frontend:
    build: ./frontend
    restart: unless-stopped
    ports:
      - "3200:80"
    depends_on:
      - platform-backend

volumes:
  platform-db-data:
  platform-redis-data:
  platform-storage:
