# Architecture Patterns - Common patterns identified from requirements

requirement_patterns:
  realtime_collaboration:
    triggers:
      - "real-time"
      - "collaborative"
      - "live updates"
      - "multi-user"
      - "simultaneous editing"
    decisions_needed:
      - websocket_solution
      - conflict_resolution
      - state_synchronization
      - presence_tracking
      - optimistic_updates
    suggested_stack:
      - "Socket.io or WebSocket native"
      - "Redis for pub/sub"
      - "Operational Transforms or CRDTs for conflict resolution"
      - "PostgreSQL for persistence"

  ecommerce:
    triggers:
      - "shopping cart"
      - "checkout"
      - "payments"
      - "inventory"
      - "product catalog"
    decisions_needed:
      - payment_processor
      - cart_persistence
      - inventory_management
      - order_workflow
      - tax_calculation
    suggested_stack:
      - "Stripe or PayPal for payments"
      - "PostgreSQL for products and orders"
      - "Redis for cart sessions"
      - "BullMQ for order processing"

  saas_platform:
    triggers:
      - "multi-tenant"
      - "subscription"
      - "billing"
      - "team management"
      - "roles and permissions"
    decisions_needed:
      - tenancy_model
      - subscription_billing
      - permission_system
      - team_collaboration
      - usage_tracking
    suggested_stack:
      - "PostgreSQL with Row Level Security"
      - "Stripe Billing for subscriptions"
      - "RBAC or ABAC for permissions"
      - "NextAuth or Clerk for auth"

  content_platform:
    triggers:
      - "CMS"
      - "blog"
      - "publishing"
      - "content management"
      - "editorial workflow"
    decisions_needed:
      - content_storage
      - rich_text_editor
      - media_handling
      - version_control
      - publishing_workflow
    suggested_stack:
      - "PostgreSQL for structured content"
      - "S3 or Cloudinary for media"
      - "Tiptap or Slate for rich text"
      - "Algolia for search"

  data_analytics:
    triggers:
      - "dashboards"
      - "reporting"
      - "metrics"
      - "analytics"
      - "data visualization"
    decisions_needed:
      - data_warehouse
      - etl_pipeline
      - visualization_library
      - query_optimization
      - caching_strategy
    suggested_stack:
      - "PostgreSQL or ClickHouse"
      - "Apache Airflow or Temporal for ETL"
      - "Chart.js or D3 for visualization"
      - "Redis for query caching"

  social_platform:
    triggers:
      - "social network"
      - "feed"
      - "following"
      - "likes"
      - "comments"
    decisions_needed:
      - graph_relationships
      - feed_algorithm
      - notification_system
      - content_moderation
      - privacy_controls
    suggested_stack:
      - "PostgreSQL with graph extensions or Neo4j"
      - "Redis for feed caching"
      - "Elasticsearch for user search"
      - "WebSockets for notifications"

  marketplace:
    triggers:
      - "marketplace"
      - "vendors"
      - "buyers and sellers"
      - "transactions"
      - "escrow"
    decisions_needed:
      - payment_splitting
      - escrow_handling
      - vendor_management
      - dispute_resolution
      - commission_model
    suggested_stack:
      - "Stripe Connect for payments"
      - "PostgreSQL for transactions"
      - "BullMQ for async processing"
      - "S3 for vendor assets"

  streaming_platform:
    triggers:
      - "video streaming"
      - "live streaming"
      - "media delivery"
      - "broadcast"
    decisions_needed:
      - video_encoding
      - cdn_strategy
      - streaming_protocol
      - bandwidth_optimization
      - drm_protection
    suggested_stack:
      - "AWS MediaConvert or Mux"
      - "CloudFront or Fastly CDN"
      - "HLS or DASH protocol"
      - "S3 for video storage"

  iot_platform:
    triggers:
      - "IoT"
      - "sensors"
      - "device management"
      - "telemetry"
      - "edge computing"
    decisions_needed:
      - message_protocol
      - time_series_database
      - device_authentication
      - data_ingestion
      - edge_processing
    suggested_stack:
      - "MQTT or CoAP protocol"
      - "TimescaleDB or InfluxDB"
      - "Apache Kafka for ingestion"
      - "Grafana for monitoring"

  ai_application:
    triggers:
      - "machine learning"
      - "AI features"
      - "LLM integration"
      - "computer vision"
      - "NLP"
    decisions_needed:
      - model_serving
      - vector_database
      - prompt_management
      - token_optimization
      - fallback_strategy
    suggested_stack:
      - "OpenAI or Anthropic API"
      - "Pinecone or pgvector for embeddings"
      - "Redis for prompt caching"
      - "Langchain or LlamaIndex"

