β¨ A repository showcasing key Nx features for Angular monorepos β¨
This repository demonstrates a production-ready Angular monorepo with:
-
2 Applications
shop
- Angular e-commerce application with product listings and detail viewsapi
- Backend API with Docker support serving product data
-
6 Libraries
@org/feature-products
- Product listing feature (Angular)@org/feature-product-detail
- Product detail feature (Angular)@org/data
- Data access layer for shop features@org/shared-ui
- Shared UI components@org/models
- Shared data models@org/products
- API product service library
-
E2E Testing
shop-e2e
- Playwright tests for the shop application
# Clone the repository
git clone <your-fork-url>
cd angular-template
# Install dependencies
# (Note: You may need --legacy-peer-deps)
npm install
# Serve the Angular shop application
npx nx serve shop
# Serve the API backend
npx nx serve api
# Build all projects
npx nx run-many -t build
# Run tests
npx nx run-many -t test
# Lint all projects
npx nx run-many -t lint
# Run e2e tests
npx nx e2e shop-e2e
# Run tasks in parallel
npx nx run-many -t lint test build e2e --parallel=3
# Visualize the project graph
npx nx graph
This repository showcases several powerful Nx features:
Enforces architectural constraints using tags. Each project has specific dependencies it can use:
scope:shared
- Can be used by all projectsscope:shop
- Shop-specific librariesscope:api
- API-specific librariestype:feature
- Feature librariestype:data
- Data access librariestype:ui
- UI component libraries
Try it out:
# See the current project graph and boundaries
npx nx graph
# View a specific project's details
npx nx show project shop --web
Learn more about module boundaries β
The API project includes Docker support with automated targets and release management:
# Build Docker image
npx nx docker:build api
# Run Docker container
npx nx docker:run api
# Release with automatic Docker image versioning
npx nx release
Nx Release for Docker: The repository is configured to use Nx Release for managing Docker image versioning and publishing. When running nx release
, Docker images for the API project are automatically versioned and published based on the release configuration in nx.json
. This integrates seamlessly with semantic versioning and changelog generation.
Learn more about Docker integration β
End-to-end testing with Playwright is pre-configured:
# Run e2e tests
npx nx e2e shop-e2e
# Run e2e tests in CI mode
npx nx e2e-ci shop-e2e
Learn more about E2E testing β
Fast unit testing with Vite for Angular libraries:
# Test a specific library
npx nx test data
# Test all projects
npx nx run-many -t test
Learn more about Vite testing β
The CI pipeline includes nx fix-ci
which automatically identifies and suggests fixes for common issues:
# In CI, this command provides automated fixes
npx nx fix-ci
This feature helps maintain a healthy CI pipeline by automatically detecting and suggesting solutions for:
- Missing dependencies
- Incorrect task configurations
- Cache invalidation issues
- Common build failures
Learn more about self-healing CI β
βββ apps/
β βββ shop/ [scope:shop] - Angular e-commerce app
β βββ shop-e2e/ - E2E tests for shop
β βββ api/ [scope:api] - Backend API with Docker
βββ libs/
β βββ shop/
β β βββ feature-products/ [scope:shop,type:feature] - Product listing
β β βββ feature-product-detail/ [scope:shop,type:feature] - Product details
β β βββ data/ [scope:shop,type:data] - Data access
β β βββ shared-ui/ [scope:shop,type:ui] - UI components
β βββ api/
β β βββ products/ [scope:api] - Product service
β βββ shared/
β βββ models/ [scope:shared,type:data] - Shared models
βββ nx.json - Nx configuration
βββ tsconfig.json - TypeScript configuration
βββ eslint.config.mjs - ESLint with module boundary rules
This repository uses tags to enforce module boundaries:
Project | Tags | Can Import From |
---|---|---|
shop |
scope:shop |
scope:shop , scope:shared |
api |
scope:api |
scope:api , scope:shared |
feature-products |
scope:shop , type:feature |
scope:shop , scope:shared |
data |
scope:shop , type:data |
scope:shared |
models |
scope:shared , type:data |
Nothing (base library) |
# Project exploration
npx nx graph # Interactive dependency graph
npx nx list # List installed plugins
npx nx show project shop --web # View project details
# Development
npx nx serve shop # Serve Angular app
npx nx serve api # Serve backend API
npx nx build shop # Build Angular app
npx nx test data # Test a specific library
npx nx lint feature-products # Lint a specific library
# Running multiple tasks
npx nx run-many -t build # Build all projects
npx nx run-many -t test --parallel=3 # Test in parallel
npx nx run-many -t lint test build # Run multiple targets
# Affected commands (great for CI)
npx nx affected -t build # Build only affected projects
npx nx affected -t test # Test only affected projects
# Docker operations
npx nx docker:build api # Build Docker image
npx nx docker:run api # Run Docker container
npx nx g @nx/angular:app my-app
npx nx g @nx/angular:lib my-lib
npx nx g @nx/angular:component my-component --project=my-lib
npx nx g @nx/node:lib my-api-lib
You can use npx nx list
to see all available plugins and npx nx list <plugin-name>
to see all generators for a specific plugin.
Nx Cloud ensures a fast and scalable CI pipeline. It includes features such as:
- Remote caching
- Task distribution across multiple machines
- Automated e2e test splitting
- Task flakiness detection and rerunning
Note: This is only required if your CI provider is not GitHub Actions.
Use the following command to configure a CI workflow for your workspace:
npx nx g ci-workflow
Nx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ.
- Nx Documentation
- Angular Monorepo Tutorial
- Module Boundaries
- Docker Integration
- Playwright Testing
- Vite with Angular
- Nx Cloud
- Releasing Packages
Join the Nx community: