Nx library types; 4 is enough

Build enterprise applications Nx time faster in smaller categorized chunks.

There could be different ways to deliver enterprise applications. Every approach would have pros & cons associated with it. We would definitely need to be able to see a big working thing in separated chunks. This allows us to assign those chunks to team members, deliver in parallel, get ownership, etc. What’s the best way to slice this pizza? How to define boundaries?

After a few projects, meetings on best practices, facing real results, one could come up with his/her own way of building & separating concerns.

Nx did that. This system provides default opinions on separating concerns, testing, linting (and much more) to deliver projects with confidence. It also provides flexibility to make your own alterations if needed. And these are production tested opinions of a talented team led by 2 ex-Googlers actively listening and interacting with the dev community.

Let’s look into how to separate concerns in our codebase.

Nx provides monorepo to organize code. Organize & scale like Google, Meta, Twitter, Uber & Airbnb with their team sizes, volume of daily contributions, and variety of frameworks & tools used to deliver.

monorepo has projects: applications & libraries.

application is a container to bundle & compile libraries for further deployment. The less code goes in here, the better. Heavy lifting is done by code in libraries.

Nx suggests 4 types of libraries: feature, ui, data-access, util. These are defaults. How much value in these defaults💰! Most of front-end code we write should fall into 1 of these library types. Yes, you can come up with additional library types. (However, thoughts can often lose clarity when entities multiply. Brevity is the soul of wit 🙂)

So anytime we need to design our front-end app, we could come up with the necessary number of libraries. Having 4 types of libs in mind, allows us to slice this pizza faster & assign libraries across the dev team. Work in parallel, track progress easier & come up with better delivery estimates.

library types are defined by tags. They are the source for Nx to build our project graph. Project graph is going to throw errors if circular dependency is found or other dependencies do not make sense. Another boost of confidence while adding to our codebase. We are going to talk about project graph in the next post…