services:
  # ── PHP-FPM (Laravel Application) ──────────────────────────────────
  app:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: alltrue-app
    restart: unless-stopped
    env_file: ./backend/.env
    volumes:
      - ./backend:/var/www
      - app-storage:/var/www/storage
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - alltrue

  # ── Nginx (Web Server) ────────────────────────────────────────────
  nginx:
    image: nginx:1.25-alpine
    container_name: alltrue-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./backend:/var/www:ro
      - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app
    networks:
      - alltrue

  # ── PostgreSQL (Database) ──────────────────────────────────────────
  postgres:
    image: postgres:15-alpine
    container_name: alltrue-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_DATABASE:-alltrue}
      POSTGRES_USER: ${DB_USERNAME:-alltrue}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-secret}
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U ${DB_USERNAME:-alltrue} -d ${DB_DATABASE:-alltrue}" ]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - alltrue

networks:
  alltrue:
    driver: bridge

volumes:
  app-code:
    driver: local
  app-storage:
    driver: local
