version: '3.8'

services:
  app:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: healthcare-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./backend:/var/www
      - ./backend/docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - healthcare-network
    depends_on:
      - db
      - redis

  webserver:
    image: nginx:alpine
    container_name: healthcare-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./backend:/var/www
      - ./backend/docker/nginx.conf:/etc/nginx/conf.d/default.conf
    networks:
      - healthcare-network
    depends_on:
      - app

  db:
    image: postgres:15-alpine
    container_name: healthcare-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: healthcare_db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: secret
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - healthcare-network

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

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: healthcare-frontend
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - NEXT_PUBLIC_API_URL=http://localhost:8080/api
    networks:
      - healthcare-network
    depends_on:
      - webserver

volumes:
  postgres_data:

networks:
  healthcare-network:
    driver: bridge
