nx
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:
{
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"cache": true
},
"test": {
"cache": true
}
},
"defaultBase": "main"
}
- Use
project.jsonfor project-specific configuration - Define proper
tagsfor enforcing module boundaries
Project Configuration
Each project should have a project.json:
{
"name": "my-app",
"sourceRoot": "apps/my-app/src",
"projectType": "application",
"tags": ["scope:web", "type:app"],
"targets": {
"build": { },
"serve": { },
"test": { }
}
}
- Define clear project types:
applicationorlibrary - Use tags for enforcing dependency constraints
Code Generation
- Use Nx generators for consistent code scaffolding:
nx g @nx/react:app my-app- Generate React applicationnx g @nx/react:lib my-lib- Generate React librarynx g @nx/react:component my-component --project=my-lib- Generate component
- Create custom generators for project-specific patterns
- Use
--dry-runto preview changes before execution
Module Boundaries
Enforce boundaries using ESLint rules:
{
"@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:buildnx affected:testnx affected:lint
- Define proper
inputsandoutputsfor accurate caching
Task Execution
- Run tasks with Nx CLI:
nx build my-app- Build specific projectnx run-many -t build- Build all projectsnx 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:testin CI for efficient test runs
CI/CD Integration
- Use Nx Cloud for distributed task execution
- Configure GitHub Actions with Nx:
- uses: nrwl/nx-set-shas@v4 - run: nx affected -t lint test build - Implement proper caching strategies
- Use
nx-cloud recordfor 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
More from zard-ui/zardui
angular-testing
Write unit and integration tests for Angular v21+ applications using Jest with @testing-library/angular, focusing on user-centric testing, AAA pattern, and modern Angular patterns (Standalone components, Signals). Use for testing components, services, and HTTP interactions with Jest globals and Testing Library DOM matchers.
27angular-signals
Implement signal-based reactive state management in Angular v20+. Use for creating reactive state with signal(), derived state with computed(), dependent state with linkedSignal(), and side effects with effect(). Triggers on state management questions, converting from BehaviorSubject/Observable patterns to signals, or implementing reactive data flows.
23angular-http
Implement HTTP data fetching in Angular v20+ using resource(), httpResource(), and HttpClient. Use for API calls, data loading with signals, request/response handling, and interceptors. Triggers on data fetching, API integration, loading states, error handling, or converting Observable-based HTTP to signal-based patterns.
22angular-di
Implement dependency injection in Angular v20+ using inject(), injection tokens, and provider configuration. Use for service architecture, providing dependencies at different levels, creating injectable tokens, and managing singleton vs scoped services. Triggers on service creation, configuring providers, using injection tokens, or understanding DI hierarchy.
22angular-routing
Implement routing in Angular v20+ applications with lazy loading, functional guards, resolvers, and route parameters. Use for navigation setup, protected routes, route-based data loading, and nested routing. Triggers on route configuration, adding authentication guards, implementing lazy loading, or reading route parameters with signals.
21angular-tooling
Use Angular CLI and development tools effectively in Angular v20+ projects. Use for project setup, code generation, building, testing, and configuration. Triggers on creating new projects, generating components/services/modules, configuring builds, running tests, or optimizing production builds.
21