name: message-queues
description: Document message queue implementation and async processing patterns
version: "1.0"
applies_to:
  - codebase_analysis
  - github_analysis
variables:
  depth: comprehensive
stages:
  - name: base_patterns
    type: builtin
    target: patterns
    enabled: true
    uses_history: false

  - name: queue_architecture
    type: custom
    target: architecture
    uses_history: false
    enabled: true
    prompt: >
      Analyze the message queue architecture.
      
      Identify:
      1. Message broker used (RabbitMQ, SQS, Kafka, Redis, etc.)
      2. Queue topology (direct, topic, fanout, headers)
      3. Message exchange/queue structure
      4. Producer patterns and configuration
      5. Consumer patterns and configuration
      6. Message routing strategies
      
      Output JSON with:
      - "broker": message broker technology
      - "topology": exchange and queue structure
      - "routing": message routing patterns
      - "producer_config": producer settings
      - "consumer_config": consumer settings
      - "deployment": broker deployment approach

  - name: message_patterns
    type: custom
    target: messages
    uses_history: true
    enabled: true
    prompt: >
      Document message structure and patterns.
      
      Cover:
      1. Message envelope structure (headers, body, metadata)
      2. Message serialization (JSON, Avro, Protobuf)
      3. Message schema validation
      4. Message size limits and chunking
      5. Correlation IDs for tracing
      6. Message priorities (if supported)
      
      Output JSON with:
      - "envelope": message structure
      - "serialization": serialization format
      - "schema_validation": validation approach
      - "size_limits": message size handling
      - "correlation": trace ID propagation
      - "priorities": priority configuration

  - name: consumer_patterns
    type: custom
    target: consumers
    uses_history: true
    enabled: true
    prompt: >
      Document consumer implementation patterns.
      
      Include:
      1. Consumer group/worker pool configuration
      2. Prefetch/concurrency settings
      3. Message acknowledgment modes (auto, manual)
      4. Dead letter queue (DLQ) configuration
      5. Poison pill handling
      6. Consumer scaling strategies
      
      Output JSON with:
      - "worker_pools": concurrency configuration
      - "prefetch": prefetch settings
      - "acknowledgment": ack/nack patterns
      - "dlq": dead letter queue setup
      - "poison_pills": bad message handling
      - "scaling": horizontal scaling approach

  - name: reliability_patterns
    type: custom
    target: reliability
    uses_history: true
    enabled: true
    prompt: >
      Document reliability and durability patterns.
      
      Cover:
      1. Message persistence configuration
      2. Delivery guarantees (at-most-once, at-least-once, exactly-once)
      3. Transaction support (if applicable)
      4. Idempotency handling
      5. Retry policies and backoff
      6. Circuit breaker patterns
      
      Output JSON with:
      - "persistence": message durability
      - "delivery_guarantees": delivery semantics
      - "transactions": transaction support
      - "idempotency": duplicate handling
      - "retries": retry configuration
      - "circuit_breaker": failure handling

  - name: queue_monitoring
    type: custom
    target: monitoring
    uses_history: true
    enabled: true
    prompt: >
      Document queue monitoring and observability.
      
      Include:
      1. Queue depth monitoring
      2. Consumer lag tracking
      3. Message processing rate
      4. Error and DLQ metrics
      5. Connection health monitoring
      6. Alerting thresholds
      
      Output JSON with:
      - "queue_depth": backlog monitoring
      - "consumer_lag": lag metrics
      - "processing_rate": throughput tracking
      - "error_metrics": failure tracking
      - "health_checks": broker health
      - "alerts": alerting configuration

  - name: advanced_patterns
    type: custom
    target: advanced
    uses_history: true
    enabled: true
    prompt: >
      Document advanced message queue patterns.
      
      Cover:
      1. Delayed/scheduled messages
      2. Message batching for throughput
      3. Priority queues
      4. Message TTL and expiration
      5. Competing consumers pattern
      6. Saga pattern for distributed transactions
      
      Output JSON with:
      - "delayed_messages": scheduling patterns
      - "batching": batch processing
      - "priority_queues": priority handling
      - "message_ttl": expiration configuration
      - "competing_consumers": load distribution
      - "saga_pattern": distributed transactions

post_process:
  reorder_sections: []
  add_metadata:
    enhanced: true
    workflow: message-queues
    domain: backend
    has_queue_docs: true
