I have an app showing us…

1 minute read

I have an app showing users then I have created a lib for the usersService. The service contains the model for User but now I would like to use the User model in another lib/service.. Should I just duplicate the model? (would prefer not to).. the second lib/service has no dependency on the UsersService..

Responses:

I guess either depend on a shared lib (like data ) that exposes all of your models, or what I tend to do is have some similar objects like UiUser where I duplicate only the properties I need , so only things like name, username, avatarUrl.

hmm.. so a lib just for the models.. could be an idea..

but then that lib might become rather messy over time :stuck_out_tongue:

Discipline is always hard :grin:

it is

It all really depends on the bigger picture.

I really like having one shared data library that not only defines my models, but is also responsible for actually handling all my data access

So all my feature libs depend on the data lib to do anything wrt data

We create type libs where needed

we used to put models with our data, but then you cannot use them in UI modules (dumb components) because of the nx-module-boundaries

we do the same like Jay now, create a type lib, which can be used by feature/data/ui libs

Make sure to scope the type libs correctly too! Otherwise your dep graphs gets reallllly messy (like ours is right now)

and when you say scope you mean?

in NX.json you can add tags to your project. NX suggests adding scope and type The combination of both is what’s used for the module boundaries

https://nx.dev/angular/workspace/structure/monorepo-tags

hmm.. so like scope: shared would be added to all libs more or less..?

Updated: