Savory/Danet

Reconsider if you really want to mimic NestJS

MickL opened this issue · 3 comments

MickL commented

As you are apparently considering a V2 I wanted to make some suggestions with the question: Do you really want to rebuild NestJS?

I am asking because the dependency injection and the modules can make the life of a developer hard and frustrating (thinking of import/export of services, useFactory, circular dependencies). Also NestJS takes 81 ms to start an empty Express app while "plain" Express takes 7 ms and is therefor not usable for serverless functions.

Looking back into Angular (the inspiration of NestJS) it is not needed anymore to register a class that has the @Injectable() decorator. Instead it "just works" and is even tree shaked if it is not used anywhere. Also a thing that Angular did is the remove of modules: Standalone apps dont need modules anymore (but can still import modules for compatibility), components (in our case controllers) import whatever they need in their @Component() decorator and Angular does the magic of putting it all together and tree shaking what is not used.

I just wanted to add this things to consider, you might close this issue :)

P.S. What about another name as well? I am not native english and this name "Danet" is really hard to remember, especially compared to something fresh like "fresh" or even the dead project "mandarine".

Hey @MickL !

First, thanks for taking the time to give such feedback!

The Angular example looks good, but it's missing something very important in my opinion. Even if modules are not useful anymore, Angular uses routers, so all components you want to use will be declared there, that's how Angular knows they are being used.
If we wanted to do standalone controllers, we would still need a file to declare them all so they are registered, which would ultimately be a module but named differently.
To remove the need for a file to declare these, we could rely on the files' name, like, looking for all controller.ts files (or any naming developers choose). That could be a very good DX.

I think that removing modules completely will penalize developers willing to do Clean/Hexa/etc architecture with abstraction for adapters and ports. Depending on interfaces and injecting the needed implementation at runtime with TokenInjector.
Doing it at a @Controller level or @Injectable level would mean changing the used implementation in each consumer, which does not scale.
We should be able to say that the token UserRepository is MongoDbUserRepository in the whole app. I, for now, do not see how to do that without an "equivalent to module" file.

However, removing boilerplate for simpler use-cases sounds good. Definitely something to think about.

MickL commented

No module does not mean there is no declaration file. In fact there is a main.ts in which global stuff is initialized and modules provide a importProvidersFrom() function:

bootstrapApplication(PhotoAppComponent, {
  providers: [
    importProvidersFrom(NgModuleOne, NgModuleTwo)
  ]
});

I kinda like the idea to declare route-files. This would for sure speedup cold start time because Nest first needs to find all controllers and maybe even lazy-loading parts that are not used in a serverless function call.

P.S. What about another name as well? I am not native english and this name "Danet" is really hard to remember, especially compared to something fresh like "fresh" or even the dead project "mandarine".

I'm not a native english speaker but I don't find "Danet" hard to remember.