name: patchmon-dev

services:
  database:
    image: postgres:17-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: patchmon_db
      POSTGRES_USER: patchmon_user
      POSTGRES_PASSWORD: 1NS3CU6E_DEV_D8_PASSW0RD
    ports:
      - "5432:5432"
    volumes:
      - ./compose_dev_data/db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U patchmon_user -d patchmon_db"]
      interval: 3s
      timeout: 5s
      retries: 7

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: redis-server --requirepass 1NS3CU6E_DEV_R3DIS_PASSW0RD
    environment:
      REDIS_PASSWORD: 1NS3CU6E_DEV_R3DIS_PASSW0RD
    ports:
      - "6379:6379"
    volumes:
      - ./compose_dev_data/redis:/data
    healthcheck:
      test: ["CMD", "redis-cli", "--no-auth-warning", "-a", "1NS3CU6E_DEV_R3DIS_PASSW0RD", "ping"]
      interval: 3s
      timeout: 5s
      retries: 7

  backend:
    build:
      context: ..
      dockerfile: docker/backend.Dockerfile
      target: development
      tags: [patchmon-backend:dev]
    restart: unless-stopped
    environment:
      NODE_ENV: development
      LOG_LEVEL: info
      DATABASE_URL: postgresql://patchmon_user:1NS3CU6E_DEV_D8_PASSW0RD@database:5432/patchmon_db
      JWT_SECRET: INS3CURE_DEV_7WT_5ECR3T
      SERVER_PROTOCOL: http
      SERVER_HOST: localhost
      SERVER_PORT: 3000
      CORS_ORIGIN: http://localhost:3000
      # Redis Configuration
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_PASSWORD: 1NS3CU6E_DEV_R3DIS_PASSW0RD
      REDIS_DB: 0
    ports:
      - "3001:3001"
    volumes:
      - ./compose_dev_data/agents:/app/agents
    depends_on:
      database:
        condition: service_healthy
      redis:
        condition: service_healthy
    develop:
      watch:
        - action: sync
          path: ../backend/src
          target: /app/backend/src
          ignore:
            - node_modules/
        - action: sync
          path: ../backend/prisma
          target: /app/backend/prisma
        - action: rebuild
          path: ../backend/package.json

  frontend:
    build:
      context: ..
      dockerfile: docker/frontend.Dockerfile
      target: development
      tags: [patchmon-frontend:dev]
    restart: unless-stopped
    environment:
      BACKEND_HOST: backend
      BACKEND_PORT: 3001
    ports:
      - "3000:3000"
    depends_on:
      backend:
        condition: service_healthy
    develop:
      watch:
        - action: sync
          path: ../frontend/src
          target: /app/frontend/src
          ignore:
            - node_modules/
        - action: rebuild
          path: ../frontend/package.json
