services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: laravel-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - .:/var/www
    environment:
      SERVICE_TYPE: app
      DB_HOST: db
      DB_DATABASE: ${DB_DATABASE:-laravel_db}
      DB_USERNAME: ${DB_USERNAME:-laravel_user}
      DB_PASSWORD: ${DB_PASSWORD:-laravel_password}
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - laravel-network

  vite:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: laravel-vite
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - .:/var/www
      - node_modules:/var/www/node_modules
    ports:
      - "5173:5173"
    environment:
      SERVICE_TYPE: vite 
    networks:
      - laravel-network

  redis:
    image: redis:7-alpine
    container_name: laravel-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    networks:
      - laravel-network

  nginx:
    image: nginx:stable-alpine
    container_name: laravel-nginx
    restart: unless-stopped
    ports:
      - "8000:8000"
    volumes:
      - .:/var/www
      - ./docker-compose/nginx/conf.d/:/etc/nginx/conf.d/
    depends_on:
      db:
        condition: service_healthy
    networks:
      - laravel-network

  db:
    image: postgres:18-alpine
    container_name: laravel-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_DATABASE:-laravel_db}
      POSTGRES_USER: ${DB_USERNAME:-laravel_user}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-laravel_password}
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-laravel_user} -d ${DB_DATABASE:-laravel_db}"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - laravel-network

networks:
  laravel-network:
    driver: bridge

volumes:
  pgdata:
  node_modules: