kamilmysliwiec / nest-cqrs-example Goto Github PK
View Code? Open in Web Editor NEWThe example usage of Nest CQRS module
Home Page: https://nestjs.com
The example usage of Nest CQRS module
Home Page: https://nestjs.com
Since events, commands and models related to the business logic are part of the domain layer, they should remain framework-agnostic, but most tools in this plugin are decorators that you apply to directly in the domain layer or classes that you need to extend. What would be the best approach to separate the domain layer and move the plugin's mechanics to the application/infrastructure layer?
CQRS (but not necessarily CQS) typically implies that you maintain a completely separate domain model for your Command side and your Query side.
With that in mind, this example seems to be leading people astray and doesn't really communicate the essence of CQRS.
Reason being, the command handlers and the query handlers in this example repo are both using the same domain model.
I would love to see this example repo updated to give a more realistic depiction of how to utilize CQRS and DDD patterns. I understand that this was put together primarily for giving a brief conference talk, but I think there's really a missed opportunity for education here.
As it stands now, Nest's attempt to steer people towards CQRS/DDD/reactive patterns seems to just cause confusion and raise more questions than it actually answers. Which is a shame, because Nest really seems primed to be a leader in this space.
Is it possible to use nest-cqrs but with Kafka for an event bus? Whats your opinion and at high level which pieces of code would I need to work with, for ex - https://github.com/nestjs/cqrs/blob/master/src/event-bus.ts, and?
Thanks!
Very nice sample and very nice, neat and consice cqrs implementation !
In the sample it is suggested that still controller - service pipeline is useful.
I think that the whole idea of cqrs is among others, to give the aggregate root a more central place in favor of attached services.
I would simply call directly the command from the controller and remove the service.
Hi,
Thanks for providing such a starting point, this sample is a good starting point for cqrs implementation w/ nestjs.
However it covers only the "read side" of the pattern (repository findone
). It is not clear to me as to where one should plugin the "write side". My understanding is that the aggregate root does all the logic, modifying the model and raises relevant events to notify subscribers. The persistence can then be triggered in either the command (just after the invocation of the root aggregate method) or in dedicated event handlers.
The drawback I see with the event handler is that the command returns before persistence is ran and therefore can lead to consistency issues. The drawback I see with invoking persistence from command is that it is not very SOLID.
What would be your opinion on this?
Rgds
Can someone add logic to command handler, event handler and model ?
Hi, exploring your framework.
Do you have a pointer to a client-side example, ie: querying and sending commands from the client?
Thanks
First off, awesome repo!
One thing I would like to see is how you handle more aggregate roots?
Do they each get their own folder like hero?
CQRS exposes 3 decorators and 3 interfaces. All of them are singular form, except one:
CommandHandler
ICommandHandler
QueryHandler
IQueryHandler
EventsHandler
IEventHandler
I think it should be EventHandler
Maybe you can change this during next breaking change release
I have downloaded this example, when I try to start the application with npm start I get the following error
Error: Package exports for ...\node_modules\@nestjs\common\node_modules\uuid' do not define a '.' subpath
at resolveExports (internal/modules/cjs/loader.js:419:17)
at Function.Module._findPath (internal/modules/cjs/loader.js:492:20)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:787:27)
at Function.Module._load (internal/modules/cjs/loader.js:693:27)
at Module.require (internal/modules/cjs/loader.js:864:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (...\node_modules\@nestjs\common\decorators\core\injectable.decorator.js:3:16)
at Module._compile (internal/modules/cjs/loader.js:971:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
at Module.load (internal/modules/cjs/loader.js:822:32) {
OS: Windows 10
Node 13.0.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.