question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prerequisites

  • 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:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:7

github_iconTop GitHub Comments

14reactions
demisxcommented, Jun 18, 2020

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.

1reaction
FrozenPandazcommented, May 29, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Libraries - CLI | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines ...
Read more >
sclable/nestjs-libs: Libraries for NestJS - GitHub
NestJS Library Collection. This monolithic repository provides essential packages for developing NestJS based applications.
Read more >
NestJS Create Reusable/Publishable Library - Stack Overflow
I want to create a Nest.js Package, so I can reuse a controller in multiple Nest.js projects. I have checked out library but...
Read more >
Create a library for a NestJS API in a Nx Workspace
In this lesson we use the @nrwl/nest plugin to create a new library called core. This is done by running the lib schematic...
Read more >
@scandinavia/nestjs-libs - npm
NestJS Utilities. Latest version: 1.9.86, last published: 14 days ago. Start using @scandinavia/nestjs-libs in your project by running `npm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found