Command Flow
The Command Flow diagram illustrates how commands flow through the system, from command handlers to repositories, generating events along the way. This provides a detailed view of the system's implementation architecture following the Command Query Responsibility Segregation (CQRS) pattern.
What is Command Flow?
The Command Flow diagram shows:
- Command Handlers: Classes that process commands
- Commands: User actions or system operations
- Domain Events: Facts that have happened in the system
- Repositories: Data storage components
- Flow: How commands flow through the system to generate events
The Bartendie Command Flow
The diagram below shows the command flow for the Bartendie system:
Key Components
Command Handlers
Command handlers are responsible for processing commands and producing domain events. Each handler typically:
- Validates the command
- Retrieves data from repositories
- Performs business logic
- Persists changes to repositories
- Generates domain events
Examples include:
- ScheduleEventHandler: Handles event creation
- CreateMenuHandler: Handles menu creation
- CheckInventoryHandler: Handles inventory checking
Commands
Commands are instructions to do something in the system. They are typically initiated by users or other parts of the system. Commands are named in the imperative tense:
- Schedule Event: Create a new event
- Check Inventory: Check current stock levels
- Add Recipe To Menu: Add a recipe to a menu
Domain Events
Domain events represent something that has happened in the system. They are named in the past tense:
- EventScheduled: An event has been scheduled
- InventoryChecked: Inventory has been checked
- RecipeAddedToMenu: A recipe has been added to a menu
Repositories
Repositories provide access to persistent storage for domain entities:
- EventRepository: Stores event data
- MenuRepository: Stores menu data
- InventoryRepository: Stores inventory data
- RecipeRepository: Stores recipe data
Event Triggers
Event triggers (shown as dotted lines) represent event-driven behavior where an event triggers a new command:
- EventScheduled triggers Define Event Theme
- ThemeDefined triggers Create Menu
- MenuCreated triggers Check Inventory
Main Workflows
The Command Flow diagram shows several key workflows:
Event Planning Workflow
- Schedule Event command is processed by ScheduleEventHandler
- EventScheduled event is generated
- This triggers the Define Event Theme command
- DefineEventThemeHandler processes the command
- ThemeDefined event is generated
- This triggers the Create Menu command
Inventory Management Workflow
- MenuCreated event triggers Check Inventory command
- CheckInventoryHandler processes the command
- InventoryChecked event is generated
- This triggers Generate Shopping List command
- ShoppingListGenerated event is produced
- When supplies are purchased, Update Inventory is triggered
Recipe Management Workflow
- Create Recipe command is processed by CreateRecipeHandler
- RecipeCreated event is generated
- This triggers Calculate Recipe Balance command
- RecipeBalanceCalculated event is generated
- If the recipe is unbalanced, it triggers Suggest Balancing Ingredients
Benefits of Command Flow Modeling
The Command Flow diagram provides several benefits:
- Clear Implementation Path: Provides a clear path for implementing the system
- Separation of Concerns: Clearly separates commands, events, and repositories
- Event-Driven Architecture: Shows how events trigger subsequent commands
- Traceability: Makes it easy to trace how a user action flows through the system
- Testability: Each command handler can be tested in isolation
This diagram complements the Event Storming and Domain Model diagrams by focusing more on the implementation details of the system's architecture, particularly the command handling and event generation mechanisms.