Angular Frontend Standard
The rules for FT frontend engineers (Angular / TypeScript; reference repository angular-ui), on one page.
This page is the readable form of the ft-angular-standards skill. If they differ, the skill wins. Report the difference.
The backend (BE) team has its own standard. Both teams share one document: the Internal API Contract between the frontend (FE) and the backend.
Rules at a glance
| Rule | In one line | Section |
|---|---|---|
C1 Folders |
Feature folder, then role; export through a barrel; never the app root |
|
C2 Naming |
Role suffix; |
|
C3 Immutability |
|
|
C4 Injection |
Constructor injection; |
|
C5 Logging |
App logger with |
|
C6 Architecture |
NgModule, RxJS (reactive streams) + NgRx, smart/dumb split; no standalone or signals yet |
|
C7 Style |
Keep the permissive norm; do not harden |
|
C8 Internal API (UI↔BE) |
The wire between the Angular UI and its backend, through a thin |
|
C9 Tests |
|
|
C10 Constants |
No magic values; |
|
C11 Caching |
NgRx store is the client cache |
|
C12 Libraries |
Existing stack first; approved, pinned, |
|
C13 Discipline |
Component ≤ 200 lines, ≤ 7 `@Input`s, method ≤ 40 lines, nesting ≤ 3; KISS |
|
C14 RxJS |
No nested |
|
C15 Templates |
|
|
C16 Security |
No |
Use the review checklist at the end of the page in every pull request.
C1 · Folders = the catalog of the app
A new file goes into its feature folder, named by its role, and is exposed through a barrel (index.ts /
public-api.ts). Never dump a file at the app root, and never inline helper logic in a component.
| Do: feature first, role second | Don’t |
|---|---|
|
|
Workspace: a shared ft-common library + apps. Import across features only through the barrel.
Selector prefixes: ft-common (library) / app (apps).
C2 · Naming: role suffix, no Hungarian
| Rule | Angular (TS) |
|---|---|
Role suffix |
|
Enums |
end with |
Interfaces |
keep the |
Variables/methods |
|
Forbidden |
Hungarian notation |
|
"Hungarian notation" = baking a variable’s type or scope into its name via a prefix
( |
Class suffixes are enforced by @angular-eslint. The I-prefix is the one intentional
divergence from the Java standard (which drops it).
|
Both the I-prefix and the …Enum suffix are deliberate FT conventions for greppability and
uniform cataloguing. Neither is the official Angular or TypeScript idiom, because the Angular style guide uses neither. Where idiom and convention differ, the convention wins on these pages.
|
C3 · Immutability by default
| Do: readonly model | Don’t: in-place mutation |
|---|---|
|
|
NgRx state is updated by spread; use as const for literals. Mutable types only where Angular requires
them (reactive form models).
C4 · Constructor injection · OnPush
Inject through the constructor (or inject(), consistently with the repo). Components are
ChangeDetectionStrategy.OnPush; a BaseComponent provides destroy$ + the takeUntil pattern; unwrap
observables with the async pipe.
C5 · Logging
Log through the app logger, never raw console. Include the device context you already have as key=value: serial (the serial number, a string) and deviceId (a number). A frontend log then greps like a backend log (J5).
| Do | Don’t |
|---|---|
|
|
Levels: error for failed ops surfaced to the user, warn for degraded/retried, info for notable
user actions, debug for dev detail (silenced in prod). No per-render / per-keystroke logging; no stray
console.log in committed code: use the app logger.
|
C6 · Architecture
| Area | Standard |
|---|---|
Components |
NgModule (not standalone), |
State |
RxJS (no signals yet) + NgRx; errors surface through effects → toastr |
Structure |
|
NgModule (not standalone), RxJS-only (no signals), and the BaseComponent + destroy$/takeUntil
pattern are a deliberate choice tied to the current Angular major. They are not the framework’s current default (standalone components, signals, and takeUntilDestroyed with DestroyRef are). Revisit them on the next major upgrade. Until then this is the norm, so do not introduce the newer patterns piecemeal.
|
C7 · Style: current permissive norm (keep, do NOT harden)
| Config | Setting (keep as-is) |
|---|---|
|
printWidth 120, single quotes, semis, trailingComma es5, |
|
2 spaces |
|
the existing rules |
Do not tighten tsconfig / eslint strictness as part of unrelated work: the permissive
norm is deliberate.
|
C8 · Contract FE↔BE
The Internal API Contract (UI↔BE) owns this rule. The Java standard states it identically (J8).
C9 · Tests
-
Specs next to the code (
*.spec.ts); name behaviourally (should … when …); group related cases. -
Test components / services / effects with the Angular testing utilities; mock HTTP at the
ApiServiceboundary. -
Coverage: new or changed code ≥ 80% diff coverage. Diff coverage is the share of added or changed lines and branches that tests run. Measure it with an lcov report and
diff-cover. There is no global gate. Cover behaviour (reducers as pure functions, effects with a mocked actions stream), not lines. -
Design first: a new feature (architecture-led) needs an approved design brief before implementation. ft-developer drafts the brief from the template (the file is
SDD.md) and the person running the session approves it. See Glossary: design brief, SDD. A bug fix is test-driven (TDD-led): write the failing test first.
C10 · Constants & enums
-
No magic numbers/strings: name them; group in a
*.const.tsor anas constobject. Prefer a stringenum(…Enum) or aconstunion over scattered literals. -
Route paths, NgRx action types, storage keys, error codes: single source of truth as constants, never re-typed inline.
-
Build/config values live in Angular
environment.*, not hard-coded constants.
C11 · Caching & client state
-
NgRx is the client cache: read from selectors; don’t re-fetch what’s already in the store. An HTTP call the store can answer is a bug.
-
Cache HTTP responses deliberately (interceptor / service) with a clear invalidation trigger; no unbounded caches.
-
Don’t duplicate server state in component fields: derive from selectors via the
asyncpipe.
C12 · External libraries
-
Prefer Angular / RxJS / the existing stack first; no second library for a job an existing one does (no extra date / HTTP / state libs). Mind bundle size.
-
A new dependency needs approval from the person running the session. Pin exact versions (lockfile). Respect licenses; avoid abandoned packages.
-
npm auditis part of "done" when dependencies change. Upgrade when it is safe. For each HIGH or CRITICAL finding that you cannot upgrade, open a Jira task with the CVE and a deadline, and link it from the PR. Never use--force.
C13 · Component & code discipline: code that stays readable
These are review norms, not CI gates. To exceed one, state the reason in the pull request.
| Threshold | Rule |
|---|---|
Component class ≤ 200 lines |
larger → split (child components, co-located |
≤ 7 `@Input`s |
more → group into a model object |
Method ≤ 40 lines · nesting ≤ 3 |
guard clauses / early return: same norm as the backend |
-
Smart/dumb split enforced (C6): dumb components take inputs and emit outputs: no store access, no HTTP.
-
Rule of Three: 2 duplicates → leave + mark
// DUPE:; the 3rd → extract (shared helper /ft-common). Look-alike blocks changing for different reasons are not duplicates. -
YAGNI applies to capabilities, never to quality: no speculative `@Input`s or generic wrappers without a second consumer; never an excuse to skip tests/error handling.
-
Comments say WHY, not what; no commented-out code, no dead exports in barrels.
-
Simplicity first (KISS): the simplest code that passes the tests and reveals intent: arrow functions and small pure helpers over stateless classes; the simplest RxJS chain that works (2–3 well-named operators beat a clever 7-operator one-liner); no abstractions/patterns (wrapper services, generic base classes) without a present second consumer; no clever one-liners that need a comment to decode; no premature optimization: measure first.
C14 · RxJS discipline
-
No nested
subscribe: compose with a flattening operator, chosen by semantics:
Operator |
When |
|
only the latest matters: typeahead, route params, reload |
|
ignore re-triggers while busy: form submit, login click (double-submit guard) |
|
every event matters, in order: queued writes |
|
independent parallel work (rare; justify the concurrency) |
-
catchErrorgoes INSIDE the inner stream of an effect: on the flattened HTTP observable, returning a failure action. On the outer stream it kills the effect after the first error (it silently stops dispatching forever). -
No manual
subscribein components where theasyncpipe can unwrap (C4/C6); a manual subscription always pairs withtakeUntil(destroy$). -
Multicast expensive shared streams deliberately:
shareReplay({ bufferSize: 1, refCount: true }): instead of re-triggering the source per subscriber.
C15 · Templates & rendering performance
-
trackByon every*ngForover changing data: without it OnPush re-creates the DOM per emission. -
No function calls in template expressions (
{{ compute(x) }}): they run every change-detection cycle; precompute in the component/selector or use a pure pipe. Derive view state in memoized NgRx selectors, not getters. -
Lazy-load feature routes (
loadChildren): a new feature module ships lazy by default. -
Heavy lists: CDK virtual scroll before pagination hacks; images sized/lazy.
C16 · Security baseline (frontend)
| Violations here are blocking review findings, not style notes. |
-
No
[innerHTML]/bypassSecurityTrustwith user- or device-supplied content*: Angular sanitizes interpolation by default; don’t opt out. A genuine rich-HTML need goes through the sanitizer and a review. -
Secrets never reach the bundle:
environment.*.tsholds endpoints and flags: no API keys/credentials (everything in the bundle is public). Never log tokens/credentials via the app logger (C5). -
No
eval/new Function/ dynamic<script>injection. -
External links with
target="_blank"carryrel="noopener noreferrer". -
The auth/session storage scheme follows the repo’s established mechanism: moving tokens between localStorage/cookie/memory is an architecture decision for the person running the session, not a drive-by "fix".
Review checklist
-
New file in a feature folder by role, exported via the barrel: not the app root
-
readonly / immutable models & NgRx state (spread, no in-place mutation)
-
Constructor injection; components OnPush;
destroy$+takeUntil -
FE logs via the app logger as
key=value(serial,deviceId); right level, no per-render noise / strayconsole.log -
Naming:
.component.ts/.service.ts…; interfacesI-prefixed;camelCasevars, verb methods; enums end…Enum -
No magic numbers/strings; constants/
as const/enum; reads from NgRx store (no needless re-fetch) -
New code ≥ 80% diff coverage; new dependency justified + pinned +
npm audit-clean; no duplicate-purpose lib -
Style left at the current permissive norm
-
Internal API (UI↔BE) contract matches the backend exactly
-
Size discipline: component ≤ 200 lines / ≤ 7 inputs; methods ≤ 40 lines, nesting ≤ 3; dumb components have no store/HTTP
-
Simplicity: pure helpers over stateless classes; simplest RxJS chain that works; no abstractions without a second consumer; no clever one-liners
-
RxJS: no nested subscribes; right flattening operator (
exhaustMapsubmits /switchMaplatest-wins /concatMapordered);catchErrorinside the effect’s inner stream -
Templates:
trackByon everyngFor; *no function calls in template expressions; new features lazy-loaded -
Security: no
[innerHTML]/bypassSecurityTrust*on user content; no secrets inenvironment.*/bundle; noeval;rel="noopener"on_blank
| Next: the shared Internal API Contract (UI↔BE) and the Java standard. |