AI Workflow Orchestration
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
AI Workflow Orchestration in the DDD project is primarily managed through .NET Aspire, which serves as the central system for service discovery, container management, and cross-service communication. The system coordinates various microservices including Scheduling, Billing, and Identity, while managing infrastructure dependencies like RabbitMQ and SQL Server.
The orchestration layer ensures that bounded contexts can communicate asynchronously via an event-driven architecture while maintaining isolated development environments through "worktree slots." This setup allows for automated startup of message brokers and ensures high observability across the distributed system.
Sources: claude.md:144-150, Aspire.AppHost/AppHost.cs:40-45
System Architecture and Orchestration
The orchestration logic is centralized in the Aspire.AppHost project. It defines the relationships between services and handles the injection of connection strings and environment variables.
Core Orchestrator Components
The orchestration is built around the DistributedApplication builder, which manages:
- Infrastructure Resources: Provisioning and configuring message brokers (RabbitMQ or Azure Service Bus).
- Project Dependencies: Defining startup order and references between APIs.
- Front-end Integration: Managing the Angular SPA lifecycle alongside backend services.
The diagram shows how the Aspire AppHost orchestrates the lifecycle and connectivity between various system components.
Sources: Aspire.AppHost/AppHost.cs:100-150, claude.md:144-165
Messaging and Event-Driven Flow
The project supports multiple messaging frameworks, primarily MassTransit with RabbitMQ, orchestrated to ensure reliable communication between bounded contexts.
Broker Orchestration Logic
The system allows switching between RabbitMQ and Azure Service Bus via configuration. For local development, it can provision an Azure Service Bus emulator or a RabbitMQ container with a management plugin.
| Broker Type | Orchestration Strategy | Connection Configuration |
|---|---|---|
| RabbitMQ | Local Docker Container | AddRabbitMQ with Data Volumes |
| Azure Service Bus | Local Emulator (v2.0.0) | AddAzureServiceBus + RunAsEmulator |
Sources: Aspire.AppHost/AppHost.cs:55-100, WebApplications/Billing.WebApi/Program.cs:45-55
Event Orchestration Flow
When a domain event occurs in one context (e.g., Scheduling), it is published as an Integration Event to the message bus, where other contexts (e.g., Billing) consume it.
This sequence illustrates the cross-service event orchestration handled by the messaging infrastructure.
Sources: claude.md:65-80, WebApplications/Billing.WebApi/Program.cs:50-53
Environment Isolation (Worktree Slots)
A unique feature of the orchestration is the support for Worktree Slots, which allows up to five concurrent development environments on the same machine without port or database collisions.
Slot-Aware Configuration
The WorktreeSlot utility derives ports and database names based on the active slot:
- Ports:
base + 100 * (slot - 1) - Databases: Suffixes the Initial Catalog with
_S{slot}(e.g.,DDDbecomesDDD_S2).
The logic flow for resolving environment isolation during orchestration initialization.
Sources: Aspire.AppHost/WorktreeSlot.cs:33-60, Aspire.AppHost/AppHost.cs:14-35
Infrastructure Automation
The project uses PowerShell scripts integrated into the MSBuild process to ensure the required Docker environment is ready before services start.
Docker Lifecycle Management
The ensure-docker.ps1 script performs health checks on the RabbitMQ container. If the container is not running, it executes docker-compose up -d. The system includes "fail-fast" logic to prevent build hangs if Docker Desktop is not active.
| Parameter | Type | Default | Description |
|---|---|---|---|
TimeoutSeconds | int | 60 | Max time to wait for container health |
SkipHealthCheck | switch | false | If set, starts container without waiting |
Sources: scripts/ensure-docker.ps1:7-40, scripts/DOCKER_AUTOSTART_FIX.md:15-30
Conclusion
The AI Workflow Orchestration in this repository is a robust implementation of .NET Aspire and event-driven patterns. By centralizing service management, automating infrastructure checks, and providing environment isolation through worktree slots, the system creates a highly scalable and developer-friendly architecture for mastering Domain-Driven Design and microservices integration.