Use when you have a written implementation plan to execute in a separate session with review checkpoints
npx skills add sajeetharan/angular-agent-kit --skill "angular-best-practices"
Install specific skill from multi-skill repository
# Description
|
# SKILL.md
name: angular-best-practices
description: |
Angular performance optimization and best practices guidelines for change detection,
bundle optimization, templates, RxJS, and component architecture. Use when writing,
reviewing, or refactoring Angular code, designing component hierarchies, optimizing
performance, or implementing reactive patterns.
license: MIT
metadata:
author: angular-agent-kit
version: "1.0.0"
Angular Best Practices
Comprehensive performance optimization guide for Angular applications, containing 45+ rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new Angular components or services
- Implementing change detection strategies
- Reviewing code for performance issues
- Refactoring existing Angular code
- Optimizing bundle size or load times
- Working with RxJS observables and state management
- Implementing forms and validation
- Writing unit and integration tests
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Change Detection | CRITICAL | cd- |
| 2 | Bundle Size Optimization | CRITICAL | bundle- |
| 3 | Template Performance | HIGH | template- |
| 4 | RxJS & Async Operations | HIGH | rxjs- |
| 5 | Component Architecture | MEDIUM-HIGH | component- |
| 6 | HTTP & Data Fetching | MEDIUM | http- |
| 7 | Forms & Validation | MEDIUM | forms- |
| 8 | Testing & Debugging | LOW-MEDIUM | testing- |
Quick Reference
1. Change Detection (CRITICAL)
cd-onpush- Use OnPush change detection strategycd-trackby- Always use trackBy in *ngForcd-pure-pipes- Prefer pure pipes over methods in templatescd-immutable-data- Use immutable data patternscd-detach-reattach- Detach change detection for heavy computationscd-run-outside-angular- Run non-UI code outside NgZone
2. Bundle Size Optimization (CRITICAL)
bundle-lazy-loading- Lazy load feature modulesbundle-tree-shaking- Ensure tree-shakeable providersbundle-standalone-components- Use standalone componentsbundle-defer-views- Use @defer for heavy componentsbundle-preload-strategies- Implement smart preloadingbundle-avoid-barrel-exports- Import directly, avoid barrel files
3. Template Performance (HIGH)
template-avoid-function-calls- Avoid function calls in templatestemplate-async-pipe- Use async pipe instead of manual subscriptionstemplate-ng-container- Use ng-container for structural directivestemplate-control-flow- Use new control flow syntax (@if, @for)template-optimize-ngif-ngfor- Never use ngIf and ngFor on same elementtemplate-image-optimization- Use NgOptimizedImage directive
4. RxJS & Async Operations (HIGH)
rxjs-avoid-nested-subscriptions- Never nest subscriptionsrxjs-unsubscribe- Always unsubscribe (takeUntilDestroyed, DestroyRef)rxjs-share-replay- Use shareReplay for HTTP cachingrxjs-switchmap-vs-mergemap- Choose correct flattening operatorrxjs-signals-vs-observables- Prefer signals for synchronous staterxjs-debounce-throttle- Debounce user input events
5. Component Architecture (MEDIUM-HIGH)
component-smart-presentational- Separate smart and presentational componentscomponent-input-transforms- Use input transforms for data conversioncomponent-output-naming- Follow output naming conventionscomponent-content-projection- Use content projection effectivelycomponent-dynamic-components- Load components dynamically when neededcomponent-host-directives- Compose behavior with host directives
6. HTTP & Data Fetching (MEDIUM)
http-interceptors- Use interceptors for cross-cutting concernshttp-caching- Implement HTTP caching strategieshttp-retry-logic- Add retry logic for resiliencehttp-cancel-requests- Cancel pending requests on navigationhttp-typed-responses- Always type HTTP responseshttp-error-handling- Implement centralized error handling
7. Forms & Validation (MEDIUM)
forms-reactive-over-template- Prefer reactive forms for complex formsforms-typed-forms- Use strictly typed reactive formsforms-custom-validators- Create reusable custom validatorsforms-async-validation- Debounce async validatorsforms-control-value-accessor- Implement ControlValueAccessor correctlyforms-form-arrays- Handle dynamic form arrays efficiently
8. Testing & Debugging (LOW-MEDIUM)
testing-component-harness- Use component harnessestesting-mock-services- Mock services properlytesting-async-testing- Use fakeAsync/tick for async teststesting-change-detection- Trigger change detection in teststesting-marble-testing- Use marble testing for RxJStesting-performance-profiling- Profile with Angular DevTools
How to Use
Read individual rule files for detailed explanations and code examples:
rules/cd-onpush.md
rules/bundle-lazy-loading.md
rules/_sections.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.