nestjs / docs.nestjs.com

The official documentation https://docs.nestjs.com 📕
MIT License
1.2k stars 1.74k forks source link

Clean architecture and DDD examples #400

Open lughino opened 5 years ago

lughino commented 5 years ago

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

NestJS is a really good framework designed with a module architecture.

Expected behavior

Would be really nice to have some official examples of how to design a nest application with clean and DDD design architecture.

What is the motivation / use case for changing the behavior?

Use those patterns allow us to write applications with "standard" design in mind. E.g. promoting the reuse of the layers when using different transport at the same time.

Sumick commented 5 years ago

Something like that? Not official but still matches the pattern -> https://github.com/juangonzaq/nestjs-ddd/tree/master/src

lughino commented 5 years ago

@Sumick yes, for the DDD looks like a good example. Looking for a Clean architecture one.

jcorkhill commented 5 years ago

@Lughino @Sumick

As far as DDD with TypeORM, that example repo you provided appears to be using the decorated entities from TypeORM, which are a one-to-one mapping to the database table, as domain models and thus making them a domain layer concern, not an infrastructure one. Any thoughts on using TypeORM with a data mapper, to map between Domain Models and Database Entities?

Thanks.

adico1 commented 4 years ago

I'm trying to incorporate clean architecture into nest, right now trying to figure out the relatiionship between the NestJs controller and the clean architecture "view".

"return" is not an option, trying to figure how to "return" from the view back to the router from the presenter which acts as a callback.

@Get()
    public async getAllAccounts(): Promise<Account[]> {
        const validator = new GetAllAccountsRequestMessageValidator();
        const presenter = new GetAllAccountsResponsePresenter();
        const repository = Factory.createDummyInMemoryAccountRepository();
        const interactor = new GetAllAccountsInteractor(validator, repository);
        const controller = new AccountLogicController(interactor, presenter);

        **return** await controller.getAll(new GetAllAccountsRequestMessage());
    } 

when I'll have a full example I'll be happy to post it here

adico1 commented 4 years ago

i created a repository with my "Production Ready" clean architecture NestJS based clean architecture.

Hope you'll enjoy it - I did.

https://github.com/adico1/clean-on-nest

1) it requires PostgresSQL locally installed 2) npm install

Seed DB and Run Test 3) npm run start:dev:db:seed && npm run test:e2e

Start in Dev mode 4) npm run "start:dev"

Sikora00 commented 4 years ago

Check also this one :) https://medium.com/@maciejsikorski/onion-architecture-with-nest-js-and-nx-d9b5c7126b37 https://github.com/Sikora00/nest-nx-onion