angular-standards
Skill0 starsChanged 2 months agoMITView on GitHub
Use when writing or reviewing Angular + TypeScript code — components, services, reactive forms, routing/guards, state, styling — even when the user does not say standards, and keep applying it across the session. Enforces two-layer @data/@presentation architecture, all HTTP through a single shared HTTP wrapper service (never HttpClient directly) with URLs from an environment-configured base URL plus a version segment, providedIn:'root' singletons, reactive forms, version-aware NgModule/standalone coexistence, signal stores when supported, strict TS (avoid any), SCSS + framework-first styling, and centralized error handling (ngx-toastr + ErrorInterceptor, never silence); flags fat smart components and hardcoded env URLs. For the core, the `coding-standards` skill helps if available; for Angular/Node upgrades, LTS or EOL migration, the `version-evolution` skill if available; for testing, the `software-testing` skill if available.
In this repository21 other files it gives its agents.
- authoring-skillsSkill
- creating-toolsSkill
- system-diagramsSkill
- java-spring-standardsSkill
- sql-authoringSkill
- exploring-designs-with-agentsSkill
- ui-authoringSkill
- project-docsSkill
- technical-writingSkill
- coding-standardsSkill
- critical-thinkingSkill
- github-workflowsSkill
- reviewing-codeSkill
- security-practicesSkill
- software-testingSkill
- version-evolutionSkill
- git-conventionsSkill
- resolving-merge-conflictsSkill
- releasing-android-appsSkill
- coordinating-agentsSkill
- masterSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Read package.json, the lockfile, angular.json and tsconfig* before choosing Angular APIs.
- Distinctive: line 19
Use only stable APIs available on that baseline.
- Very specific: line 22
Keep Angular core and CLI on the same major.
- Distinctive: line 24
Treat the existing code patterns below as compatibility history, not as limits on newer supported Angular versions.
- Very specific: line 35
All HTTP goes through a single wrapper service (e.g.
- Very specific: line 51
Use inject() only when the installed Angular baseline supports the required stable API.
- Distinctive: line 80
Do not add NgRx/Akita unless the problem justifies that dependency and the team accepts it.
- Very specific: line 81
When the installed Angular line supports stable signals, prefer a light signal store for new local state: private writable signal(), …
- Very specific: line 105
Stop polling (timer/interval) on 401/403.
- Very specific: line 129
Use the runner configured by the target and treat sparse coverage as a gap.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
angular-standards — Angular + TypeScript standards
Purpose
Stack conventions for writing and reviewing Angular code. It contributes idiomatic Angular/TS rules; it does not write the consumer's code.
Knowledge
Version and toolchain baseline
- Read
package.json, the lockfile,angular.jsonandtsconfig*before choosing Angular APIs. Resolve Angular core/CLI, Node.js, TypeScript, RxJS, the package manager and configured builders. - For ordinary work, those declared versions are the compatibility baseline. Use only stable APIs available on that baseline; never downgrade or upgrade it incidentally.
- For a new project or explicit migration, apply the
version-evolutionskill if it is available. Choose a supported Angular line, a compatible Node.js LTS and the official TypeScript/RxJS ranges. - Keep Angular core and CLI on the same major.
Upgrade one major at a time with
ng update, pin the result and regenerate the lockfile. - Treat the existing code patterns below as compatibility history, not as limits on newer supported Angular versions.
Two-layer architecture
src/app/@data/— data access:services/(HTTP),interceptors/,guards/,interfaces/,directives/.src/app/@presentation/— UI:auth/,home/,shared/,pages/.- Cross-cutting helpers in
Utils/. Global types in@data/interfaces/; local types in the feature'sinterfaces/. - Tolerated minor variant: a repo without path-aliases (
@data/*) that imports via absolutesrc/app/.... Respect the repo's convention.
HTTP always through the shared wrapper (never HttpClient directly)
- All HTTP goes through a single wrapper service (e.g.
@data/services/api-client.service.tswithget/post/put/patch/delete+getBlob/getResource); each method doescatchError -> formatErrors. Feature services inject the wrapper, neverHttpClient. URLs are built from an environment-configured base URL (e.g.
environment.apiBaseUrl) + an explicit version segment such as/v1/. Never hardcode URLs/hosts inline:const url = `${environment.apiBaseUrl}/v1/users/roles`; return this.apiClient.get(url);- Query and body are built with shared
Utils/helpers: a query helper (e.g.buildQuery(): trims, dropsnull/empty, keeps0) for querystrings and a payload helper (e.g.wrapPayload<T>()) to wrap the body. Never ad-hocHttpParams. - The response envelope types (e.g.
IResponsePayload<T>,IPayloadList<T>) are the shared FE-BE contract.
Dependency injection
- Services
@Injectable({ providedIn: 'root' })(tree-shakable singletons). - Two styles coexist: constructor injection (
privatecollaborators, dominant in existing code) andinject()(forDestroyRef, signal stores, and functional guards/interceptors). Useinject()only when the installed Angular baseline supports the required stable API; otherwise preserve constructor injection.
Reactive forms
ReactiveFormsModule+FormBuilder/FormGroup/Validatorsfor capture screens. Build inngOnInit/constructor.- Clean up
valueChangeswithtakeUntilDestroyed(destroyRef)when the installed baseline supports it; otherwise use the repository's existing teardown pattern without adding a compatibility shim. - Dependent combos: subscribe to the parent's
valueChangesand reset/patch the children. - On edit, preload with
patchValue({...}, { emitEvent: false })to avoid firing thevalueChangeschain. [(ngModel)]only in simple/legacy views.
Modules, routing and components
- In an existing NgModule feature, preserve its module +
*-routing.module.ts(forChild) shape unless the task explicitly includes migration. - On an Angular baseline that supports stable standalone APIs, prefer standalone components and lazy routes for new isolated features. They may coexist with existing NgModules.
- Migrate existing NgModules only as explicit, feature-sized increments using the official migration tooling.
- The root router declares auth/home/admin and lazy-loads features using the syntax supported by the installed version. Wildcard
'**'redirects. - Smart/presentational: "page" components are smart containers (forms, services, orchestrate HTTP+navigation); the pieces in
shared/componentsare@Input-driven with getter-derived state. Selector prefixapp, separatetemplateUrl+styleUrls.OnPushis the target for new components. Flag: "fat smart component" (e.g. a ~410-line component injecting 11 services) — propose extraction. - Guards: preserve class-based guards on baselines that require them. Use functional guards
(
CanActivateFn/CanMatchFnwithinject()) only when the installed Angular line supports the required stable APIs, or migrate them as an explicit increment. Post-login navigation is permission-driven (default-deny RBAC). - An empty permission set renders an empty menu. Never fall back to showing every item (or a default route) because the permissions came back empty — that turns a backend failure into an access grant. Surface the empty state; the same no-hidden-fallback rule as in the
coding-standardsskill, if available, applied to authorization.
State
- Do not add NgRx/Akita unless the problem justifies that dependency and the team accepts it.
- When the installed Angular line supports stable signals, prefer a light signal store for new local
state: private writable
signal(), readonlycomputed()selectors,asReadonly()exposure,.store.tssuffix and a co-located state interface. - On older baselines, follow the existing RxJS state pattern.
Migrate
BehaviorSubjectservices to signals only in an explicit, tested modernization increment.
Strict typing
- With
strict+strictTemplatesactive intsconfig, discipline is the gap. Avoidany(use the concrete type orunknown); type the HTTP wrapper generically instead ofObservable<any>. Avoid!(non-null assertion) without justification.
Centralized error handling (never silence)
- Two levels: (1) the HTTP wrapper's
catchErrornormalizesHttpErrorResponseand shows anngx-toastrtoast ('danger'), then re-throws withthrowError; (2) a globalErrorInterceptorhandles auth: 403 → silent refresh-token + replay of the cloned request; 401 → redirect to/login; exclude the login/refresh endpoints. The logout belongs to the refresh, not to the replay. Put the
catchErrorthat logs out on the refresh call, before theswitchMapthat replays. Placed after it, a 403 for a missing permission, a 500 or a network drop on the replayed request logs out a valid session.refreshToken$().pipe( catchError((error) => { logout(); return throwError(() => error); }), switchMap(() => next.handle(retried)), );- Make logout idempotent: parallel requests (
forkJoin) can each receive the 403. - Detect the rejection by the
HttpErrorResponsestatus, not only by the body: a gateway can answer 403 with HTML or plain text. - Stop polling (
timer/interval) on 401/403. A poll whosecatchErrorswallows the error keeps calling with a dead session. - Forbidden:
catchError(() => of([]))and leftoverconsole.logof tokens/responses. - Guard the deep message path: read
error?.error?.status?.error?.messages?.[0]with optional-chaining + fallback. The unguarded accesserror.error.status.error.messages[0]blows up when the shape differs — fix it when touched. - The session interceptor (Bearer token, per-request identity headers, pre-auth skip) is a separate interceptor from the
ErrorInterceptor.
Styling
- SCSS over
.css(per-component.component.scss+ globalstyles.scss/theme.scss). Bootstrap as cherry-picked SCSS partials with$primary/$successoverridden before the import. Respect the per-component style budgets inangular.json. Avoid one-off inline styles. - Existing codebases often mix Angular Material, Bootstrap and ng/ngx-bootstrap, plus, if the project has one, a shared component catalog
in
shared/components(e.g. data-table, pagination, status-badge, form-modal, page-header…). Detect the target's installed libraries and versions; reuse before creating and never copy a snapshot as a dependency baseline. - Modals: use the installed compatible dialog library and the shared confirm dialog, if the project has one (e.g.
confirm-dialog), for destructive actions.window.confirm()is forbidden. - UX feedback: the loading service (e.g.
LoadingService.show()/hide()) paired innextanderror; errors via the toast service (e.g. aToastServiceover ngx-toastr, dedup). Keep it simple (data-or-empty + toast); no Retry-button error blocks.
Naming and i18n
- Domain identifiers follow the project's established language; framework members keep their Angular names.
- Catalog constants in
SCREAMING_SNAKE, centralized inUtils/const.tswith a shared prefix (e.g.CAT_STAGE,CAT_BANK) — the FE mirror of the backend's catalog tables. - In a single-locale app, never introduce a translation layer (
@angular/localize/TranslateService) unless asked. Toast titles are literal strings in the app's locale. For prose rules, thetechnical-writingskill helps if it is available.
Lint and test (gaps to remediate, never emulate)
- Lint: if a repo has no ESLint, recommend an ESLint + Prettier baseline for it. Never propagate the absence.
- Karma + Jasmine is a common legacy runner, not a permanent version constraint.
Use the runner configured by the target and treat sparse coverage as a gap. For level/command/naming detail, the
software-testingskill helps if it is available.
Mounting a screen component drags its whole injector chain. A screen component
injects a domain service, which injects the shared HTTP wrapper, which injects the toast service —
so a TestBed that declares only the component fails on a provider three hops away, and the error
names the last link, not the missing import. The two that account for most of it:
- Anything that reaches the shared HTTP wrapper needs
HttpClientTestingModule. - Anything that reaches the toast service needs the toast library's
forRoot()inimports; without it the failure readsNo provider for InjectionToken ToastConfig.
Test the logic without mounting the template. A screen component's template pulls in child components, directives and bindings that have nothing to do with the rule under test. Override it:
TestBed.configureTestingModule({ declarations: [DebtComponent], schemas: [NO_ERRORS_SCHEMA] })
.overrideComponent(DebtComponent, { set: { template: '' } });Then call the method and assert the field it sets, instead of querying the DOM for a control the test never needed to render. Keep the build as the companion check: the unit runner compiles templates in JIT, so a template the AOT build rejects passes the suite and breaks the branch.
Output
Rules to apply when implementing or reviewing Angular/TS. It generates no files and runs no runners. On detecting a violation (direct HttpClient, hardcoded URL, catchError(()=>of([])), unguarded error path, fat smart component, any at the HTTP boundary), flag it and propose the idiomatic fix; the consumer decides and writes the change.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

