finds.dev← search

// the find

kamilmysliwiec/nest-cqrs-example

★ 545 · TypeScript · updated Jun 2023

The example usage of Nest CQRS module

A small Nest.js example app that shows how to wire the @nestjs/cqrs module into a feature module. It has a single heroes domain with commands, queries, events, and a saga, backed by an in-memory fixture repository. It is aimed at developers who are new to CQRS in Nest and want a concrete layout to copy from.

- Each feature folder splits commands, queries, events, and sagas into their own directories with an index.ts barrel per handler set. That keeps the read and write sides visibly separate, which is the thing most CQRS examples blur.

- The sagas file shows how to react to events and dispatch follow-up commands, which is the part of the module most people get wrong first. It is a useful reference for that wiring even though the domain is trivial.

- The example is short enough to read in one sitting. There is no framework scaffolding to wade through, so the CQRS wiring in heroes.module.ts is easy to follow.

- The last push was June 2023. Check which @nestjs/cqrs and Nest versions it pins against your own project before copying anything, because the API has moved since then.

- The repository is an in-memory fixture (repository/fixtures/user.ts). It shows nothing about transactions, persistence, or how to keep event handlers idempotent when a write partly fails.

- The README is only install and start instructions. It does not explain the command, query, and event flow, so the code has to carry the whole lesson. No tests appear in the visible tree, so there is no executable spec of the behaviour either.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →