version: "3.9"

services:
  db:
    image: postgres:16-alpine
    container_name: dwa_postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: dwa_user
      POSTGRES_PASSWORD: dwa_pass
      POSTGRES_DB: dwa_ai_tracker
    ports:
      - "5437:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U dwa_user -d dwa_ai_tracker"]
      interval: 5s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: dwa_backend
    restart: unless-stopped
    ports:
      - "8003:8000"
    environment:
      DATABASE_URL: postgresql+asyncpg://dwa_user:dwa_pass@db:5432/dwa_ai_tracker
      JWT_SECRET_KEY: dev-secret-change-in-production
      JWT_ALGORITHM: HS256
      JWT_EXPIRATION_MINUTES: 1440
      APP_ENV: production
      CORS_ORIGINS: http://localhost:3700
      BASE_URL: http://localhost:8003
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - ./backend/app:/code/app

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: dwa_frontend
    restart: unless-stopped
    ports:
      - "3700:3700"
    environment:
      NEXT_PUBLIC_API_URL: http://localhost:8003/api
    depends_on:
      - backend
    volumes:
      - ./frontend/src:/app/src

volumes:
  pgdata:
