> ## 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.

# Extending Nx

> Learn how to extend Nx with local generators, local executors, and publishable plugins to enforce best practices and integrate tools across your organization.

Nx core functionality focuses on task running and understanding your project and task graph. Nx plugins build on that foundation to enforce best practices, integrate tooling, and let developers get up and running quickly.

As your repository grows, you'll find more reasons to create your own extensions:

* **Standardize workflows** — local generators automate repetitive scaffolding so every team member follows the same patterns.
* **Eliminate duplicate config** — local executors wrap tool invocations once and share them across every project.
* **Scale across repos** — publishable plugins let you share generators, executors, and inferred task logic with multiple monorepos or with the wider community.

## Three ways to extend Nx

<CardGroup cols={3}>
  <Card title="Local generators" icon="wand-magic-sparkles" href="/extending-nx/local-generators">
    Automate code scaffolding, enforce project structure, and standardize workflows within a single workspace.
  </Card>

  <Card title="Local executors" icon="play" href="/extending-nx/local-executors">
    Wrap build, test, and deployment scripts in a consistent interface with schema validation and caching support.
  </Card>

  <Card title="Create a plugin" icon="puzzle-piece" href="/extending-nx/create-plugin">
    Package generators and executors into a publishable plugin that integrates a tool or framework and can be shared across repos.
  </Card>
</CardGroup>

## When to use each approach

| Situation                                      | Recommended approach        |
| ---------------------------------------------- | --------------------------- |
| Automate a repetitive task in one repo         | Local generator             |
| Standardize a build or test script in one repo | Local executor              |
| Infer tasks from a config file automatically   | Plugin with `createNodesV2` |
| Share logic across multiple monorepos          | Publishable plugin          |
| Integrate a framework for the community        | Publishable plugin          |

## The @nx/devkit API

All plugin development uses the `@nx/devkit` package, which provides the building blocks for generators and executors.

<Tabs>
  <Tab title="Generator utilities">
    ```typescript theme={null}
    import {
      Tree,                       // Virtual file system
      generateFiles,              // Create files from EJS templates
      formatFiles,                // Format files with Prettier
      addProjectConfiguration,    // Register a new project
      readProjectConfiguration,   // Read an existing project's config
      updateProjectConfiguration, // Modify an existing project's config
      readNxJson,                 // Read nx.json
      updateNxJson,               // Write nx.json
      updateJson,                 // Modify any JSON file
      installPackagesTask,        // Trigger package installation after generation
      names,                      // Derive camelCase/PascalCase/kebab-case names
      joinPathFragments,          // Join path segments safely
    } from '@nx/devkit';
    ```
  </Tab>

  <Tab title="Executor utilities">
    ```typescript theme={null}
    import {
      ExecutorContext,    // Context object passed to every executor
      runExecutor,        // Compose and run another executor
      parseTargetString,  // Parse 'project:target:config' strings
    } from '@nx/devkit';
    ```
  </Tab>

  <Tab title="Plugin / project graph utilities">
    ```typescript theme={null}
    import {
      CreateNodesV2,              // Infer projects and targets from config files
      CreateNodesContextV2,       // Context provided during node creation
      CreateDependencies,         // Add dependencies to the project graph
      CreateDependenciesContext,  // Context provided during dep creation
      createNodesFromFiles,       // Helper for batching createNodesV2 calls
      DependencyType,             // Enum: static | dynamic | implicit
      validateDependency,         // Validate a candidate dependency
    } from '@nx/devkit';
    ```
  </Tab>
</Tabs>

## Create your first plugin

<Steps>
  <Step title="Add the plugin package">
    ```bash theme={null}
    npx nx add @nx/plugin
    ```
  </Step>

  <Step title="Scaffold a plugin in your workspace">
    ```bash theme={null}
    npx nx g @nx/plugin:plugin tools/my-plugin
    ```

    Or create a brand-new workspace with a plugin already set up:

    ```bash theme={null}
    npx create-nx-plugin my-plugin
    ```
  </Step>

  <Step title="Add generators and executors">
    ```bash theme={null}
    # Add a generator
    npx nx g @nx/plugin:generator tools/my-plugin/src/generators/my-generator

    # Add an executor
    npx nx g @nx/plugin:executor tools/my-plugin/src/executors/my-executor
    ```
  </Step>
</Steps>

## Explore further

<CardGroup cols={2}>
  <Card title="Local generators" icon="wand-magic-sparkles" href="/extending-nx/local-generators">
    Create and run generators inside your workspace.
  </Card>

  <Card title="Local executors" icon="play" href="/extending-nx/local-executors">
    Write custom task runners with schema validation.
  </Card>

  <Card title="Create a plugin" icon="puzzle-piece" href="/extending-nx/create-plugin">
    Package everything into a publishable Nx plugin.
  </Card>

  <Card title="Project graph plugins" icon="diagram-project" href="/extending-nx/project-graph-plugins">
    Add nodes and dependencies to the Nx project graph.
  </Card>
</CardGroup>
