Skip to content

How to understand a Nx monorepo codebase

Nx manages large monorepos with a project graph, task running and caching. Projects declare targets in `project.json` or have them inferred by plugins from config files. Tags and lint rules often encode the architecture: which libraries may depend on which.

How to tell it's Nx monorepo

  • nx.json at the root and nx in devDependencies
  • project.json files in project folders
  • apps/ and libs/ folders, and @nx/* plugins

Where things usually live

nx.json
Plugins, target defaults, caching, named inputs.
apps/*
Applications.
libs/*
Libraries, often split by type such as feature, ui, data-access and util.
project.json
Per-project targets, tags and options.
tsconfig.base.json
Path aliases mapping library names to folders.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. nx.json and its plugins
  2. tsconfig.base.json paths, to map imports to folders
  3. Module-boundary rules in the ESLint config

How a request moves through the code

  1. 1Nx builds a project graph from imports and project config.
  2. 2nx run app:build runs the target and its dependencies' targets.
  3. 3Results are cached locally or remotely by input hash.
  4. 4nx affected runs tasks only for projects touched by a change.

Questions to ask about the repository

  • Which libraries does this app depend on, directly and indirectly?
  • What do the project tags mean, and which dependencies do the rules forbid?
  • Which targets are inferred by plugins rather than declared?

What trips people up

  • Inferred targets don't appear in project.json; run nx show project <name> to see them.
  • Path aliases make imports look like npm packages even though they're local folders.