Andrew's Digital Garden

NX Mental Model

NX generates and uses a project graph - a reflection of the code in your NX repository. The graph reflects dependencies between projects (apps and libs), and creates a graph through code analysis, configuration, etc.

This project graph is used for both tasks commands, and 'affected' commands.

Executing a task, e.g. nx test lib1 generates a task graph based on the project graph. When running a task in NX, it will run the requested task, and any tasks it depends on. NX aims to execute in the most efficient order. If things can be run parallel, it will be. This lets your build an app without having to manually build to dependent libs first.

As the repository grows, using nx affected becomes more powerful. NX analyses files/apps/libs that have changed in your branch/PR. Then, you can run tasks based on projects that have changed (and their dependent projects). This saves a chunk of time, as you don't need to run a task for all projects.

All of these tools are more reasons to create independent, small apps and libraries. These projects can then be composed together in the most efficient manner possible, building/testing/running only what needs to be.

[[20220905121648-nx-cloud]] [[20221014051039-nx-apps-and-libs]]

https://nx.dev/concepts/mental-model

[[architecture]] [[nx]]

NX Mental Model