An open API service indexing awesome lists of open source software.

https://github.com/nrwl/angular-template

Template repository containing an Nx Workspace with an Angular app. It uses Esbuild for building, Vitest for unit tests and Playwright for e2e tests.
https://github.com/nrwl/angular-template

Last synced: 3 months ago
JSON representation

Template repository containing an Nx Workspace with an Angular app. It uses Esbuild for building, Vitest for unit tests and Playwright for e2e tests.

Awesome Lists containing this project

README

          

# Nx Angular Repository

โœจ A repository showcasing key [Nx](https://nx.dev) features for Angular monorepos โœจ

## ๐Ÿ“ฆ Project Overview

This repository demonstrates a production-ready Angular monorepo with:

- **2 Applications**

- `shop` - Angular e-commerce application with product listings and detail views
- `api` - 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

## ๐Ÿš€ Quick Start

```bash
# Clone the repository
git clone
cd

# Install dependencies
# (Note: You may need --legacy-peer-deps)
npm install

# Serve the Angular shop application (this will simultaneously serve the API backend)
npx nx serve shop

# ...or you can serve the API separately
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
```

## โญ Featured Nx Capabilities

This repository showcases several powerful Nx features:

### 1. ๐Ÿ”’ Module Boundaries

Enforces architectural constraints using tags. Each project has specific dependencies it can use:

- `scope:shared` - Can be used by all projects
- `scope:shop` - Shop-specific libraries
- `scope:api` - API-specific libraries
- `type:feature` - Feature libraries
- `type:data` - Data access libraries
- `type:ui` - UI component libraries

**Try it out:**

```bash
# 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 โ†’](https://nx.dev/features/enforce-module-boundaries)

### 2. ๐Ÿณ Docker Integration

The API project includes Docker support with automated targets and release management:

```bash
# 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 โ†’](https://nx.dev/recipes/nx-release/release-docker-images)

### 3. ๐ŸŽญ Playwright E2E Testing

End-to-end testing with Playwright is pre-configured:

```bash
# 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 โ†’](https://nx.dev/technologies/test-tools/playwright/introduction#e2e-testing)

### 4. โšก Vitest for Unit Testing

Fast unit testing with Vite for Angular libraries:

```bash
# Test a specific library
npx nx test data

# Test all projects
npx nx run-many -t test
```

[Learn more about Vite testing โ†’](https://nx.dev/recipes/vite)

### 5. ๐Ÿ”ง Self-Healing CI

The CI pipeline includes `nx fix-ci` which automatically identifies and suggests fixes for common issues:

```bash
# 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 โ†’](https://nx.dev/ci/features/self-healing-ci)

## ๐Ÿ“ Project Structure

```
โ”œโ”€โ”€ 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
```

## ๐Ÿท๏ธ Understanding Tags

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) |

## ๐Ÿ“š Useful Commands

```bash
# 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
```

## ๐ŸŽฏ Adding New Features

### Generate a new Angular application:

```bash
npx nx g @nx/angular:app my-app
```

### Generate a new Angular library:

```bash
npx nx g @nx/angular:lib my-lib
```

### Generate a new Angular component:

```bash
npx nx g @nx/angular:component my-component --project=my-lib
```

### Generate a new API library:

```bash
npx nx g @nx/node:lib my-api-lib
```

You can use `npx nx list` to see all available plugins and `npx nx list ` to see all generators for a specific plugin.

## Nx Cloud

Nx Cloud ensures a [fast and scalable CI](https://nx.dev/ci/intro/why-nx-cloud?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) pipeline. It includes features such as:

- [Remote caching](https://nx.dev/ci/features/remote-cache?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Task distribution across multiple machines](https://nx.dev/ci/features/distribute-task-execution?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Automated e2e test splitting](https://nx.dev/ci/features/split-e2e-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Task flakiness detection and rerunning](https://nx.dev/ci/features/flaky-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Install Nx Console

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.

[Install Nx Console ยป](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## ๐Ÿ”— Learn More

- [Nx Documentation](https://nx.dev)
- [Angular Monorepo Tutorial](https://nx.dev/getting-started/tutorials/angular-monorepo-tutorial)
- [Module Boundaries](https://nx.dev/features/enforce-module-boundaries)
- [Docker Integration](https://nx.dev/recipes/nx-release/release-docker-images)
- [Playwright Testing](https://nx.dev/technologies/test-tools/playwright/introduction#e2e-testing)
- [Vite with Angular](https://nx.dev/recipes/vite)
- [Nx Cloud](https://nx.dev/ci/intro/why-nx-cloud)
- [Releasing Packages](https://nx.dev/features/manage-releases)

## ๐Ÿ’ฌ Community

Join the Nx community:

- [Discord](https://go.nx.dev/community)
- [X (Twitter)](https://twitter.com/nxdevtools)
- [LinkedIn](https://www.linkedin.com/company/nrwl)
- [YouTube](https://www.youtube.com/@nxdevtools)
- [Blog](https://nx.dev/blog)