services:
  postgres:
    image: pgvector/pgvector:pg16
    environment:
      POSTGRES_USER: smriti
      POSTGRES_PASSWORD: smriti
      POSTGRES_DB: smriti
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U smriti"]
      interval: 5s
      timeout: 5s
      retries: 5

  backend:
    profiles: ["production"]
    build:
      context: ./backend
      dockerfile: Dockerfile
    # ports:
    #   - "8000:8000"
    environment:
      DATABASE_URL: postgresql://smriti:smriti@postgres:5432/smriti
      OPENAI_API_KEY: ${OPENAI_API_KEY:-}
      OPENAI_MODEL: ${OPENAI_MODEL:-gpt-4o-mini}
      DEBUG: ${DEBUG:-false}
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - ./backend:/app
    command: >
      sh -c "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload"

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "5173:5173"
    volumes:
      - ./frontend:/app
      - /app/node_modules
    command: npm run dev -- --host 0.0.0.0

volumes:
  postgres_data:
