# Development Environment
# Hot-reload enabled for rapid development
# Includes debugging tools and utilities

services:
  # Application with hot-reload
  app:
    build:
      context: ./app
      dockerfile: Dockerfile.dev
      target: development
    container_name: dev-app
    restart: unless-stopped
    ports:
      - "3000:3000"
      - "9229:9229"  # Node.js debugger port
    volumes:
      # Bind mount for live code changes
      - ./app:/app
      # Preserve node_modules in container
      - /app/node_modules
      # Mount logs
      - ./logs:/app/logs
    environment:
      - NODE_ENV=development
      - DEBUG=app:*
      - DATABASE_URL=postgresql://dev:dev@db:5432/devdb
      - REDIS_URL=redis://redis:6379
      - CHOKIDAR_USEPOLLING=true  # Enable hot-reload in Docker
    command: npm run dev
    networks:
      - dev
    depends_on:
      - db
      - redis
    stdin_open: true  # Keep STDIN open
    tty: true         # Allocate a pseudo-TTY

  # PostgreSQL Database
  db:
    image: postgres:16-alpine
    container_name: dev-db
    restart: unless-stopped
    ports:
      - "5432:5432"  # Exposed for external tools
    environment:
      - POSTGRES_USER=dev
      - POSTGRES_PASSWORD=dev
      - POSTGRES_DB=devdb
    volumes:
      - postgres-data:/var/lib/postgresql/data
      - ./database/init:/docker-entrypoint-initdb.d
      - ./database/seed:/docker-entrypoint-initdb.d/seed
    networks:
      - dev

  # Redis for caching
  redis:
    image: redis:7-alpine
    container_name: dev-redis
    restart: unless-stopped
    ports:
      - "6379:6379"  # Exposed for external tools
    command: redis-server --appendonly yes
    volumes:
      - redis-data:/data
    networks:
      - dev

  # Mailhog for email testing
  mailhog:
    image: mailhog/mailhog:latest
    container_name: dev-mailhog
    restart: unless-stopped
    ports:
      - "1025:1025"  # SMTP server
      - "8025:8025"  # Web UI
    networks:
      - dev

  # Adminer for database management
  adminer:
    image: adminer:latest
    container_name: dev-adminer
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      - ADMINER_DEFAULT_SERVER=db
      - ADMINER_DESIGN=nette
    networks:
      - dev
    depends_on:
      - db

  # Redis Commander for Redis management
  redis-commander:
    image: rediscommander/redis-commander:latest
    container_name: dev-redis-commander
    restart: unless-stopped
    ports:
      - "8081:8081"
    environment:
      - REDIS_HOSTS=local:redis:6379
    networks:
      - dev
    depends_on:
      - redis

  # Optional: MinIO for S3-compatible object storage testing
  minio:
    image: minio/minio:latest
    container_name: dev-minio
    restart: unless-stopped
    ports:
      - "9000:9000"  # API
      - "9001:9001"  # Console
    environment:
      - MINIO_ROOT_USER=minioadmin
      - MINIO_ROOT_PASSWORD=minioadmin
    volumes:
      - minio-data:/data
    command: server /data --console-address ":9001"
    networks:
      - dev
    profiles:
      - storage

networks:
  dev:
    driver: bridge
    name: dev-network

volumes:
  postgres-data:
    name: dev-postgres-data
  redis-data:
    name: dev-redis-data
  minio-data:
    name: dev-minio-data
