services:
  postgres:
    image: postgres:13
    container_name: apoj_postgres_dev
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - '${POSTGRES_PORT:-5432}:5432'
    volumes:
      - postgres_data:/var/lib/postgresql/data
  redis:
    image: redis:7
    ports:
      - '${REDIS_PORT}:6379'
  minio:
    image: minio/minio
    container_name: apoj_minio_dev
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
    command: server /data --console-address ":${MINIO_CONSOLE_PORT}"
    ports:
      - '${MINIO_PORT}:9000'
      - '${MINIO_CONSOLE_PORT}:${MINIO_CONSOLE_PORT}'
    volumes:
      - minio_data:/data
  backend:
    build:
      context: .
      dockerfile: docker/backend/Dockerfile
    container_name: apoj_backend_dev
    working_dir: /workspace/packages/backend
    environment:
      - DATABASE_URL=${DATABASE_URL}
      - REDIS_URL=${REDIS_URL}
      - MINIO_ENDPOINT=${MINIO_ENDPOINT}
      - MINIO_PORT=${MINIO_PORT}
      - MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}
      - MINIO_SECRET_KEY=${MINIO_SECRET_KEY}
      - MINIO_PUBLIC_HOST=${MINIO_PUBLIC_HOST}
      - MINIO_PUBLIC_PORT=${MINIO_PUBLIC_PORT}
      - MINIO_PUBLIC_PROTOCOL=${MINIO_PUBLIC_PROTOCOL}
      - NODE_ENV=${NODE_ENV}
      - PORT=${BACKEND_PORT}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - OPENAI_MODEL=${OPENAI_MODEL}
      - OPENAI_TIMEOUT=${OPENAI_TIMEOUT}
      - LOG_LEVEL=${LOG_LEVEL}
      - PNPM_HOME=/pnpm
      - CI=true
    volumes:
      - ./:/workspace
      - pnpm-store:/pnpm
    command: sh -c "corepack enable && pnpm install --filter backend --ignore-scripts --no-frozen-lockfile && pnpm --filter backend run dev"
    ports:
      - '${BACKEND_PORT}:${BACKEND_PORT}'
      - '${DEBUG_PORT}:9229'
    depends_on:
      - postgres
      - redis
      - minio
  frontend:
    image: node:20-alpine
    container_name: apoj_frontend_dev
    working_dir: /workspace/packages/frontend
    environment:
      - CI=true
      - PNPM_HOME=/pnpm
    volumes:
      - ./:/workspace
      - pnpm-store:/pnpm
    command: sh -c "corepack enable && pnpm install --filter frontend --ignore-scripts --no-frozen-lockfile && pnpm --filter frontend run dev --host 0.0.0.0"
    ports:
      - '${FRONTEND_PORT}:5173'
    depends_on:
      - backend
volumes:
  postgres_data:
  minio_data:
  pnpm-store:
