services:
  postgres:
    image: postgres:15.6
    container_name: ${APP_NAME}_db
    restart: unless-stopped
    environment:
      TZ: Asia/Seoul
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_INITDB_ARGS: "--locale=C --encoding=UTF8"
    volumes:
      - ./postgres:/var/lib/postgresql/data
      - ./db/init:/docker-entrypoint-initdb.d:ro
    ports:
      - "${POSTGRES_PORT}:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 10

  backend:
    build:
      context: .
      dockerfile: backend/Dockerfile
    container_name: ${APP_NAME}_backend
    restart: unless-stopped
    env_file:
      - ./backend/.env
    environment:
      TZ: Asia/Seoul
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./backend/logs:/app/logs
      # Host upload dir (Windows: ./backend/uploads, Linux Synology: set UPLOAD_HOST in .env).
      - ${UPLOAD_HOST:-./backend/uploads}:/app/uploads
    depends_on:
      postgres:
        condition: service_healthy

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: ${APP_NAME}_frontend
    restart: unless-stopped
    environment:
      TZ: Asia/Seoul
    ports:
      - "${FRONTEND_PORT}:80"
    depends_on:
      - backend
