01NgModules were doing two jobs

If you started with Angular recently, you may never have written an NgModule. It's a class with an @NgModule decorator that lists the components it declares and the other modules it imports, and a component's template could use anything its module made available. A standalone component lists its own imports instead. On current Angular, components are standalone unless they set standalone: false, which is why a migrated codebase mostly shows that flag disappearing.

In older Angular apps, NgModules handled compilation scope (which components a template could use) and, informally, architecture: a feature module was a boundary. Standalone components remove the first job entirely, because each component declares its own imports.

The second job doesn't disappear. If you delete the modules without replacing the boundaries, features slowly start importing each other's internals. A good standalone migration replaces modules with route-level boundaries and lint rules.

02How to run it

  1. 01

    Pass 1: convert declarations

    ng generate @angular/core:standalone with "Convert all components, directives and pipes to standalone". Commit. The app should build and behave identically.

  2. 02

    Pass 2: remove unnecessary modules

    Run the schematic again with "Remove unnecessary NgModule classes". Modules that only re-exported things disappear; review what's left by hand.

  3. 03

    Pass 3: bootstrap standalone

    The final pass switches main.ts to bootstrapApplication and moves root providers into an app.config.ts. Libraries that still ship an NgModule for setup can stay there, wrapped in importProvidersFrom().

  4. 04

    Go one folder at a time

    The schematic accepts a path option. On a large app, run all three passes on one feature folder, ship it, then move to the next. Small pull requests get reviewed properly; a 900-file one gets skimmed.

  5. 05

    Replace feature modules with route files

    Each feature exports a Routes array, lazy-loaded with loadChildren. Feature-level providers move onto the route's providers. If some routes are still eagerly loaded, the route-lazy-loading migration converts them.

  6. 06

    Trim the imports the schematic over-adds

    Generated components often import more than they use. Angular reports unused standalone imports as a warning, and ng generate @angular/core:cleanup-unused-imports removes them for you. common-to-standalone does the same job for blanket CommonModule imports.

  7. 07

    Kill the SharedModule

    A shared module that imports everything makes every component depend on everything. Import shared components individually instead.

03What replaces the module boundary

Without NgModules, the feature boundary is the folder plus its routes.ts. Everything a feature exposes goes through that routes file; nothing else is imported from outside the folder.

That rule only holds if a tool enforces it. An ESLint boundaries rule (or Nx's module-boundary rule, if you use Nx) turns "please don't import from another feature" into a failing build. I go through the full folder layout and the lint configuration in Structuring a Large Angular Codebase.

04A feature module, after

The old BillingModule with its routing module and providers becomes a single routes file. Providers scoped to the feature move to the parent route, so they're created when the feature loads and shared by its children.

features/billing/billing.routes.ts
import { Routes } from '@angular/router';
import { BillingStore } from './billing.store';
import { InvoicesApi } from './invoices.api';

export default [
  {
    path: '',
    providers: [BillingStore, InvoicesApi], // was BillingModule.providers
    children: [
      { path: '', loadComponent: () => import('./invoice-list.component') },
      { path: ':id', loadComponent: () => import('./invoice-detail.component') },
    ],
  },
] satisfies Routes;

// app.routes.ts
{ path: 'billing', loadChildren: () => import('./features/billing/billing.routes') }

Two details make this file shorter than it looks. loadChildren and loadComponent both accept a module whose default export is the routes array or the component, so no .then((m) => m.X) is needed as long as each component file uses export default. And satisfies Routes type-checks the array without widening it.

One thing NgModules did implicitly is worth checking: lifetime. Services in a route's providers get their own injector, and Angular keeps that injector after the user leaves the feature unless you opt in to cleanup with withAutoCleanupInjectors() (stable since Angular 22.2). That's fine for an API client like InvoicesApi. For a store that should start fresh each visit, provide it on a feature shell component instead, as I describe in State Management Without Over-Engineering.

The takeaway

Let the schematic do the mechanical conversion in three committed passes, then do the part it can't: replace module boundaries with route files and a lint rule. Standalone makes Angular simpler, but only if the architecture survives the migration.

Sources

Written by Jaymin MahetaSenior UI/UX Developer turning Figma designs into fast, accessible enterprise apps in Angular and React.
About me →