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.jsonat the root andnxindevDependenciesproject.jsonfiles in project foldersapps/andlibs/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-accessandutil. - 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
nx.jsonand its pluginstsconfig.base.jsonpaths, to map imports to folders- Module-boundary rules in the ESLint config
How a request moves through the code
- Nx builds a project graph from imports and project config.
nx run app:buildruns the target and its dependencies' targets.- Results are cached locally or remotely by input hash.
nx affectedruns 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; runnx show project <name>to see them. - Path aliases make imports look like npm packages even though they're local folders.