version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    container_name: yotrip-db
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: travel_db
    ports:
      - "5432:5432"
    volumes:
      - pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d travel_db"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: yotrip-redis
    ports:
      - "6379:6379"

  backend:
    build:
      context: ./backend
      target: development
    container_name: yotrip-backend
    command: >
      sh -c "npx prisma migrate dev --schema=prisma/schema.prisma && npm run start:dev"
    ports:
      - "3001:3001"
    volumes:
      - ./backend:/usr/src/app
      - /usr/src/app/node_modules
    environment:
      DATABASE_URL: "postgresql://postgres:password@postgres:5432/travel_db?schema=public"
      REDIS_URL: "redis://redis:6379"
      PORT: 3001
      ADMIN_SECRET_KEY: "yotrip_secret_admin_key"
      JWT_SECRET: "super-secret"
      FRONTEND_URL: "http://localhost:5173"
      NODE_ENV: development
      SMTP_HOST: "${SMTP_HOST}"
      SMTP_PORT: "${SMTP_PORT}"
      SMTP_SECURE: "${SMTP_SECURE}"
      SMTP_USER: "${SMTP_USER}"
      SMTP_PASS: "${SMTP_PASS}"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started

  frontend:
    build:
      context: ./frontend
      target: development
    container_name: yotrip-frontend
    command: npm run dev -- --host 0.0.0.0
    ports:
      - "5173:5173"
    volumes:
      - ./frontend:/usr/src/app
      - /usr/src/app/node_modules
    environment:
      VITE_API_URL: "http://localhost:3001"
    depends_on:
      - backend

volumes:
  pg_data:
