# CQRS Handlers Reference {#cqrs-handlers-reference}


Command Query Responsibility Segregation patterns in Ever Gauzy.


## Overview {#overview}


Gauzy uses NestJS CQRS (`@nestjs/cqrs`) to separate write operations (commands) from read operations (queries). This provides:

- Clear separation of concerns
- Easy testing of business logic
- Event-driven side effects


## Command Pattern {#command-pattern}



### Defining a Command {#defining-a-command}


```typescript
export class CreateOrganizationSprintCommand implements ICommand {
  constructor(public readonly input: IOrganizationSprintCreateInput) {}
}
```


### Handling a Command {#handling-a-command}


```typescript
@CommandHandler(CreateOrganizationSprintCommand)
export class CreateOrganizationSprintHandler implements ICommandHandler<CreateOrganizationSprintCommand> {
  constructor(private readonly sprintService: OrganizationSprintService) {}

  async execute(command: CreateOrganizationSprintCommand) {
    const { input } = command;
    return await this.sprintService.create(input);
  }
}
```


### Dispatching a Command {#dispatching-a-command}


```typescript
@Post('/')
async create(@Body() entity: CreateSprintDTO) {
  return await this.commandBus.execute(
    new CreateOrganizationSprintCommand(entity)
  );
}
```


## Command Flow {#command-flow}






```mermaid
sequenceDiagram
    Controller->>CommandBus: execute(Command)
    CommandBus->>CommandHandler: handle(Command)
    CommandHandler->>Service: business logic
    Service->>Repository: database operation
    Repository-->>Service: result
    Service-->>CommandHandler: result
    CommandHandler-->>Controller: result
```






## Common Patterns {#common-patterns}


| Pattern                 | Description                       |
| ----------------------- | --------------------------------- |
| Create commands         | Entity creation with side effects |
| Update commands         | Entity updates with validation    |
| Composite commands      | Multi-step operations             |
| Event-emitting commands | Trigger events after execution    |


## Related Pages {#related-pages}


- [Plugin Development Guide](https://sourcey-gauzy.pages.dev/plugins-built-in/plugin-development-guide/index.md) — creating plugins with CQRS
- [Architecture Overview](https://sourcey-gauzy.pages.dev/architecture/overview/index.md) — system architecture
