# CQRS

In a nut shell, with CQRS you have Commands that will change the state of your application and Queries that will return information about the state of your application.

### Installation

```shell
composer require sonsofphp/cqrs-contract
```

### Messages

Both Commands and Queries are considered Messages and are handled by Message Handlers.

### Message Handlers

When a message is dispatched/handled, it is handled by a message handler.

### Message Bus

The Message Bus is given a Message and will use a Message Handler to handle the message. If it's a Query Message, the bus will return a result and for Command Messages, it will not return anything.

### Message Handler Provider

Returns the Handler that will handle the Message. They do not actually handle or process the message.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonsofphp.com/contracts/cqrs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
