Nx is a VSCode of build tools — a powerful core driven by metadata and extensible through plugins. Everything Nx does flows from a small set of interconnected concepts: project graphs, task graphs, affected commands, computation hashing, and caching.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nrwl/nx/llms.txt
Use this file to discover all available pages before exploring further.
The three levels of an Nx workspace
Workspace
The root of your repository. Contains
nx.json, one or more projects, and shared configuration.Projects
Individual applications or libraries detected by
package.json or project.json files. Each project has named targets (tasks) that Nx can run.Tasks
An invocation of a target on a specific project. Running
nx build myapp creates a single myapp:build task.The project graph
Nx analyzes your file system to build a project graph — a directed acyclic graph where nodes are projects and edges are dependencies between them.package.json or project.json files. It then infers dependencies by:
- Statically analyzing TypeScript/JavaScript
importstatements - Reading installed
node_modulesversions - Respecting manually declared
implicitDependenciesin project configuration - Using plugin-provided dependency detection logic
Metadata-driven
Everything in Nx comes with metadata that enables toolability. Nx gathers information about your projects and tasks and uses that information to help you understand and interact with your codebase. With the right plugins installed, most of this metadata can be inferred directly from your existing configuration files — no manual definition required. This metadata powers:- The Nx CLI itself
- VSCode and WebStorm integrations via Nx Console
- GitHub PR integration
- Third-party tools built on top of Nx
The task graph
Nx uses the project graph to construct a task graph for every command you run. The task graph and the project graph are related but not isomorphic — task dependencies are determined by target configuration, not purely by project dependencies. For example, runningnx test lib produces a task graph with a single node:
nx run-many -t test -p app1 app2 lib produces a task graph with three nodes that can run in parallel, because testing app1 does not depend on testing lib by default:
test target that declares it depends on ^test (test of all dependencies):
apps/app1/project.json
lib:test must complete before app1:test and app2:test can start:
Affected commands
As your workspace grows, running every task in the repository on every CI run becomes too slow. Nx solves this with theaffected command, which performs code-change analysis to compute the minimum set of projects that could be impacted by your changes.
When you run nx affected -t test, Nx:
- Looks at the files changed in your PR (compared to the base branch)
- Determines which projects own those files
- Walks the project graph to find all downstream dependents
- Runs
nx run-many -t testfor only that set of projects
lib, and app1 and app2 both depend on lib, Nx runs:
next in package.json only affects projects that use Next.js — not every project in the repo.
Computation hashing and caching
Before running any cacheable task, Nx computes a computation hash based on:- All source files of the project and its dependencies
- Relevant global configuration (e.g.,
nx.json,tsconfig.base.json) - Versions of external dependencies
- Runtime values such as the Node.js version
- CLI command flags
.nx/cache) or the remote cache (Nx Cloud), Nx replays the result — restoring output files and printing terminal output — without running the task. From the user’s perspective, the command ran the same, only much faster.
If no match is found, Nx runs the task and stores its outputs for future use.
Distributed task execution
For large workspaces, even aggressive caching may not be enough to keep CI fast. Nx Agents distribute the task graph across multiple machines. Tasks run in parallel across agents, sharing artifacts through remote caching. From your CI configuration’s perspective, results appear as if everything ran on a single machine.Summary
Nx builds a project graph by analyzing your source code
Nx builds a project graph by analyzing your source code
Projects are detected from
package.json and project.json files. Dependencies are inferred from import statements, installed packages, and plugin logic. The graph is cached and incrementally updated.Nx creates a task graph from the project graph for every command
Nx creates a task graph from the project graph for every command
Tasks declare dependencies via
dependsOn in target configuration. The task graph determines execution order and parallelism. The project graph and task graph are related but not identical.Nx uses affected analysis to run only what's needed
Nx uses affected analysis to run only what's needed
Changed files map to affected projects via the project graph. Only those projects and their dependents have their tasks run.
Nx caches task results and replays them when inputs haven't changed
Nx caches task results and replays them when inputs haven't changed
The cache key is a hash of all inputs. Cache hits restore output files and terminal output. The cache can be local, remote, or both.
