> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# CQRS: decisions and views

Command Query Responsibility Segregation separates the model used to change
state from the model used to read it. A command expresses intent; a query asks for
information. Separate models can share one database and one process.

## Commands express business tasks

`ObserveExternalProject` applies a prepared, qualified source observation. Its
handler checks the target, admission, source ownership and expected version before
calling Project behaviour. A material change saves the root. An unchanged complete
read records source-success evidence while preserving the material revision.

Read the <a href="/source/services/beto/contexts/project/application/commands/observe_external_project.go.txt">command</a>.
A stable command identity and unchanged material input recover a recorded outcome
on retry. A new business attempt receives a new command identity.

## Queries return useful representations

`GetProjectIntegrationSnapshot` returns canonical Project state and source status.
It uses a read repository and explicit authorisation. Its freshness calculation
belongs to the query's contract.

<a href="/source/services/beto/contexts/project/application/queries/get_project_integration_snapshot.go.txt">Source: get_project_integration_snapshot.go</a>

```go
type GetProjectIntegrationSnapshotQueryHandler struct {
	Authoriser ports.Authoriser
	Repository ports.ProjectIntegrationReadRepository
	Clock      foundation.Clock
	Freshness  time.Duration
}
```

Read the <a href="/source/services/beto/contexts/project/application/queries/get_project_integration_snapshot.go.txt">query implementation</a>
and [published boundary](/reference/contracts/project/messaging/README.md).
Queries preserve revisions, missing-resource behaviour and complete or explicitly
paginated results. Silent truncation can change an access decision.

## Views, projections and freshness

A read model answers a question. A projection maintains a representation from
source information, often asynchronously. Each consumer owns its local view and
its recovery policy. An event's arrival alone cannot establish that every related
projection is current.

Project has separate material-state and authority revision streams. An unchanged
source read can renew authority without changing the aggregate's material state.
Consumers must retain the source's validity and ordering semantics. Read the owner
contract before combining streams into a local access decision.

Browser delivery uses server-authorised Centrifugo subscriptions and typed Protobuf
projections. Queries reconcile state after gaps; revision checks prevent delayed
responses replacing newer data. [CLIENT-SUBSCRIPTIONS.md](/reference/CLIENT-SUBSCRIPTIONS.md)
defines the platform rules.

CQRS adds representations and mappings. Use the separation where it clarifies
business decisions, read needs or recovery. It does not require separate databases
or an event-sourced aggregate.

Next: [Event-driven architecture](/learn/event-driven-architecture.md).

Adapted from the [architecture reference](/learn/attribution.md), with Pharos examples.

<details class="page-source"><summary>Page source</summary>

<a href="/source/docs/content/learn/cqrs.md.txt">Source snapshot</a> · Revision `f928834c8`.

</details>
