Skip to content

project rulesFrontendangulartypescript

Angular Rules

Project rules for Angular: standalone components, signals, typed reactive forms, safe RxJS subscriptions and TestBed component tests.

npx workspacetemplates add angular-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file23 lines · 1.5 KBFile
# Project rules: Angular

## Components
- Standalone components only; do not create new NgModules. Set `changeDetection: ChangeDetectionStrategy.OnPush` on every component.
- Use `input()`, `output()` and `model()` for the component API, `signal` and `computed` for state, and `effect` rarely and only for side effects.
- Write templates with `@if`, `@for` (always with `track`) and `@switch`. Keep logic out of templates; do not call methods that do work from bindings.
- Keep components presentational where possible. Smart containers talk to services; dumb ones take inputs and emit outputs.

## Services and DI
- Use `inject()` and `providedIn: 'root'` for singletons. One service per concern; do not put HTTP calls in components.
- Use `HttpClient` with typed responses and interceptors for auth and error handling. Define API models as interfaces.

## RxJS
- Prefer `async` pipe or `toSignal` over manual `subscribe`. When you must subscribe, end it with `takeUntilDestroyed()`.
- Flatten with `switchMap` for search and `concatMap` for ordered writes. Never nest subscribes.

## Forms
- Use typed reactive forms (`FormBuilder.nonNullable`) with validators; show errors only after touch.

## Structure and tests
- Group by feature with lazy-loaded routes (`loadComponent`, `loadChildren`). Strict mode stays on.
- Test with TestBed or a component harness, query the DOM, and mock services with `provideHttpClientTesting`.
- Run `ng lint`, `ng test --watch=false` and `ng build` before finishing.

What it does

These rules direct an agent to write current Angular: standalone components, signals for local state, the new control flow syntax and the inject function.

They also address the places where Angular code goes wrong, such as leaked subscriptions, untyped forms and components that do too much, and set a clear testing habit.

Example

you › Create a product search page with debounced input and results list

agent › The agent adds a lazy route and a standalone OnPush component, a typed form control, switchMap with debounce via toSignal, @for with track, and a TestBed test with a stubbed service.

Questions

Is NgModule support removed?
No, but new code does not need it. The rule applies to files the agent creates, and existing modules can stay until you migrate.
Why OnPush everywhere?
It limits change detection to input and signal changes, which keeps screens fast and exposes accidental mutation early.
  • .NET Blazor Rules

    Project rulescsharp

    Free
  • Astro Rules

    Project rulesastro

    Free
  • Electron Rules

    Project ruleselectron

    Free
  • Next.js App Router Rules

    Project rulesnextjs

    Free