Skip to content

Repository files navigation

CQRS Command Flow Analyzer

A lightweight command-line tool that analyzes CQRS command relationships within a .NET solution using the Roslyn compiler API.


🔍 Purpose

In complex enterprise systems, especially those following the CQRS + MediatR pattern, it’s often difficult to see how commands interact with each other.
For example, executing one command may trigger several others — directly or indirectly — but these dependencies are hidden inside handler logic.

CQRS Flow Analyzer solves this by automatically detecting and visualizing these command invocation chains.

This allows you to:

  • Quickly understand what other commands are triggered when a specific command runs.
  • Identify side effects and dependencies before modifying an existing command.
  • Speed up onboarding when joining a new or unfamiliar project.
  • Improve confidence in code changes by seeing the impact scope visually.

⚙️ How It Works

The analyzer:

  1. Loads a .sln file using MSBuildWorkspace.
  2. Scans all projects for classes implementing
    IRequestHandler<TRequest, TResponse> (via Roslyn syntax trees).
  3. Finds all usages of mediator.Send(new SomeCommand(...)) inside handler methods.
  4. Builds a recursive tree of command-to-command relationships.
  5. Displays the result in a colored tree view in the console and
    exports it to a .txt file for documentation.

🧩 Example Output

Console

CQRS Command Flow
├── SubmitOrderCommand
│   ├── ValidateOrderCommand
│   │   └── NotifyWarehouseCommand
│   ├── ChargePaymentCommand
│   │   └── SendInvoiceCommand
│   └── UpdateInventoryCommand
│       └── NotifySupplierCommand
└── CancelOrderCommand
    ├── RefundPaymentCommand
    └── ReleaseInventoryCommand
        └── NotifyCustomerCommand

🧠 Key Benefits

  • Architectural Clarity – Understand your CQRS command flow at a glance.
  • Onboarding Efficiency – New developers can learn system behavior quickly.
  • Impact Analysis – Before refactoring or deleting a command, check what depends on it.
  • Documentation Aid – Auto-generates readable command trees for Confluence or code reviews.

🚀 Usage

cfa "path-to-solution.sln"

About

CLI tool to explore CQRS command chains in .NET solutions. Helps developers see what commands call others — instantly.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages