πŸ“‚App

Command & Query Central

In the heart of The Cillop Architecture lies the app directory. This pivotal directory encapsulates the application's core business logic, segregating it into distinct command and query actions. By organizing our logic in this fashion, we promote clarity, scalability, and maintainability, allowing developers to understand and extend functionalities with ease.

Command: The Action Takers

Commands in software architecture are actions or functions that change the state of an application. They encapsulate the logic for creating, updating, or deleting entities, ensuring that the business rules and validations are adhered to.

In the app/command directory, you will find various command handlers that define and execute these state-changing operations. Each command is a reflection of a business action, and its sole responsibility is to ensure that the action adheres to the business's rules and expectations.

Typical Use Cases:

  • Creating a new product.

  • Updating user profiles.

  • Processing payment transactions.

Query: The State Readers

Contrary to commands, queries are actions that fetch or read the state of an application without altering it. They allow the application to retrieve and display data, ensuring it's in the right format and adheres to any necessary filtering or sorting rules.

The app/query directory is where these data retrieval handlers reside. Each query handler focuses on fetching data in response to specific user requests or system needs. They ensure the data is sourced correctly, transformed if necessary, and delivered efficiently to the requesting component.

Typical Use Cases:

  • Fetching a list of products for display.

  • Retrieving user data for profile views.

  • Checking order history for a customer.

Why Separate Command and Query?

The distinction between command and query isn't just for organizational clarityβ€”it stems from the Command Query Responsibility Segregation (CQRS) principle. By separating the write actions (commands) from the read actions (queries), we:

  • Enhance scalability by allowing independent scaling of read-heavy and write-heavy components.

  • Improve maintainability by segregating logic and reducing complexity.

  • Boost performance by optimizing the respective handlers for their specific roles.

Last updated