← All posts

Migrate Angular Material to your design system, safely

Move an Angular app off Angular Material in small batches: measure usages, map components, block new imports and let an AI agent do the edits.

Thiago Baptistella · · 5 min read

Most Angular teams with a design system have the same problem: the design system is new, the apps are not. The newer screens use your Button and TextField. The older ones are full of mat-raised-button, <mat-form-field> and <mat-table>, themed to look roughly like your brand, and every quarter someone asks how far along the migration is. Nobody has a number.

A big-bang rewrite rarely works. The app keeps shipping while you migrate, Material keeps getting new usages, and the branch goes stale. What works is boring: measure, map, block new usages, then move a few files at a time. This guide shows how to do that with plain tools, and how an AI coding agent can do most of the editing without changing behaviour.

Step 1: Measure what's left

You can't plan a migration you can't count. Start with an inventory of Material elements and directives in your templates:

# Material elements, most used first
grep -rhoE "<mat-[a-z-]+" src --include=*.html --include=*.ts | sort | uniq -c | sort -rn

# Material buttons, inputs and tooltips used as attributes
grep -rhoE "mat-(raised-|flat-|stroked-|icon-)?button|mat-mini-fab|mat-fab|matInput|matTooltip|matBadge" \
  src --include=*.html --include=*.ts | sort | uniq -c | sort -rn

# Files that still import Material modules
grep -rlE "@angular/material" src --include=*.ts | wc -l

Include .ts files because standalone and older components often have inline templates. Save the output with a date. Run it again every week and you have a progress number that leadership can follow.

Then list the files with the most work, so you can pick batches:

grep -rcE "<mat-|mat-[a-z-]*button|matInput" src --include=*.html \
  | grep -v ":0$" | sort -t: -k2 -rn | head -20

Step 2: Map every Material piece to your component

Write the mapping down before anyone touches code. It's the document your developers and your AI tools will both follow. Keep it in the repo, for example docs/migration-map.md:

  • mat-raised-button, mat-flat-button, mat-stroked-button → <ds-button variant="primary|secondary|outline">
  • mat-icon-button → <ds-button variant="ghost" icon-only> with an aria-label
  • <mat-form-field> + matInput → <ds-text-field label="…">
  • <mat-select> → <ds-select>
  • <mat-checkbox>, <mat-radio-group>, <mat-slide-toggle> → <ds-checkbox>, <ds-radio-group>, <ds-switch>
  • <mat-card> → <ds-card>
  • <mat-tab-group> → <ds-tabs>
  • <mat-table> → <ds-table> (usually the biggest single job)
  • matTooltip → <ds-tooltip>
  • <mat-spinner>, <mat-progress-bar> → <ds-spinner>, <ds-progress>

For each line, note what doesn't map one to one. Material's form field shows errors from the form control's state; your text field may need an error input. A Material dialog is opened from a service; yours may be a component in the template. These are the places where a migration quietly breaks behaviour, so write them down.

Decide what "done" means for a file

A file is migrated when it has no Material elements, no Material imports and no hard-coded colours or spacing left from the old theme overrides. That last part matters: teams often remove mat-card but keep a .card { padding: 18px; background: #f5f7fa } that came with it.

Step 3: Stop new usages first

Before migrating anything, make sure nobody adds more Material. In an Angular project with ESLint, restrict the imports:

{
  "rules": {
    "no-restricted-imports": ["error", {
      "patterns": [{
        "group": ["@angular/material", "@angular/material/*"],
        "message": "Use the design system component instead. See docs/migration-map.md."
      }]
    }]
  }
}

Material components can only be used in a template if their module is imported in TypeScript, so this catches new usages in standalone components and new modules. Existing files will fail too, so either list them in an overrides block with the rule off, or run the lint only on changed files in CI. The point is that the count only goes down from here.

Step 4: Migrate in small batches

Pick three to five files from your list, ideally from one feature folder, and migrate them in one pull request. Small batches keep reviews honest: a reviewer can open the page before and after and check that forms still validate, buttons still submit and keyboard focus still works.

For each file:

  1. Replace the template elements using your map.
  2. Remove the Material module imports from the component or its module.
  3. Delete the theme overrides that only existed to style Material.
  4. Run the unit tests and click through the screen.

This is where AI coding agents help most. The work is repetitive and well specified, which suits Claude Code or Cursor, as long as you give them the map and the rules. A prompt that works:

Migrate src/app/orders/order-form.component.* to our design system.
Follow docs/migration-map.md exactly. Keep behaviour identical: events,
validation messages, disabled states, aria attributes and keyboard order.
Don't change any other file. Use only tokens from src/styles/tokens.css,
never hex values. When done, list anything you couldn't map.

Then rerun your inventory commands on the files it touched. If a mat- tag or a hex colour is still there, send it back.

Where the do-it-yourself version runs out

The grep inventory doesn't know your components, so it can't tell you whether the new code uses them correctly. The map lives in a Markdown file the agent may or may not read. And when you have several apps, some in React or with PHP templates next to Angular, you end up maintaining one script per repo.

The same migration with Brandrail

Brandrail does these four steps with your actual Brand Kit and component registry. In the repo:

npx brandrail connect
npx brandrail migrate

connect signs you in through the browser, writes the rule files for Claude Code, Cursor, Copilot and other tools, and sets up the local MCP server. migrate shows how much of the app is on the design system, usages left per library (Angular Material, MUI, Bootstrap, Ant, Chakra, PrimeNG) and the files with the most work. Use --top 30 for a longer list or --json for CI.

For the editing, connect also installs a brandrail-migrate skill and a migrator agent for Claude Code. Ask it:

Migrate src/app/orders to the design system.

The agent works a few files at a time, maps each Material piece to your component through the get_migration_map MCP tool, keeps events, validation and accessibility the same, and re-checks every file it touched against the Checker's rules. Other AI tools get the same instructions through AGENTS.md and the MCP server. The server runs on your machine, so the code doesn't leave it.

To stop new usages, add Material to forbiddenImports in brandrail.config.json. Setting the list replaces the defaults, so keep any other libraries you still want blocked:

{
  "forbiddenImports": ["@angular/material", "@mui/material", "bootstrap"]
}

The Checker then fails pull requests that add new Material imports, while the existing ones are migrated. And when someone asks how far along you are:

npx brandrail report

That writes a shareable HTML handover report with paths and counts, never code.

Try it

Run npx brandrail migrate in an Angular repo to see what's left. The free plan covers one repo, three people and 100 checks a month. When you want the agent to do the edits, run npx brandrail connect and ask it to migrate one feature folder.