Workflows Framework
This section provides technical documentation for developers who want to integrate workflows into their applications, extend the engine with custom functionality, or understand the underlying architecture.
For Developers
Getting Started
- Architecture - Understand the workflow engine design, event sourcing, and state machine model
- Services - Integrate workflows via REST API and TypeScript services
- Testing - Write unit and integration tests for workflow implementations
Advanced Topics
- Extending - Create custom activities, step handlers, and signal processors
Quick Links
Integration Guides
Start workflows, send signals, and complete tasks programmatically:
- Starting Workflows - Create workflow instances via API
- Sending Signals - Resume workflows with external events
- Completing Tasks - Complete user tasks programmatically
- Event Listeners - Subscribe to workflow events
Extension Points
Extend the workflow engine with custom functionality:
- Custom Activities - Add new activity types
- Custom Step Handlers - Implement new step types
- Custom Signal Processors - Process signals with custom logic
Architecture Deep Dive
Understand how the workflow engine works:
- Core Components - Definitions, instances, executor
- Execution Flow - How workflows progress through steps
- Event Sourcing - Complete audit trail
- Compensation - Saga pattern for rollback
- Async Activities - Queue-based execution
Example: Starting a Workflow
import { apiFetch } from '@saasframe/ui/backend/utils/api'
async function startApprovalWorkflow(orderId: string, amount: number) {
const response = await apiFetch('/api/workflows/instances', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
workflowId: 'purchase-approval-v1',
initialContext: {
orderId,
amount,
},
correlationKey: orderId
})
})
if (!response.ok) {
throw new Error('Failed to start workflow')
}
return await response.json()
}
Example: Custom Activity
import { ActivityDefinition, ActivityExecutionContext, ActivityResult } from '../types'
export async function executeSendSmsActivity(
definition: ActivityDefinition,
context: ActivityExecutionContext
): Promise<ActivityResult> {
const { to, message } = definition.config
try {
const smsService = context.container.resolve('smsService')
const result = await smsService.send({ to, message })
return {
success: true,
output: { messageId: result.messageId }
}
} catch (error: any) {
return {
success: false,
error: error.message,
retryable: true
}
}
}
User Documentation
For non-technical users and business users, see the User Guide.
API Reference
REST Endpoints
POST /api/workflows/instances- Start workflowPOST /api/workflows/instances/{id}/signal- Send signalGET /api/workflows/instances/{id}- Get instance detailsGET /api/workflows/instances- List instancesPOST /api/workflows/tasks/{id}/complete- Complete task
Service Interfaces
WorkflowService- Core workflow operationsWorkflowExecutor- State machine executionActivityExecutor- Activity executionTaskService- User task management
Next Steps
- Understand the Architecture: Read the architecture guide to learn how the engine works
- Integrate via API: Follow the services guide to start workflows programmatically
- Extend the Engine: Use the extending guide to add custom functionality
- Test Your Implementation: Follow the testing guide to write comprehensive tests
See Also
- User Guide - Documentation for end users
- Business Rules Architecture - Integrate business rules with workflows
- API Reference - Complete API documentation