Libs and NestJs
See original GitHub issuePrerequisites
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
- I’m reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)
Please note that this is not an issue, but rather some questions on best-practice when developing a full-stack application with nrwl/nx
.
First of all, i would like to thank you for this awesome package - i really (!) really like the approach and the code-base.
As i would like to use nrwl/nx
for my upcoming project, i was more than happy to see that you added nestjs
as backend framework 👍 As i am currently mainly focussing on the backend side, these questions refer to explicitly to the combination nrwl/nx + nestjs
I once read an article from @vsavkin , where he said that apps
should only be some kind of “empty shells” that bundle libs
together. Keeping this in mind, i thought it would be a good idea to start right away and create a lot of libs.
In this context, i used the following command to bootstrap new / empty libs:
ng g @nrwl/workspace:lib NAME
# when it asked about the folder to create the lib, i entered "api" to get the proper folder structure i want!
For example, i created a libs/api/account
that manages the accounts, i added an libs/api/auth
that manages everything related to authentication with various providers (e.g., google, jwt, oauth, …), and a lib/api/profile
to store user-profiles (i.e., an account has one profile assigned, one profile belongs to one account: there is a @OneToOne()
relationship between those models).
When i developed the account.entity.ts
and profile.entity.ts
models (remember, both are in separate packages), i quickly ran into Circular Dependency Warnings, because the Account
requires the Profile
and vice versa).
Going further, i have an CurrentUser
decorator that resolves the currently logged in user (via JWT tokens, for example). This decorator, in turn, returns the logged in Account
. This decorator, however, is then used in the libs/api/account
module in order to protect some specific routes - so there is another circular dependency.
Finally, if you go deeper, there may be another use-case where you have a circular dependency with
User > Article > Comment > User
Is there something fundamentally wrong with this appoach? I.e., should i use libs
for such features? Or should those “modules” (with controllers, dtos, entitites, models, …) all be moved to the apps/
folder. And libs/
are more for angular applications?
I am really struggling with these questions, because actually there is no “real world example” for this setup. Maybe the nrwl/nw
team or community can provide a sophisticated example?
I am aware of the https://github.com/xmlking/ngx-starter-kit
starter repository - however, the author puts everything that is related to the API into the apps/api
folder…
All the best and thank you so much for your help!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:16
- Comments:7
I’m surprised how little info there is on structuring a backend API project in Nx. I see many questions to go unanswered. The examples are very trivial at best. This is very frustrating.
Hi, sorry about this.
This was mislabeled as stale. We are testing ways to mark not reproducible issues as stale so that we can focus on actionable items but our initial experiment was too broad and unintentionally labeled this issue as stale.