version: '3.8'

# Development compose: backend with VNC + PostgreSQL for chat persistence.
# Frontend runs locally with `cd frontend && npm run dev`.

services:
  db:
    image: postgres:16-alpine
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: openbrowser
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 3s
      retries: 5

  backend:
    build:
      context: .
      dockerfile: backend/Dockerfile
    ports:
      - "8000:8000"      # FastAPI backend
      - "6080-6090:6080-6090"  # VNC websockify ports
    env_file:
      - ./backend/.env
    environment:
      - VNC_ENABLED=true
      - VNC_WIDTH=1920
      - VNC_HEIGHT=1080
      - DEBUG=true
      - AUTH_ENABLED=false
      - CORS_ORIGINS=["http://localhost:3000","http://127.0.0.1:3000"]
      - DATABASE_URL=postgresql+asyncpg://postgres:${POSTGRES_PASSWORD}@db:5432/openbrowser
    volumes:
      # Mount for hot-reload during development
      - ./backend/app:/app/backend/app
      - ./src:/app/src
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped
    # Required for Xvfb to work properly
    shm_size: '2gb'
    # Security context for X11
    security_opt:
      - seccomp:unconfined

volumes:
  pgdata:
