version: '3.9'

services:
  # Redis (opsiyonel — MVP'de gerekli değil, ileride cache/queue için)
  # Gerekirse `docker compose --profile cache up` ile başlatılır
  redis:
    image: redis:7-alpine
    container_name: kres_redis
    profiles: ['cache']
    ports:
      - '6379:6379'
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5

  api:
    build:
      context: ..
      dockerfile: apps/api/Dockerfile
      target: development
    container_name: kres_api
    ports:
      - '3001:3001'
    volumes:
      - ../apps/api:/app/apps/api
      - ../packages:/app/packages
      - /app/node_modules
    environment:
      NODE_ENV: development
      PORT: 3001
      DATABASE_URL: ${DATABASE_URL}
      DIRECT_URL: ${DIRECT_URL}
      SUPABASE_URL: ${SUPABASE_URL}
      SUPABASE_ANON_KEY: ${SUPABASE_ANON_KEY}
      SUPABASE_SERVICE_ROLE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
      JWT_SECRET: ${JWT_SECRET}
      JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET}
      CORS_ORIGINS: http://localhost:3000
    restart: unless-stopped

  web:
    build:
      context: ..
      dockerfile: apps/web/Dockerfile
      target: development
    container_name: kres_web
    ports:
      - '3000:3000'
    volumes:
      - ../apps/web:/app/apps/web
      - ../packages:/app/packages
      - /app/node_modules
      - /app/apps/web/.next
    environment:
      NEXT_PUBLIC_API_URL: http://localhost:3001/api/v1
    depends_on:
      - api
    restart: unless-stopped

volumes:
  redis_data:
