nx — Claude Code skill: Nx monorepo conventions
A skill that tells the agent how to work inside an Nx workspace: apps and libs layout, tags, module boundaries, generators, caching. Useful once your repo runs on Nx.
npx skills add Mindrally/skills --skill nx -a claude-codeWhat nx does
This skill is a set of conventions the agent follows in an Nx workspace. Projects sit under apps/ and libs/, names follow scope-type-name, and related libraries go into feature folders. Workspace-wide settings live in nx.json, while each project gets a project.json with its own sourceRoot, projectType and tags.
Module boundaries are enforced through the ESLint rule @nx/enforce-module-boundaries and its depConstraints: an app may depend only on libs and utils, and a scope like scope:web reaches its own scope plus scope:shared. Builds and tests are cached, and affected commands run tasks only for changed projects. Generators look like nx g @nx/react:app my-app, with --dry-run previewing changes before anything is written.
The skill installs nothing into your repo and edits no configs on its own — it is guidance for the agent. If your projects carry no tags, the boundary rule has nothing to compare, so cross-domain imports slip through unchecked. It advises starting with nx graph to see current links, then assigning tags.
What it helps with
- split projects into apps and libs instead of one flat folder
- stop an app from importing another domain
- scaffold an app or library with a single generator call
- run tasks only for affected projects instead of rebuilding everything
- turn on build and test caching in nx.json
Example prompts for the agent
- Generate a React library shared-ui-button and tag it scope:shared and type:lib
- Read project.json and tell me which tags break the module boundary rule
- Set up targetDefaults in nx.json so build depends on dependency builds and is cached
How to install nx
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a claude-code2Manually: put the files in place
~/.claude/skills/nx/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/nx/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a codex2Manually: put the files in place
.agents/skills/nx/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a cursor2Manually: put the files in place
.cursor/skills/nx/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills nx2Manually: put the files in place
.github/skills/nx/SKILL.md1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a gemini-cli2Platform CLI
gemini skills install https://github.com/Mindrally/skills --path nxManually: put the files in place
.devin/skills/nx/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about nx
How do I install nx in Claude?
Run npx skills add Mindrally/skills --skill nx -a claude-code. The skill file then lives at ~/.claude/skills/nx/SKILL.md.
What does the nx skill do?
It explains Nx workspace conventions to the agent: apps and libs layout, nx.json and project.json config, generators, module boundaries and affected commands. The agent leans on those rules while writing code and editing config.
Why do tags in project.json matter?
The ESLint rule @nx/enforce-module-boundaries reads them. Without tags in depConstraints there is nothing to compare, so the ban on cross-domain dependencies never fires.
Source text
SKILL.md · Apache-2.0
---
name: nx
description: Best practices for Nx monorepo development, project configuration, and code generation
metadata:
maintainer: Mindrally
source: https://github.com/Mindrally/skills
---
# Nx Monorepo Development
You are an expert in Nx, the smart, fast, and extensible build system for monorepos.
## Project Structure
- Organize projects following Nx conventions:
- `apps/` - Application projects (web apps, APIs, mobile apps)
- `libs/` - Library projects (shared code, features, utilities)
- Use consistent naming patterns: `scope-type-name` (e.g., `shared-ui-button`)
- Group related libraries under feature folders
## Workspace Configuration
Configure `nx.json` for workspace-wide settings:
```json
{
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"cache": true
},
"test": {
"cache": true
}
},
"defaultBase": "main"
}
```
- Use `project.json` for project-specific configuration
- Define proper `tags` for enforcing module boundaries
## Project Configuration
Each project should have a `project.json`:
```json
{
"name": "my-app",
"sourceRoot": "apps/my-app/src",
"projectType": "application",
"tags": ["scope:web", "type:app"],
"targets": {
"build": { },
"serve": { },
"test": { }
}
}
```
- Define clear project types: `application` or `library`
- Use tags for enforcing dependency constraints
## Code Generation
- Use Nx generators for consistent code scaffolding:
- `nx g @nx/react:app my-app` - Generate React application
- `nx g @nx/react:lib my-lib` - Generate React library
- `nx g @nx/react:component my-component --project=my-lib` - Generate component
- Create custom generators for project-specific patterns
- Use `--dry-run` to preview changes before execution
## Module Boundaries
Enforce boundaries using ESLint rules:
```json
{
"@nx/enforce-module-boundaries": [
"error",
{
"depConstraints": [
{ "sourceTag": "type:app", "onlyDependOnLibsWithTags": ["type:lib", "type:util"] },
{ "sourceTag": "type:lib", "onlyDependOnLibsWithTags": ["type:lib", "type:util"] },
{ "sourceTag": "scope:web", "onlyDependOnLibsWithTags": ["scope:web", "scope:shared"] }
]
}
]
}
```
- Define clear dependency rules between project types
- Use scopes to separate domain boundaries
## Caching and Performance
- Enable computation caching for faster builds
- Configure Nx Cloud for distributed caching and task execution
- Use affected commands to only run tasks for changed projects:
- `nx affected:build`
- `nx affected:test`
- `nx affected:lint`
- Define proper `inputs` and `outputs` for accurate caching
## Task Execution
- Run tasks with Nx CLI:
- `nx build my-app` - Build specific project
- `nx run-many -t build` - Build all projects
- `nx affected -t test` - Test affected projects
- Use task pipelines for proper dependency ordering
- Configure parallel execution for independent tasks
## Testing Strategy
- Use Jest for unit testing with Nx presets
- Configure Cypress or Playwright for E2E testing
- Implement component testing for UI libraries
- Use `nx affected:test` in CI for efficient test runs
## CI/CD Integration
- Use Nx Cloud for distributed task execution
- Configure GitHub Actions with Nx:
```yaml
- uses: nrwl/nx-set-shas@v4
- run: nx affected -t lint test build
```
- Implement proper caching strategies
- Use `nx-cloud record` for capturing metrics
## Best Practices
- Keep applications thin; move logic to libraries
- Create shared utility libraries for common code
- Use barrel exports (`index.ts`) for clean imports
- Implement proper type exports from libraries
- Document library purposes and public APIs
- Use Nx Console VS Code extension for visual project management
- Leverage the project graph for understanding dependencies: `nx graph`
© Mindrally · Apache-2.0 · Mindrally/skills