services:
  server:
    build:
      context: .
      dockerfile: server/Dockerfile
      target: dev
    init: true
    command: django-admin runserver 0.0.0.0:8000
    environment:
      DJANGO_SECRET_KEY: secret
      DJANGO_DEBUG: "true"
      DJANGO_ALLOWED_HOSTS: "*"
      DATABASE_URL: postgres://postgres@postgres/postgres
    ports:
      - 8000:8000
    volumes:
      - ./server:/app/
      - ./client:/client/
    depends_on:
      postgres:
        condition: service_healthy

  client:
    build:
      context: .
      dockerfile: client/Dockerfile
      target: dev
    init: true
    command: npm run dev -- --host
    volumes:
      - ./client:/client/
    ports:
      - 5173:5173

  postgres:
    image: postgres:15
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust
    expose:
      - 5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5