# Quality attribute patterns
quality_attributes:
  high_availability:
    triggers:
      - "99.9% uptime"
      - "high availability"
      - "fault tolerance"
      - "disaster recovery"
    architectural_needs:
      - load_balancing
      - database_replication
      - health_checks
      - circuit_breakers
      - graceful_degradation

  high_performance:
    triggers:
      - "millisecond response"
      - "high throughput"
      - "low latency"
      - "performance critical"
    architectural_needs:
      - caching_layers
      - database_optimization
      - cdn_strategy
      - code_splitting
      - lazy_loading

  high_security:
    triggers:
      - "compliance"
      - "HIPAA"
      - "GDPR"
      - "financial data"
      - "PCI DSS"
    architectural_needs:
      - encryption_at_rest
      - encryption_in_transit
      - audit_logging
      - access_controls
      - data_isolation

  scalability:
    triggers:
      - "millions of users"
      - "elastic scale"
      - "global reach"
      - "viral growth"
    architectural_needs:
      - horizontal_scaling
      - database_sharding
      - microservices
      - queue_systems
      - auto_scaling

# Integration patterns
integration_requirements:
  payment_processing:
    common_choices:
      - "Stripe - most developer friendly"
      - "PayPal - widest consumer adoption"
      - "Square - best for in-person + online"
    considerations:
      - transaction_fees
      - international_support
      - subscription_handling
      - marketplace_capabilities

  email_service:
    common_choices:
      - "Resend - modern, developer friendly"
      - "SendGrid - mature, scalable"
      - "Amazon SES - cost effective at scale"
      - "Postmark - transactional focus"
    considerations:
      - deliverability
      - template_management
      - analytics_needs
      - cost_per_email

  sms_notifications:
    common_choices:
      - "Twilio - most comprehensive"
      - "Amazon SNS - AWS integrated"
      - "Vonage - competitive pricing"
    considerations:
      - international_coverage
      - delivery_rates
      - two_way_messaging
      - cost_per_message

  authentication_providers:
    social_providers:
      - "Google - highest adoption"
      - "GitHub - developer focused"
      - "Microsoft - enterprise"
      - "Apple - iOS users"
    enterprise_providers:
      - "SAML 2.0"
      - "OAuth 2.0"
      - "OpenID Connect"
      - "Active Directory"

# Decision heuristics
decision_rules:
  database_selection:
    if_requirements_include:
      - complex_relationships: "PostgreSQL"
      - flexible_schema: "MongoDB"
      - time_series: "TimescaleDB"
      - graph_data: "Neo4j or PostgreSQL with extensions"
      - key_value: "Redis"
      - wide_column: "Cassandra"

  api_pattern_selection:
    if_requirements_include:
      - simple_crud: "REST"
      - complex_queries: "GraphQL"
      - type_safety_critical: "tRPC"
      - microservices: "gRPC"
      - public_api: "REST with OpenAPI"

  deployment_selection:
    if_requirements_include:
      - nextjs_only: "Vercel"
      - complex_infrastructure: "AWS"
      - quick_prototype: "Railway"
      - global_edge: "Fly.io"
      - kubernetes_needed: "GCP or AWS EKS"
