Skip to main content

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:

  1. Validates the command
  2. Retrieves data from repositories
  3. Performs business logic
  4. Persists changes to repositories
  5. 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

  1. Schedule Event command is processed by ScheduleEventHandler
  2. EventScheduled event is generated
  3. This triggers the Define Event Theme command
  4. DefineEventThemeHandler processes the command
  5. ThemeDefined event is generated
  6. This triggers the Create Menu command

Inventory Management Workflow

  1. MenuCreated event triggers Check Inventory command
  2. CheckInventoryHandler processes the command
  3. InventoryChecked event is generated
  4. This triggers Generate Shopping List command
  5. ShoppingListGenerated event is produced
  6. When supplies are purchased, Update Inventory is triggered

Recipe Management Workflow

  1. Create Recipe command is processed by CreateRecipeHandler
  2. RecipeCreated event is generated
  3. This triggers Calculate Recipe Balance command
  4. RecipeBalanceCalculated event is generated
  5. If the recipe is unbalanced, it triggers Suggest Balancing Ingredients

Benefits of Command Flow Modeling

The Command Flow diagram provides several benefits:

  1. Clear Implementation Path: Provides a clear path for implementing the system
  2. Separation of Concerns: Clearly separates commands, events, and repositories
  3. Event-Driven Architecture: Shows how events trigger subsequent commands
  4. Traceability: Makes it easy to trace how a user action flows through the system
  5. 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.