Master Application Flow Guide

The Master Application Flow is a comprehensive, production-ready workflow system that combines all subsystems with extensive error handling, fallback mechanisms, and interconnected nodes.

Overview

This workflow represents a complete software application with:

Architecture Components

Core Orchestration Layer

MasterOrchestrator - Entry point for all requests

RequestValidator - Validates all incoming requests

SecurityChecker - Security and compliance

Routing Layer

SubsystemRouter - Routes to appropriate subsystems

Subsystem Processors

OrderProcessor - Complete order lifecycle

PaymentProcessor - Payment processing

UserManager - User operations

Error Handling Layer

ErrorDetector - Detects errors from all sources

ErrorRetrier - Retries with exponential backoff

ErrorResolver - Resolves errors and stores learnings

FallbackHandler - Comprehensive fallback system

Supporting Systems

NotificationManager - Multi-channel notifications

CacheManager - Performance optimization

AuditLogger - Complete audit trail

WorkflowMonitor - Real-time monitoring

WorkflowCompleter - Finalization

Event Flow

The workflow uses an event-driven architecture with 50+ event topics:

master.request-received
  → request.validated
  → security.verified
  → master.routed
  → subsystem.{subsystem}.trigger
  → [subsystem-specific events]
  → notification.sent
  → monitoring.metrics-updated
  → workflow.completed

Error Flow

[Any Step] → error.occurred
  → error.detected
  → error.classified
  → fallback.activated
  → [Fallback Strategy]
    → retry.initiated / fallback.alternative / fallback.skip / fallback.escalate / fallback.graceful-degradation

State Management

All steps share state through Motia’s state system:

// Store state
state.set('key', value)

// Retrieve state
const value = state.get('key')

// Common state keys:
- master-${executionId} - Master execution context
- validation-${executionId} - Validation results
- security-${executionId} - Security check results
- routing-${executionId} - Routing decisions
- order-${orderId} - Order data
- payment-${paymentId} - Payment data
- cache-${key} - Cache entries
- audit-logs - Audit log history
- workflow-monitoring - Monitoring metrics

Memory Integration

Memory is integrated at 10+ points:

  1. Master Orchestrator - Searches for similar past executions
  2. Security Checker - Detects suspicious activity patterns
  3. Subsystem Router - Uses memory for routing decisions
  4. Order Processor - Stores order completion in memory
  5. Payment Processor - Stores payment transactions
  6. User Manager - Loads user preferences from memory
  7. Approval Router - Finds best approvers from past decisions
  8. Error Resolver - Stores resolution strategies for learning
  9. Fallback Handler - Stores fallback decisions
  10. Workflow Completer - Stores workflow summaries

Usage Examples

Complete Order Flow

curl -X POST http://localhost:3000/master/execute \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "create",
    "subsystem": "order",
    "data": {
      "customerId": "user-123",
      "items": [
        {"id": "prod-1", "price": 49.99, "quantity": 2},
        {"id": "prod-2", "price": 29.99, "quantity": 1}
      ],
      "paymentMethod": "credit-card"
    },
    "userId": "user-123",
    "priority": "normal",
    "fallbackEnabled": true
  }'

Payment Processing

curl -X POST http://localhost:3000/master/execute \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "process",
    "subsystem": "payment",
    "data": {
      "amount": 199.99,
      "paymentMethod": "paypal",
      "customerId": "user-123",
      "orderId": "ORD-12345"
    },
    "userId": "user-123"
  }'

User Management

curl -X POST http://localhost:3000/master/execute \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "profile",
    "subsystem": "user",
    "data": {},
    "userId": "user-123"
  }'

Fallback Strategies

1. Retry Strategy

2. Alternative Strategy

3. Skip Strategy

4. Graceful Degradation

5. Escalation Strategy

Best Practices

  1. Always enable fallbacks - Set fallbackEnabled: true for production
  2. Use appropriate priorities - Set priority based on business needs
  3. Include userId - Always provide userId for security and memory integration
  4. Validate data - Ensure data structure matches subsystem requirements
  5. Monitor metrics - Check workflow monitoring for performance insights
  6. Review audit logs - Regularly review audit logs for compliance

Troubleshooting

High Error Rate

Slow Performance

Security Failures

Next Steps