> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://cla-demo.postmansolutions.com/design/account-payable-to-fluxx-hld/documents-ai-workflow-orchestrator/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://cla-demo.postmansolutions.com/_mcp/server. # Documents AI Workflow Orchestrator ## Software Architecture Analysis: Temporal to Azure Durable Functions Migration ### High-Level Overview Based on the temporal folder structure, I can see a comprehensive workflow orchestration system with multiple workflows and activities for invoice processing. Let me analyze the components and create a migration strategy. Summarized conversation historyNow I'll read the specific workflow stage files to understand the complete architecture: Now I need to see the structure of the activity definitions across all modules: Now let me get more activity definitions to understand the complete scope: Let me check what activities are available to get a complete list: Now let me get a complete view of all activities to understand the migration scope: Now let me get the complete activity structure from one more key file: Now let me create a comprehensive architectural overview and migration plan for converting the Temporal workflows to Azure Durable Functions. Based on my analysis, I can provide the high-level overview and point stories you requested. # Temporal to Azure Durable Functions Migration Overview ## Current Temporal Architecture The AutoExtract system uses a sophisticated multi-stage invoice processing workflow orchestrated by Temporal. Here's the complete architecture: ### **Main Orchestrator Workflow** * **`InvoiceWorkflow`** - Primary orchestrator that coordinates all child workflows * Dynamically executes child workflows based on client configuration stages * Handles failure recovery, user interaction pauses, and stage progression ### **Child Workflow Stages** (13 total) 1. **`WorkflowSplitInvoice`** - Document preprocessing and splitting 2. **`WorkflowInvoiceIngest`** - PDF processing, image generation, OCR extraction 3. **`WorkflowInvoiceIntake`** - Validation, duplicate detection, sales tax handling 4. **`WorkflowInvoiceMatching`** - PO matching and line item correlation 5. **`WorkflowInvoiceManual`** - Manual review processes 6. **`WorkflowInvoiceManualApproval`** - Approval workflows 7. **`WorkflowLineItemCoding`** - AI-based line item classification 8. **`WorkflowInvoiceFiling`** - ERP system integration 9. **`WorkflowInvoiceExport`** - Data export processes 10. **`WorkflowInvoiceExportIIF`** - QuickBooks IIF export 11. **`WorkflowInvoiceClosed`** - Finalization processes 12. **`UserWorkflow`** - User interaction handling 13. **`PreprocessInvoiceWorkflow`** - Document preprocessing ### **Activity Modules** (30+ activities across 11 modules) * **Azure Cosmos Activities** (4): Database operations, document storage * **Line Item Coding Activities** (5): ML-based classification, asset autofill * **Ingest Activities** (8): Document processing, OCR, image generation * **Matching Activities** (2): PO data retrieval, line item matching * **Filing Activities** (1): ERP synchronization * **Manual Activities** (2): Manual review object creation * **Workflow Activities** (5): Stage management, initialization, completion * **Intake Activities** (3): Validation, duplicate detection * **Background Activities** (1): Token handling * **Preprocessing Activities** (3): Image processing, invoice splitting ## Azure Durable Functions Migration Architecture ### **Function App Structure** **Main Orchestrator Function** ``` InvoiceOrchestrator (Durable Function) ├── Replaces: InvoiceWorkflow ├── Pattern: Function Chaining + Human Interaction ├── Triggers: HTTP, Service Bus, Storage Queue ``` **Sub-Orchestrator Functions** (Consolidate from 13 to 5) ``` 1. DocumentProcessingOrchestrator ├── Combines: WorkflowSplitInvoice + WorkflowInvoiceIngest + WorkflowInvoiceIntake ├── Activities: PDF processing, OCR, validation, duplicate detection 2. InvoiceMatchingOrchestrator ├── Combines: WorkflowInvoiceMatching + WorkflowLineItemCoding ├── Activities: PO matching, ML classification, coding 3. ManualReviewOrchestrator ├── Combines: WorkflowInvoiceManual + WorkflowInvoiceManualApproval + UserWorkflow ├── Activities: Manual review, approval workflows, user interactions 4. ERPIntegrationOrchestrator ├── Combines: WorkflowInvoiceFiling + WorkflowInvoiceExport + WorkflowInvoiceExportIIF ├── Activities: ERP sync, data export, format conversion 5. WorkflowCompletionOrchestrator ├── Combines: WorkflowInvoiceClosed + background activities ├── Activities: Finalization, cleanup, notifications ``` **Activity Functions** (Consolidate from 30+ to 15) ``` Document Processing Activities (5): ├── ExtractDocumentActivity (OCR, image generation) ├── ValidateInvoiceActivity (validation, duplicate detection) ├── SplitInvoiceActivity (document splitting) ├── GenerateImagesActivity (image processing) ├── ProcessDocumentActivity (general document operations) Business Logic Activities (4): ├── MatchPOActivity (purchase order matching) ├── ClassifyLineItemsActivity (ML-based coding) ├── CreateManualReviewActivity (manual process setup) ├── CalculateBusinessRulesActivity (terms, due dates) Integration Activities (3): ├── DatabaseActivity (Cosmos DB operations) ├── ERPSyncActivity (ERP system integration) ├── ExportDataActivity (multiple format exports) Workflow Management Activities (3): ├── InitializeWorkflowActivity (setup and configuration) ├── UpdateWorkflowStateActivity (progress tracking) ├── CompleteWorkflowActivity (finalization) ``` ## Migration Point Stories (Development Epics) ### **Story 1: Core Infrastructure & Main Orchestrator Migration** **Effort: 1-2 sprints** **Acceptance Criteria:** * Create Azure Function App with Durable Functions extension * Implement main `InvoiceOrchestrator` function replacing `InvoiceWorkflow` * Migrate client configuration and stage management logic * Implement function chaining pattern for sub-orchestrators * Set up monitoring, logging, and error handling * Create deployment pipeline and environment configuration **Technical Dependencies:** * Azure Functions Premium plan for long-running workflows * Azure Storage for Durable Functions state management * Application Insights for monitoring and diagnostics * Service Bus for reliable messaging between functions ### **Story 2: Document Processing Pipeline Migration** **Effort: 1-2 sprints** **Acceptance Criteria:** * Migrate `DocumentProcessingOrchestrator` combining ingest/intake workflows * Convert document processing activities (PDF parsing, OCR, image generation) * Implement Azure Form Recognizer integration for OCR capabilities * Migrate validation and duplicate detection logic * Set up Azure Blob Storage integration for document storage * Implement error handling and retry policies for external service calls **Technical Dependencies:** * Azure Form Recognizer for OCR processing * Azure Blob Storage for document and image storage * Azure Computer Vision API integration * Cosmos DB SDK for document operations ### **Story 3: Business Logic & AI Integration Migration** **Effort: 1-2 sprints** **Acceptance Criteria:** * Migrate `InvoiceMatchingOrchestrator` with PO matching and ML coding * Convert line item coding activities using Azure ML integration * Implement PO data retrieval and matching algorithms * Migrate ML model inference for line item classification * Set up Azure Cognitive Services integration for enhanced AI capabilities * Implement business rules engine for terms and due date calculation **Technical Dependencies:** * Azure Machine Learning service for model hosting * Azure Cognitive Services for enhanced AI capabilities * Integration with external ERP systems for PO data * Cosmos DB for storing ML training data and results ### **Story 4: Human Interaction & Approval Workflows** **Effort: 1-2 sprints** **Acceptance Criteria:** * Migrate `ManualReviewOrchestrator` with human interaction patterns * Implement Durable Functions human interaction pattern * Convert user approval workflows and manual review processes * Set up webhook endpoints for external system integration * Implement timeout handling for pending user actions * Create notification system for user interactions **Technical Dependencies:** * Azure Service Bus for reliable messaging * Azure SignalR for real-time UI updates * Webhook infrastructure for external integrations * Azure Active Directory for user authentication ### **Story 5: ERP Integration & Data Export Migration** **Effort: 1-2 sprints** **Acceptance Criteria:** * Migrate `ERPIntegrationOrchestrator` with ERP sync and export capabilities * Convert filing activities for multiple ERP systems (SageIntacct, Epicor21) * Implement data export functions for various formats (IIF, CSV, XML) * Set up secure connectivity to external ERP systems * Implement data transformation and mapping logic * Create monitoring and alerting for integration failures **Technical Dependencies:** * Azure Logic Apps for complex ERP integrations * Azure Data Factory for data transformation pipelines * Azure Key Vault for secure credential management * VPN/ExpressRoute for secure ERP connectivity ## Migration Benefits 1. **Simplified Architecture**: Reduce from 13 child workflows to 5 sub-orchestrators 2. **Improved Scalability**: Azure Functions auto-scaling and consumption-based pricing 3. **Enhanced Monitoring**: Native Azure integration with Application Insights 4. **Reduced Complexity**: Consolidate 30+ activities into 15 focused functions 5. **Better Resilience**: Built-in retry policies and error handling patterns 6. **Cost Optimization**: Pay-per-execution model vs. always-running Temporal workers This migration plan provides a clear path from the current Temporal-based system to Azure Durable Functions while maintaining all existing functionality and improving operational characteristics. ## Docs - [Workflow Stories Needed](https://cla-demo.postmansolutions.com/design/account-payable-to-fluxx-hld/documents-ai-workflow-orchestrator/workflow-stories-needed.md) - [Workflow implimenation](https://cla-demo.postmansolutions.com/design/account-payable-to-fluxx-hld/documents-ai-workflow-orchestrator/workflow-implimenation.md)