version: '3.8'

services:
  postgres:
    image: postgres:16-alpine
    container_name: carry-your-live-db
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: carry_your_live
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: .
      target: dev
    container_name: carry-your-live-api
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql://postgres:postgres@postgres:5432/carry_your_live
      JWT_SECRET: your-super-secret-jwt-key-change-in-production-min-32-chars
      PORT: 3000
      NODE_ENV: development
      FRONTEND_URL: http://localhost:8081
    ports:
      - "3000:3000"
    volumes:
      - ./:/app
      - backend_node_modules:/app/node_modules
    command: >
      sh -c "npm run db:push || true
      && npm run dev"

volumes:
  postgres_data:
  backend_node_modules:
