name: event-driven
description: Document event-driven architecture and event sourcing 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: event_architecture
    type: custom
    target: architecture
    uses_history: false
    enabled: true
    prompt: >
      Analyze the event-driven architecture.
      
      Identify:
      1. Event bus/broker technology (Kafka, EventBridge, NATS, etc.)
      2. Event types and categories (domain, integration, notification)
      3. Event schema structure (CloudEvents, custom)
      4. Event producers and consumers
      5. Event versioning strategy
      6. Event ordering and sequencing guarantees
      
      Output JSON with:
      - "event_bus": broker technology
      - "event_types": event categorization
      - "schema": event schema definition
      - "producers_consumers": component mapping
      - "versioning": schema evolution strategy
      - "ordering": ordering guarantees

  - name: event_sourcing
    type: custom
    target: sourcing
    uses_history: true
    enabled: true
    prompt: >
      Document event sourcing implementation (if applicable).
      
      Cover:
      1. Event store selection and configuration
      2. Aggregate reconstruction from events
      3. Snapshot strategies for performance
      4. Event versioning and migration
      5. Temporal queries (point-in-time state)
      6. Projections and read models
      
      Output JSON with:
      - "event_store": storage technology
      - "aggregate_rebuild": reconstruction logic
      - "snapshots": snapshot configuration
      - "event_versioning": version handling
      - "temporal_queries": time-travel queries
      - "projections": read model generation

  - name: cqrs_pattern
    type: custom
    target: cqrs
    uses_history: true
    enabled: true
    prompt: >
      Document CQRS (Command Query Responsibility Segregation) patterns.
      
      Include:
      1. Command handlers and validation
      2. Query handlers and optimization
      3. Read/write model separation
      4. Event handlers for read model updates
      5. Consistency model (eventual vs strong)
      6. Sync vs async read model updates
      
      Output JSON with:
      - "commands": command handling
      - "queries": query optimization
      - "model_separation": read/write split
      - "handlers": event handler patterns
      - "consistency": consistency guarantees
      - "sync_strategies": update strategies

  - name: saga_orchestration
    type: custom
    target: saga
    uses_history: true
    enabled: true
    prompt: >
      Document saga pattern for distributed transactions.
      
      Cover:
      1. Saga orchestration vs choreography
      2. Saga definition and steps
      3. Compensating transactions
      4. Saga state management
      5. Failure handling and rollback
      6. Saga monitoring and timeouts
      
      Output JSON with:
      - "pattern_type": orchestration or choreography
      - "saga_definition": saga structure
      - "compensation": rollback logic
      - "state_management": state tracking
      - "failure_handling": error recovery
      - "monitoring": saga observability

  - name: event_schema_governance
    type: custom
    target: governance
    uses_history: true
    enabled: true
    prompt: >
      Document event schema governance and evolution.
      
      Include:
      1. Schema registry usage (Confluent, AWS Glue)
      2. Schema compatibility rules (backward, forward, full)
      3. Event versioning strategy
      4. Schema validation at producer/consumer
      5. Breaking change detection
      6. Schema documentation standards
      
      Output JSON with:
      - "schema_registry": registry configuration
      - "compatibility": compatibility rules
      - "versioning": version strategy
      - "validation": validation approach
      - "breaking_changes": change detection
      - "documentation": schema docs

  - name: observability_events
    type: custom
    target: observability
    uses_history: true
    enabled: true
    prompt: >
      Document observability in event-driven systems.
      
      Cover:
      1. Event tracing and correlation
      2. Event flow visualization
      3. Dead letter queue monitoring
      4. Event processing lag
      5. Event delivery guarantees verification
      6. Alerting on event anomalies
      
      Output JSON with:
      - "tracing": distributed tracing
      - "flow_visualization": event flow mapping
      - "dlq_monitoring": dead letter tracking
      - "processing_lag": latency monitoring
      - "delivery_guarantees": verification
      - "alerting": anomaly alerts

post_process:
  reorder_sections: []
  add_metadata:
    enhanced: true
    workflow: event-driven
    domain: backend
    has_event_docs: true
