nx-workspace-patterns

Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.

Author

Install

Hot:2

Download and extract to your skills directory

Copy command and send to OpenClaw for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-nx-workspace-patterns&locale=en&source=copy

Nx Workspace Patterns - Nx Monorepo Workspace Configuration and Optimization Guide

Skill Overview


Nx Workspace Patterns provides production-grade configuration patterns and best practices for Nx monorepos. It helps developers efficiently manage multi-application projects, optimize build caching, enforce module boundaries, and accelerate CI/CD workflows through affected commands.

Use Cases

1. Setting Up a New Nx Workspace


When you need to create an Nx monorepo project from scratch, this skill offers end-to-end architectural guidance, including apps/libs directory planning, defining project tags, and the core configuration in nx.json. It covers workspace initialization for multiple stacks such as React, Angular, and Node.js.

2. Configuring Project Boundaries and Dependency Rules


As your team grows and your codebase becomes more complex, enforce architectural constraints using module boundary rules. Define library type tags such as type:feature, type:ui, and type:data-access to prevent circular dependencies and keep code dependency relationships clear and controllable.

3. Optimizing CI Pipelines and Build Cache


When CI time becomes too long and impacts development efficiency, use affected commands to only test and build changed projects. Combined with Nx Cloud or self-hosted remote caching, this can significantly reduce CI duration and improve delivery speed.

Core Features

1. Workspace Architecture Design


Provides a standardized Nx workspace directory structure template, including apps (deployable applications), libs (shared libraries), and tools (custom executors and generators). Defines five core library types: feature (business logic), ui (presentation components), data-access (data access), util (utility functions), and shell (application startup) to keep responsibilities clear.

2. Enforced Module Boundaries


Uses the ESLint plugin enforce-module-boundaries to enforce dependency constraints at the code level. For example: type:app can only depend on libraries of types feature/ui/data-access/util, and type:util cannot depend on any other library type. Works with project tags (e.g., scope:web/api/shared) to govern architecture across dimensions.

3. Cache and CI Optimization


Configures cacheable operations (build, lint, test, e2e). Use namedInputs to precisely control cache invalidation conditions. Integrates CI templates for GitHub Actions, runs tasks in parallel using nx affected commands, and supports Nx Cloud remote caching as well as an AWS S3 self-hosted caching setup.

Frequently Asked Questions

What is an Nx monorepo? Is it suitable for my project?


Nx is a build system designed specifically for monorepos (single repositories). It allows you to manage multiple applications and shared libraries within one repo. If your team has multiple related frontend projects, a shared UI component library, or needs a unified CI/CD workflow, Nx can significantly improve development efficiency. Compared with Lerna or Turborepo, Nx offers stronger dependency graph analysis and intelligent caching.

How do I configure Nx module boundary rules?


Configure the @nx/enforce-module-boundaries rule in .eslintrc.json at your project root. First, define tags for each project (e.g., type:feature, scope:web), then specify dependency constraints in depConstraints. For example: a project with sourceTag "type:ui" can only depend on libraries with "type:ui" and "type:util". After configuration, ESLint will detect invalid dependency imports in real time during development.

How do Nx affected commands speed up CI?


Conventional CI runs tests and builds for all projects, even if most code hasn’t changed. The nx affected command compares the current branch with a base branch (such as main), and only detects and executes tasks for affected projects. Combined with the --parallel option to run tasks in parallel, it can greatly reduce CI time. For example: npx nx affected -t build --parallel=3 builds only the changed projects and their dependencies.