How Nx builds the project graph
Nx constructs the project graph automatically every time it runs. The process works as follows:1
Detect projects
Nx scans the workspace for
package.json and project.json files. Each file found marks a project boundary. Plugins can extend this detection logic to identify projects in non-standard locations.2
Analyze dependencies
For each project, Nx analyzes the source files to find dependencies on other projects. It uses TypeScript and JavaScript static import analysis as the primary mechanism, supplemented by plugin-provided analyzers for other file types.
3
Apply plugin and manual overrides
Plugins can contribute additional edges to the graph (e.g., based on config files). Developers can also declare
implicitDependencies in project.json to add edges that static analysis cannot detect.4
Cache the result
The completed graph is cached on disk. On subsequent runs, Nx only re-analyzes files that have changed since the last computation, keeping graph construction fast even in large repositories.
Dependency types
Edges in the project graph have a type that describes how the dependency was detected:TypeScript and JavaScript analysis
Nx’s built-in dependency analysis understands TypeScript path mappings configured intsconfig.base.json. When a file imports from a path alias like @myorg/shared-ui, Nx resolves that alias back to the owning project and adds the appropriate edge:
tsconfig.base.json
Implicit dependencies
Some dependencies cannot be detected from imports alone. Declare them explicitly:apps/e2e/project.json
implicitDependencies to declare that a project depends on all other projects (useful for meta tools like linters or formatters):
Visualizing the project graph
Nx provides an interactive graph viewer. Launch it with:Navigating the graph UI
- Click a node to see a tooltip with links to project details
- Click a dependency edge to see which file(s) created that dependency
- Use the search bar to filter projects by name
- Use proximity controls to expand the graph outward from a focused project
- Trace the dependency path between any two projects using Start/End point selection
- In Nx 20+, composite nodes group projects in the same folder — expand them in place to see individual projects
Export options
.png image.
How the graph powers affected detection
When you runnx affected -t build, Nx uses the project graph to determine which projects are affected by your changes:
- Identifies which files changed (e.g., from a git diff against the base branch)
- Maps those files to their owning projects
- Traverses the project graph to find all downstream dependents of those projects
- Runs the task only for the affected set
How the graph powers task ordering
Nx creates a task graph from the project graph every time you run a command. The task graph respects both the project graph structure and thedependsOn rules in your target configuration. See Task Pipeline for details on how to configure those rules.
Exploring the task graph
In addition to the project graph, you can visualize the task graph for any command using the--graph flag:
- Which tasks will run and in what order
- Which executor handles each task
- Which inputs Nx uses to compute the cache hash for each task
