Command Flow
Command Flow
Section titled “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?
Section titled “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
Section titled “The Bartendie Command Flow”The diagram below shows the command flow for the Bartendie system:
flowchart TD
%% Command Handlers
subgraph Command Handlers
%% Event Planning Handlers
CH1[ScheduleEventHandler]
CH2[DefineEventThemeHandler]
CH23[CreateGuestListHandler]
CH24[AddGuestHandler]
CH25[RemoveGuestHandler]
CH26[TrackGuestRSVPHandler]
CH27[SetGuestPreferencesHandler]
CH28[SetAttendanceEstimateHandler]
%% Menu Handlers
CH3[CreateMenuHandler]
CH17[AddRecipeToMenuHandler]
%% Inventory Handlers
CH4[CheckInventoryHandler]
CH5[GenerateShoppingListHandler]
CH6[PurchaseSuppliesHandler]
CH11[UpdateInventoryHandler]
CH48[ScanProductBarcodeHandler]
CH49[LookUpProductDataHandler]
CH50[AddProductToInventoryHandler]
CH51[UpdateProductLevelHandler]
CH52[MarkProductEmptyHandler]
CH53[AddProductToShoppingListHandler]
CH29[RecalculateShoppingQuantitiesHandler]
%% Bar Setup Handlers
CH7[PrepareBarSetupHandler]
CH8[CreateBatchedCocktailsHandler]
CH9[ServeDrinksHandler]
CH10[CollectGuestFeedbackHandler]
%% Recipe Handlers
CH12[CreateRecipeHandler]
CH13[UpdateRecipeHandler]
CH14[RateRecipeHandler]
CH15[TagRecipeHandler]
CH16[SearchRecipesHandler]
CH38[DefineFlavorProfileHandler]
CH39[AddIngredientProfileHandler]
CH40[UpdateIngredientProfileHandler]
CH41[CalculateRecipeBalanceHandler]
CH42[SuggestBalancingIngredientsHandler]
CH43[FilterByFlavorProfileHandler]
CH44[CalculateBatchQuantitiesHandler]
CH45[ScaleRecipeHandler]
CH46[ConvertUnitsHandler]
CH47[SaveBatchRecipeHandler]
%% Tagging System Handlers
CH18[CreateTagHandler]
CH19[UpdateTagHandler]
CH20[ApplyTagHandler]
CH21[RemoveTagHandler]
CH22[SearchByTagHandler]
%% Equipment Handlers
CH30[AddBarToolHandler]
CH31[UpdateBarToolHandler]
CH32[RemoveBarToolHandler]
CH33[AddEquipmentHandler]
CH34[UpdateEquipmentHandler]
CH35[RemoveEquipmentHandler]
CH36[LinkToolsToRecipeHandler]
CH37[CheckToolAvailabilityHandler]
%% Venue Management Handlers
CH54[CreateVenueHandler]
CH55[UpdateVenueHandler]
CH56[AddStorageHandler]
CH57[UpdateStorageHandler]
CH58[RemoveStorageHandler]
CH59[AddBarHandler]
CH60[UpdateBarHandler]
CH61[RemoveBarHandler]
end
%% Commands
%% Event Planning Commands
C1[/"Schedule Event"/]
C2[/"Define Event Theme"/]
C23[/"Create Guest List"/]
C24[/"Add Guest"/]
C25[/"Remove Guest"/]
C26[/"Track Guest RSVP"/]
C27[/"Set Guest Preferences"/]
C28[/"Set Attendance Estimate"/]
%% Menu Commands
C3[/"Create Menu"/]
C17[/"Add Recipe To Menu"/]
%% Inventory Commands
C4[/"Check Inventory"/]
C5[/"Generate Shopping List"/]
C6[/"Purchase Supplies"/]
C11[/"Update Inventory"/]
C48[/"Scan Product Barcode"/]
C49[/"Look Up Product Data"/]
C50[/"Add Product To Inventory"/]
C51[/"Update Product Level"/]
C52[/"Mark Product Empty"/]
C53[/"Add Product To Shopping List"/]
C29[/"Recalculate Shopping Quantities"/]
%% Bar Setup Commands
C7[/"Prepare Bar Setup"/]
C8[/"Create Batched Cocktails"/]
C9[/"Serve Drinks"/]
C10[/"Collect Guest Feedback"/]
%% Recipe Commands
C12[/"Create Recipe"/]
C13[/"Update Recipe"/]
C14[/"Rate Recipe"/]
C15[/"Tag Recipe"/]
C16[/"Search Recipes"/]
C38[/"Define Flavor Profile"/]
C39[/"Add Ingredient Profile"/]
C40[/"Update Ingredient Profile"/]
C41[/"Calculate Recipe Balance"/]
C42[/"Suggest Balancing Ingredients"/]
C43[/"Filter By Flavor Profile"/]
C44[/"Calculate Batch Quantities"/]
C45[/"Scale Recipe"/]
C46[/"Convert Units"/]
C47[/"Save Batch Recipe"/]
%% Tagging System Commands
C18[/"Create Tag"/]
C19[/"Update Tag"/]
C20[/"Apply Tag"/]
C21[/"Remove Tag"/]
C22[/"Search By Tag"/]
%% Equipment Commands
C30[/"Add Bar Tool"/]
C31[/"Update Bar Tool"/]
C32[/"Remove Bar Tool"/]
C33[/"Add Equipment"/]
C34[/"Update Equipment"/]
C35[/"Remove Equipment"/]
C36[/"Link Tools To Recipe"/]
C37[/"Check Tool Availability"/]
%% Venue Management Commands
C54[/"Create Venue"/]
C55[/"Update Venue"/]
C56[/"Add Storage"/]
C57[/"Update Storage"/]
C58[/"Remove Storage"/]
C59[/"Add Bar"/]
C60[/"Update Bar"/]
C61[/"Remove Bar"/]
%% Domain Events
%% Event Planning Events
E1{{EventScheduled}}
E2{{ThemeDefined}}
E23{{GuestListCreated}}
E24{{GuestAdded}}
E25{{GuestRemoved}}
E26{{GuestRSVPUpdated}}
E27{{GuestPreferencesSet}}
E28{{AttendanceEstimateSet}}
%% Menu Events
E3{{MenuCreated}}
E17{{RecipeAddedToMenu}}
E45{{MenuBalanceAnalyzed}}
%% Inventory Events
E4{{InventoryChecked}}
E5{{ShoppingListGenerated}}
E6{{SuppliesPurchased}}
E11{{InventoryUpdated}}
E29{{ShoppingQuantitiesRecalculated}}
E50{{ProductBarcodeScanned}}
E51{{ProductDataRetrieved}}
E52{{ProductAddedToInventory}}
E53{{ProductLevelUpdated}}
E54{{ProductMarkedEmpty}}
E55{{ProductAddedToShoppingList}}
%% Bar Setup Events
E7{{BarSetupCompleted}}
E8{{CocktailsBatched}}
E9{{DrinkServed}}
E10{{FeedbackCollected}}
%% Recipe Events
E12{{RecipeCreated}}
E13{{RecipeUpdated}}
E14{{RecipeRated}}
E15{{RecipeTagged}}
E16{{RecipesSearched}}
E39{{FlavorProfileDefined}}
E40{{IngredientProfileAdded}}
E41{{IngredientProfileUpdated}}
E42{{RecipeBalanceCalculated}}
E43{{BalancingSuggestionsGenerated}}
E44{{RecipesFilteredByProfile}}
E46{{BatchQuantitiesCalculated}}
E47{{RecipeScaled}}
E48{{UnitsConverted}}
E49{{BatchRecipeSaved}}
%% Tagging System Events
E18{{TagCreated}}
E19{{TagUpdated}}
E20{{TagApplied}}
E21{{TagRemoved}}
E22{{ItemsSearchedByTag}}
%% Equipment Events
E30{{BarToolAdded}}
E31{{BarToolUpdated}}
E32{{BarToolRemoved}}
E33{{EquipmentAdded}}
E34{{EquipmentUpdated}}
E35{{EquipmentRemoved}}
E36{{ToolsLinkedToRecipe}}
E37{{ToolAvailabilityChecked}}
E38{{ToolShortageIdentified}}
%% Venue Management Events
E56{{VenueCreated}}
E57{{VenueUpdated}}
E58{{StorageAdded}}
E59{{StorageUpdated}}
E60{{StorageRemoved}}
E61{{BarAdded}}
E62{{BarUpdated}}
E63{{BarRemoved}}
%% Repositories
subgraph Repositories
R1[(EventRepository)]
R2[(MenuRepository)]
R3[(RecipeRepository)]
R4[(TagRepository)]
R5[(InventoryRepository)]
R6[(ShoppingListRepository)]
R7[(BarSetupRepository)]
R8[(GuestRepository)]
R9[(FeedbackRepository)]
R10[(FlavorProfileRepository)]
R11[(EquipmentRepository)]
R12[(BatchRecipeRepository)]
R13[(ProductRepository)]
R14[(VenueRepository)]
end
%% Command flows - Event Planning
C1 --> CH1
CH1 --> R1
CH1 --> R14
CH1 --> E1
C2 --> CH2
CH2 --> R1
CH2 --> E2
C23 --> CH23
CH23 --> R8
CH23 --> E23
C24 --> CH24
CH24 --> R8
CH24 --> E24
C25 --> CH25
CH25 --> R8
CH25 --> E25
C26 --> CH26
CH26 --> R8
CH26 --> E26
C27 --> CH27
CH27 --> R8
CH27 --> E27
C28 --> CH28
CH28 --> R1
CH28 --> E28
%% Command flows - Menu
C3 --> CH3
CH3 --> R1
CH3 --> R2
CH3 --> E3
C17 --> CH17
CH17 --> R2
CH17 --> R3
CH17 --> E17
%% Command flows - Inventory
C4 --> CH4
CH4 --> R5
CH4 --> E4
C5 --> CH5
CH5 --> R5
CH5 --> R6
CH5 --> E5
C6 --> CH6
CH6 --> R6
CH6 --> E6
C11 --> CH11
CH11 --> R5
CH11 --> E11
C29 --> CH29
CH29 --> R6
CH29 --> E29
C48 --> CH48
CH48 --> E50
C49 --> CH49
CH49 --> R13
CH49 --> E51
C50 --> CH50
CH50 --> R5
CH50 --> R13
CH50 --> E52
C51 --> CH51
CH51 --> R5
CH51 --> R13
CH51 --> E53
C52 --> CH52
CH52 --> R5
CH52 --> R13
CH52 --> E54
C53 --> CH53
CH53 --> R6
CH53 --> R13
CH53 --> E55
%% Command flows - Bar Setup
C7 --> CH7
CH7 --> R7
CH7 --> R14
CH7 --> E7
C8 --> CH8
CH8 --> R3
CH8 --> R7
CH8 --> R12
CH8 --> E8
C9 --> CH9
CH9 --> R5
CH9 --> E9
C10 --> CH10
CH10 --> R9
CH10 --> E10
%% Command flows - Recipe
C12 --> CH12
CH12 --> R3
CH12 --> E12
C13 --> CH13
CH13 --> R3
CH13 --> E13
C14 --> CH14
CH14 --> R3
CH14 --> E14
C15 --> CH15
CH15 --> R3
CH15 --> R4
CH15 --> E15
C16 --> CH16
CH16 --> R3
CH16 --> E16
C38 --> CH38
CH38 --> R10
CH38 --> E39
C39 --> CH39
CH39 --> R10
CH39 --> E40
C40 --> CH40
CH40 --> R10
CH40 --> E41
C41 --> CH41
CH41 --> R3
CH41 --> R10
CH41 --> E42
C42 --> CH42
CH42 --> R3
CH42 --> R10
CH42 --> E43
C43 --> CH43
CH43 --> R3
CH43 --> R10
CH43 --> E44
C44 --> CH44
CH44 --> R3
CH44 --> R12
CH44 --> E46
C45 --> CH45
CH45 --> R3
CH45 --> R12
CH45 --> E47
C46 --> CH46
CH46 --> E48
C47 --> CH47
CH47 --> R12
CH47 --> E49
%% Command flows - Tagging System
C18 --> CH18
CH18 --> R4
CH18 --> E18
C19 --> CH19
CH19 --> R4
CH19 --> E19
C20 --> CH20
CH20 --> R4
CH20 --> E20
C21 --> CH21
CH21 --> R4
CH21 --> E21
C22 --> CH22
CH22 --> R4
CH22 --> E22
%% Command flows - Equipment
C30 --> CH30
CH30 --> R11
CH30 --> E30
C31 --> CH31
CH31 --> R11
CH31 --> E31
C32 --> CH32
CH32 --> R11
CH32 --> E32
C33 --> CH33
CH33 --> R11
CH33 --> E33
C34 --> CH34
CH34 --> R11
CH34 --> E34
C35 --> CH35
CH35 --> R11
CH35 --> E35
C36 --> CH36
CH36 --> R3
CH36 --> R11
CH36 --> E36
C37 --> CH37
CH37 --> R11
CH37 --> E37
CH37 -.-> E38
%% Command flows - Venue Management
C54 --> CH54
CH54 --> R14
CH54 --> E56
C55 --> CH55
CH55 --> R14
CH55 --> E57
C56 --> CH56
CH56 --> R14
CH56 --> E58
C57 --> CH57
CH57 --> R14
CH57 --> E59
C58 --> CH58
CH58 --> R14
CH58 --> E60
C59 --> CH59
CH59 --> R14
CH59 --> E61
C60 --> CH60
CH60 --> R14
CH60 --> E62
C61 --> CH61
CH61 --> R14
CH61 --> E63
%% Event triggers based on Policies from Event Storm
%% P1
E1 -.-> C2
%% P2
E2 -.-> C3
%% P3
E3 -.-> C4
%% P4
E4 -.-> C5
%% P5
E6 -.-> C11
%% P6
E3 -.-> C7
%% P7
E7 -.-> C8
%% P8
E2 -.-> C16
%% P9
E17 -.-> C4
%% P10
E1 -.-> C20
%% P11
E12 -.-> C20
%% P12
E1 -.-> C23
%% P13, P16
E24 -.-> C28
E25 -.-> C28
E26 -.-> C28
%% P14
E28 -.-> C29
%% P15
E27 -.-> C17
%% P17
E3 -.-> C37
%% P18
E17 -.-> C36
%% P19
E38 -.-> C5
%% P20
E7 -.-> C37
%% P21
E40 -.-> C41
%% P22
E12 -.-> C41
%% P23
E42 -.-> C42
%% P24
E3 -.-> C41
%% P25
E27 -.-> C43
%% P26
E28 -.-> C44
%% P27
E47 -.-> C46
%% P28
E8 -.-> C44
%% P29
E50 -.-> C49
%% P30
E51 -.-> C50
%% P31
E54 -.-> C53
%% P32
E53 -.-> C53
%% Styles
classDef command fill:#5D9CEC,stroke:#333,stroke-width:1px;
classDef event fill:#FF9900,stroke:#333,stroke-width:1px;
classDef handler fill:#4CAF50,stroke:#333,stroke-width:1px;
classDef repository fill:#9C27B0,stroke:#333,stroke-width:1px,color:#fff;
%% Apply styles to all nodes
%% Event Planning
class C1,C2,C23,C24,C25,C26,C27,C28 command;
class E1,E2,E23,E24,E25,E26,E27,E28 event;
class CH1,CH2,CH23,CH24,CH25,CH26,CH27,CH28 handler;
%% Menu
class C3,C17 command;
class E3,E17,E45 event;
class CH3,CH17 handler;
%% Inventory
class C4,C5,C6,C11,C29,C48,C49,C50,C51,C52,C53 command;
class E4,E5,E6,E11,E29,E50,E51,E52,E53,E54,E55 event;
class CH4,CH5,CH6,CH11,CH29,CH48,CH49,CH50,CH51,CH52,CH53 handler;
%% Bar Setup
class C7,C8,C9,C10 command;
class E7,E8,E9,E10 event;
class CH7,CH8,CH9,CH10 handler;
%% Recipe
class C12,C13,C14,C15,C16,C38,C39,C40,C41,C42,C43,C44,C45,C46,C47 command;
class E12,E13,E14,E15,E16,E39,E40,E41,E42,E43,E44,E46,E47,E48,E49 event;
class CH12,CH13,CH14,CH15,CH16,CH38,CH39,CH40,CH41,CH42,CH43,CH44,CH45,CH46,CH47 handler;
%% Tagging System
class C18,C19,C20,C21,C22 command;
class E18,E19,E20,E21,E22 event;
class CH18,CH19,CH20,CH21,CH22 handler;
%% Equipment
class C30,C31,C32,C33,C34,C35,C36,C37 command;
class E30,E31,E32,E33,E34,E35,E36,E37,E38 event;
class CH30,CH31,CH32,CH33,CH34,CH35,CH36,CH37 handler;
%% Venue Management
class C54,C55,C56,C57,C58,C59,C60,C61 command;
class E56,E57,E58,E59,E60,E61,E62,E63 event;
class CH54,CH55,CH56,CH57,CH58,CH59,CH60,CH61 handler;
%% Repositories
class R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14 repository;
%% Legend
subgraph Legend
L1[/"Command"/]:::command
L2{{Domain Event}}:::event
L3[Command Handler]:::handler
L4[(Repository)]:::repository
L5-- Direct Flow -->L6
L7-. Event Trigger .->L8
end
Key Components
Section titled “Key Components”Command Handlers
Section titled “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
- AddBarHandler: Handles adding bars to venues
- UpdateBarHandler: Handles updating bar details
- RemoveBarHandler: Handles removing bars from venues
Commands
Section titled “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
- Add Bar: Add a new bar to a venue
- Update Bar: Modify bar details and features
- Remove Bar: Remove a bar from a venue
Domain Events
Section titled “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
- BarAdded: A bar has been added to a venue
- BarUpdated: A bar’s details have been updated
- BarRemoved: A bar has been removed from a venue
Repositories
Section titled “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
- VenueRepository: Stores venue data including bars and storage areas
Event Triggers
Section titled “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
Section titled “Main Workflows”The Command Flow diagram shows several key workflows:
Event Planning Workflow
Section titled “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
Section titled “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
Section titled “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
Bar Management Workflow
Section titled “Bar Management Workflow”- Add Bar command is processed by AddBarHandler
- AddBarHandler validates the bar data and venue existence
- AddBarHandler persists the new bar to VenueRepository
- BarAdded event is generated
- Update Bar and Remove Bar commands follow similar patterns through their respective handlers
- All bar management operations are scoped within the Venue Aggregate boundary
Benefits of Command Flow Modeling
Section titled “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.