Free tools Windows power users keep installed
One-click scans. No signup required.
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Angular schematics are code generators that create or modify project files. Run built-in generators with ng generate, or use a library’s schematics to install, configure, generate, or migrate code. A schematic works on a virtual project tree and stages file changes for validation before they are applied.
What Angular schematics do
A schematic is a set of instructions for transforming a software project: it can create, overwrite, rename, or delete files. Schematics are grouped into collections and typically distributed as npm packages. The Angular CLI runs generators from its default @schematics/angular collection as well as from library-provided collections. See Angular’s schematics overview.
These are developer-facing workspace transformations, not runtime features by themselves. The generated or changed files become ordinary project code that you should review, build, and maintain.
Run a schematic with Angular CLI
The general command is ng generate <schematic> [options], abbreviated ng g. Common built-in generators include components, services, directives, pipes, guards, and applications. A command such as ng generate component is shorthand for running the corresponding schematic in the default Angular collection.
#1 Best Overall
To invoke a named schematic from a particular collection, use ng generate collection:schematic. For example, a library may provide a generator that creates one of its own artifacts. The CLI reference documents generation syntax and options at ng generate.
Review changes before writing
For an initial check, add --dry-run (or -d) to report the schematic’s activity without writing changes:
Rank #2
ng generate component example --dry-run
Use --force only when you intend to permit overwriting existing files. It can replace work already in the workspace. The --interactive option controls prompts; check the command’s behavior and options before running a generator in a project with valuable local changes.
How a custom schematic works
Custom schematics are rules that transform a virtual Tree, a representation of project files. A rule receives that tree and returns a transformed tree. Rather than immediately editing the real workspace, the framework stages file actions and applies them after validation. That staging helps make transformations reviewable, but it does not remove the need to plan for collisions and overwrite behavior.
Rank #3
Collection, factory, and schema
A collection’s collection.json maps schematic names to descriptions, factory entry points, and optionally option schemas. The factory creates the rule that performs the transformation. A schematic’s schema.json describes accepted options, their types, and defaults; prompts can also ask users for values. Angular’s schematic authoring guide describes these pieces.
Templates and workspace-aware generation
When generated files need more than a fixed write operation, optional files in a files/ directory can serve as templates. A rule can pass option values into template filenames and contents. Library schematics can also read workspace information and place generated templates in the selected project, as shown in Angular’s guide to schematics for libraries.
Rank #4
Set defaults for workspace generators
Workspace-level schematic defaults can be configured in angular.json, keyed by schematic name. For example, a workspace can set a default option for @schematics/angular:component, so future component generation follows that preference. Consult Angular workspace configuration for the configuration format.
What libraries can automate
Library authors can integrate schematics with three CLI workflows. Which one matters depends on whether the library needs to set up a project, create repeatable artifacts, or adapt existing code:
| CLI workflow | Purpose | Example use |
|---|---|---|
ng add |
Install and configure a library | Angular’s documentation gives Angular Material setup, including theming, as an example. |
ng generate |
Create library-defined artifacts | Generate a component or service using the library’s templates and rules. |
ng update |
Update dependencies and run migrations | Apply project edits needed for a library change that might otherwise require manual work. |
Angular’s overview of schematics and its library schematics guide explain these integration points.
Quick Recap
Choose the right generation approach
- Use a built-in CLI schematic for standard Angular artifacts such as components and services; it is already available through the default collection.
- Use a library schematic when a package provides setup, a domain-specific artifact generator, or a migration tailored to its code.
- Prefer a schematic over repeated manual edits when the same file structure or project transformation must be applied consistently more than once.
- Start with a simple rule for straightforward file changes. Use templates and workspace-aware logic when output depends on options or the target project.
- Use dry-run during review to inspect the reported activity without writing it; do not treat it as a substitute for understanding potential collisions or checking the resulting code.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

