Production-strict modern Angular (v20+) best practices covering standalone components, Signals-first reactivity, zoneless change detection, feature-first architecture, functional routing and HTTP, typed and Signal forms, SSR with incremental hydration, performance, security, accessibility, and Vitest testing conventions.
Install directly into your Antigravity environment via the CLI:
agy plugin install https://github.com/HalcyonTech-LTDA/modern-angular-best-practicesVerify that the plugin is active and conforms to the strict official schema:
agy plugin list
agy plugin validate --strict ./modern-angular-best-practicesModern Angular (v20+) has undergone a generational transformation—from NgModule boilerplate and Zone.js monkey-patching to a lean, Signals-first, standalone-by-default, zoneless web platform. Without clear architectural guardrails, AI-assisted and team-built Angular codebases frequently regress into outdated patterns:
- Legacy
NgModule& Structural Directive Drift: Generating unnecessaryNgModulefiles,CommonModulebarrel imports, and*ngIf/*ngFor/*ngSwitchinstead of standalone components and native control flow (@if,@for,@switch,@let). - Imperative State &
effect()Abuse: UsingBehaviorSubjectboilerplate for local UI state or mutating signals insideeffect()instead of declarativecomputed()andlinkedSignal(). - Zone.js Coupling & Performance Bloat: Mutating plain class properties in async callbacks, skipping
ChangeDetectionStrategy.OnPush, missing@defercode-splitting, and shipping oversized initial bundles. - Technical-Layer Folder Spaghetti: Dumping unrelated code into global
/components,/services, and/modelsdirectories instead of bounded feature-first domains. - Class-Based Routing/HTTP & Untyped Forms: Writing deprecated class-based guards/interceptors, subscribing to
ActivatedRoutemanually instead ofwithComponentInputBinding(), and leakinganythrough untyped forms. - Legacy Karma Testing & Flaky Suites: Scaffolding deprecated Karma/Jasmine runners and brittle
setTimeoutassertions instead of first-party@angular/build:unit-testwith Vitest,RouterTestingHarness,DeferBlockBehavior.Manual, and Playwright.
This plugin establishes a Production-Strict Angular v20+ Baseline across five foundational pillars:
┌─────────────────────────────────────────────────┐
│ Modern Angular v20+ Engineering System │
└────────────────────────┬────────────────────────┘
│
┌──────────────────────┬──────────────────────┬─────┴─────┬──────────────────────┬──────────────────────┐
▼ ▼ ▼ ▼ ▼ │
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ Components & │ │ Architecture & │ │ Routing, HTTP │ │ Performance, │ │ Testing & │ │
│ Signals │ │ State / DI │ │ & Forms │ │ SSR & Security │ │ Tooling │ │
├─────────────────┤ ├─────────────────┤ ├─────────────────┤ ├─────────────────┤ ├─────────────────┤ │
│• Standalone │ │• Feature-First │ │• provideRouter │ │• @defer Views │ │• Vitest Builder │ │
│• Signals/linked │ │• Smart vs UI │ │• Input Binding │ │• NgOptimizedImg │ │• Zoneless Tests │ │
│• Zoneless+OnPush│ │• Route Providers│ │• Functional Fn │ │• Inc. Hydration │ │• RouterHarness │ │
│• @if/@for/@let │ │• SignalStore │ │• withFetch HTTP │ │• Bundle Budgets │ │• angular-eslint │ │
│• inject() & host│ │• RxJS Interop │ │• Typed & Signal │ │• XSS/CSP/WCAG │ │• Playwright E2E │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
This plugin provides five specialized skills loaded progressively on demand, backed by focused reference guides:
| Skill | Focus Area | Key Capabilities |
|---|---|---|
modern-angular-components-and-signals |
Components, Signals & Templates | Standalone-by-default, signal/computed/linkedSignal/effect, input/output/model/signal queries, provideZonelessChangeDetection + OnPush, @if/@for/@switch/@let, host metadata, inject(), and Angular v20+ style guide. |
modern-angular-architecture-and-state |
Architecture, DI & State | Feature-first domain layout (core/, features/, shared/), Smart vs. Presentational split, DI scoping & InjectionToken, provideAppInitializer(), Signal stores, @ngrx/signals, and toSignal/toObservable/takeUntilDestroyed. |
modern-angular-routing-http-and-forms |
Routing, HTTP & Forms | provideRouter (withComponentInputBinding, withViewTransitions, lazy loading), functional guards/resolvers/interceptors, provideHttpClient(withFetch()), RFC 7807 error normalization, NonNullableFormBuilder, and Signal Forms (@angular/forms/signals). |
modern-angular-performance-ssr-and-security |
Performance, SSR, Security & A11y | @defer code-splitting & prefetching, NgOptimizedImage, provideClientHydration(withEventReplay(), withIncrementalHydration()), afterNextRender(), bundle budgets, XSS/CSP/CSRF hardening, and WCAG 2.1 AA accessibility. |
modern-angular-testing-and-tooling |
Testing, Linting & CI Gates | First-party @angular/build:unit-test with Vitest, zoneless TestBed, RouterTestingHarness, DeferBlockBehavior.Manual, HttpTestingController, strict tsconfig.json, angular-eslint flat config, and Playwright E2E. |
- Standalone-by-Default: Zero new
NgModuledeclarations; bootstrap exclusively viabootstrapApplication()andApplicationConfig. - Signals-First & Zoneless-Ready: Use
signal(),computed(),linkedSignal(),input(),output(),model(),provideZonelessChangeDetection(), andChangeDetectionStrategy.OnPush. Never derive state insideeffect(). - Native Control Flow & Bindings: Strictly prohibit
*ngIf,*ngFor,*ngSwitch,ngClass,ngStyle,@HostBinding, and@HostListener. Use@if,@for (...; track ...),@switch,@let, native[class.*]/[style.*], andhost: {}. - Function-Based DI & Primitives: Prefer
inject()over constructor injection; write all guards, resolvers, and HTTP interceptors as pure functions. - Memory Safety: Zero unmanaged
.subscribe()calls; usetoSignal(),asyncpipe, ortakeUntilDestroyed(). - Strict Type Safety: Enforce TypeScript
strict: true,strictTemplates: true,NonNullableFormBuilder, and zeroany. - Security & Accessibility: Zero unchecked
bypassSecurityTrust*(), zero secrets inenvironment.*.ts, CSP/XSRF hygiene, and semantic WCAG 2.1 AA HTML. - Deterministic Vitest Testing: Zero new Karma configs; test deterministically with
@angular/build:unit-test(Vitest),RouterTestingHarness,DeferBlockBehavior.Manual,HttpTestingController, and Playwright.
import { ChangeDetectionStrategy, Component, computed, inject, input, output } from '@angular/core';
import { CurrencyPipe } from '@angular/common';
import { CartStore } from '../data-access/cart-store';
export interface Product {
readonly id: string;
readonly name: string;
readonly priceCents: number;
readonly stock: number;
}
@Component({
selector: 'app-product-card',
imports: [CurrencyPipe],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { '[class.out-of-stock]': 'isOutOfStock()' },
template: `
@let item = product();
<article>
<h3>{{ item.name }}</h3>
<p>{{ item.priceCents / 100 | currency }}</p>
@if (isOutOfStock()) {
<span class="badge">Sold out</span>
} @else {
<button type="button" (click)="onAdd()">Add to Cart</button>
}
</article>
`,
})
export class ProductCard {
private readonly cart = inject(CartStore);
readonly product = input.required<Product>();
readonly added = output<Product>();
protected readonly isOutOfStock = computed(() => this.product().stock <= 0);
protected onAdd(): void {
const item = this.product();
this.cart.add(item);
this.added.emit(item);
}
}rules/modern-angular-engineering.md: Automatic guardrails, skill router, and the 8 non-negotiable Angular v20+ invariants.
skills/modern-angular-components-and-signals/SKILL.md+ 2 reference guidesskills/modern-angular-architecture-and-state/SKILL.md+ 2 reference guidesskills/modern-angular-routing-http-and-forms/SKILL.md+ 2 reference guidesskills/modern-angular-performance-ssr-and-security/SKILL.md+ 2 reference guidesskills/modern-angular-testing-and-tooling/SKILL.md+ 2 reference guides
modern-angular-best-practices/
├── plugin.json # Official Antigravity manifest (schema v1)
├── LICENSE # MIT License (Copyright 2026 HalcyonTech LTDA)
├── .gitignore # Ignores system junk, logs & installed_version.json
├── .gitattributes # Deterministic LF line endings (* text=auto eol=lf)
├── README.md # Golden Standard documentation & runbook
├── assets/
│ ├── logo.svg # Official Halcyon Tech marketplace icon
│ └── halcyon-horizontal-cor.svg # Official Halcyon Tech horizontal brand card
├── rules/
│ └── modern-angular-engineering.md # Normative guardrails and skill router
└── skills/
├── modern-angular-components-and-signals/
│ ├── SKILL.md # Standalone, Signals, Zoneless & templates workflow
│ └── references/
│ ├── signals_and_zoneless.md # Signals, linkedSignal, effect discipline & zoneless
│ └── components_and_templates.md # Signal APIs, @if/@for/@switch/@let & v20+ style guide
├── modern-angular-architecture-and-state/
│ ├── SKILL.md # Feature-first architecture, DI & state workflow
│ └── references/
│ ├── feature_architecture_and_di.md # Core/Features/Shared, Smart vs UI & DI scoping
│ └── state_and_rxjs_interop.md # Signal stores, NgRx SignalStore & RxJS interop
├── modern-angular-routing-http-and-forms/
│ ├── SKILL.md # Functional routing, HTTP & forms workflow
│ └── references/
│ ├── routing_and_http.md # provideRouter, functional guards/interceptors & fetch
│ └── typed_and_signal_forms.md # NonNullableFormBuilder & @angular/forms/signals
├── modern-angular-performance-ssr-and-security/
│ ├── SKILL.md # Performance, SSR, security & WCAG workflow
│ └── references/
│ ├── performance_and_ssr.md # @defer, NgOptimizedImage, hydration & bundle budgets
│ └── security_and_accessibility.md # XSS/CSP/CSRF hardening & WCAG 2.1 AA patterns
└── modern-angular-testing-and-tooling/
├── SKILL.md # Vitest, linting & Playwright testing workflow
└── references/
├── vitest_and_component_testing.md # @angular/build:unit-test, TestBed & RouterHarness
└── tooling_linting_and_e2e.md # Strict tsconfig, angular-eslint & Playwright E2E
Copy and paste these prompts directly into your Antigravity chat:
"Refactor this NgModule-based Angular component to standalone Signals-first architecture: replace
@Input/@Outputwithinput()/output(), migrate constructor DI toinject(), switch to@if/@for/@let, addChangeDetectionStrategy.OnPush, and make it zoneless-ready."
"Design a feature-first
ordersdomain undersrc/app/features/orders/with lazy routes, a route-scoped Signal Store service, Smart/Presentational component split, and a typedOrdersApiusing functional HTTP interceptors."
"Audit this Angular application for zoneless readiness, SSR safety (
afterNextRender),@deferopportunities,NgOptimizedImageLCP compliance, XSS sanitization boundaries, and WCAG 2.1 AA accessibility gaps."
"Migrate this Karma spec to
@angular/build:unit-testwith Vitest usingprovideZonelessChangeDetection(),fixture.componentRef.setInput(),RouterTestingHarness,DeferBlockBehavior.Manual, andHttpTestingController."
Distributed under the MIT License. See LICENSE for the full text.
Engineered with precision and excellence by Halcyon Tech — GitHub Organization.