version: '3.8'

services:
  # Laravel Backend
  app:
    build:
      context: ./docker/php
    container_name: dw_app
    volumes:
      - ./backend:/var/www/html
    depends_on:
      - postgres
      - redis
    environment:
      - DB_CONNECTION=pgsql
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_DATABASE=digitalworkshop
      - DB_USERNAME=dw_user
      - DB_PASSWORD=dw_secret
      - REDIS_HOST=redis
    networks:
      - dw_network

  # Nginx (serves Laravel API)
  web:
    image: nginx:alpine
    container_name: dw_web
    ports:
      - "8080:80"
    volumes:
      - ./backend:/var/www/html
      - ./docker/nginx:/etc/nginx/conf.d
    depends_on:
      - app
    networks:
      - dw_network

  # Next.js Frontend
  frontend:
    build:
      context: ./docker/node
    container_name: dw_frontend
    volumes:
      - ./frontend:/app
    ports:
      - "3000:3000"
    command: sh -c "npm install && npm run dev"
    networks:
      - dw_network

  # PostgreSQL Database
  postgres:
    image: postgres:16-alpine
    container_name: dw_postgres
    environment:
      POSTGRES_DB: digitalworkshop
      POSTGRES_USER: dw_user
      POSTGRES_PASSWORD: dw_secret
    volumes:
      - dw_pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - dw_network

  # Redis (cache, session, queue)
  redis:
    image: redis:7-alpine
    container_name: dw_redis
    ports:
      - "6379:6379"
    networks:
      - dw_network

  # Meilisearch (product search)
  meilisearch:
    image: getmeili/meilisearch:v1.8
    container_name: dw_meilisearch
    environment:
      MEILI_MASTER_KEY: dw_search_master_key
    ports:
      - "7700:7700"
    volumes:
      - dw_meili_data:/meili_data
    networks:
      - dw_network

networks:
  dw_network:
    driver: bridge

volumes:
  dw_pgdata:
  dw_meili_data:
