The CLI, project anatomy, and standalone bootstrapping

Intermediate · 11 min

What `ng new` actually generates, and how a modern Angular app boots without an `app.module.ts`.

Before thisWhat Angular is, and how it's put together

Loiane Groner · 11 min

The CLI, project anatomy, and standalone bootstrapping

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Loiane GronerReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A modern Angular app boots through `bootstrapApplication(AppComponent, config)` in `main.ts` — there's no root `NgModule` to find.
  • `app.config.ts` is where you register the app-wide providers (router, HTTP client, and so on) that used to live in `app.module.ts`'s `providers` array.
  • The CLI's generated file tree is small on purpose — `ng generate` exists so you rarely hand-write boilerplate for a new component, service, or route.

Every app needs a starting point

Somewhere, some piece of code has to be first — the thing that says “render this component into that DOM node, and here’s what it’s allowed to use.” In a hand-rolled script you’d write that yourself: grab an element, construct your root object, attach it. Angular needs the same thing, just with more machinery behind it, because “render this component” also has to set up dependency injection, wire the router, and register whatever global services your app depends on before a single pixel draws.

That starting point is main.ts, and what it calls is bootstrapApplication.

Reading main.ts for what it actually does

A freshly generated project’s main.ts looks close to this:

import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';

bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));

Read it literally: “take this root component, boot it with this configuration.” AppComponent is just a normal, standalone component — nothing marks it as special beyond being the one you handed to bootstrapApplication. The configuration is the interesting part. It’s an ApplicationConfig object, usually defined in a sibling file, app.config.ts:

export const appConfig: ApplicationConfig = {
  providers: [provideRouter(routes), provideHttpClient(), /* ...more */],
};

If you’ve used Angular before the standalone era, that providers array is where your instincts should go looking. It’s doing the same job app.module.ts’s imports: [RouterModule.forRoot(routes), HttpClientModule] used to do — registering the router and the HTTP client so the rest of the app can inject them. The provideX() functions (provideRouter, provideHttpClient, provideAnimations, and more) are each a small factory that returns the providers a particular Angular feature needs, instead of a monolithic module import.

This lesson’s video walks through exactly this file, built from a blank ng new project — watch it with the main.ts → app.config.ts → AppComponent chain in mind, since that’s the whole story of how the app comes alive.

What ng new hands you, and why it’s small

Run ng new my-app and you get a deliberately minimal tree: main.ts, app.config.ts, app.routes.ts, and a root AppComponent with its template, styles, and spec file. That’s close to the entire skeleton. Everything else — a new component, a new service, a new route — you generate as you need it with ng generate component, ng generate service, and so on (or their ng g c / ng g s shorthands).

The CLI isn’t just a convenience here; it’s enforcing consistency. A component you generate gets its files named and wired the same way every other component in every other Angular project does — same decorator shape, same spec-file boilerplate, same folder convention. That consistency is the same instinct behind shipping router and forms as part of the platform (from the previous lesson), applied at the level of a single file generator instead of a whole package.

Standalone by default means no module to hunt for

If you’re coming from an older Angular codebase, the biggest shock in a new project is what’s missing: there’s no app.module.ts, no declarations array listing every component, no NgModule decorator anywhere near the root. Every component generated by a current-version CLI is standalone by default — it declares its own imports (other components, directives, pipes it uses) directly on itself, rather than relying on a module to have already declared them.

That’s not a cosmetic change. It means a component is a self-contained, portable unit: you can see everything it depends on by reading its own decorator, without tracing back to find which module happened to declare it. The next lesson covers NgModule properly — what it did, and why you’ll still run into it in any codebase older than a couple of years — but from here on, every example in this roadmap assumes the standalone, bootstrapApplication-based setup you just read.

Check yourself

  1. 01In a standalone Angular app, what does `main.ts` actually call to get the app running?

    It calls `bootstrapApplication(AppComponent, appConfig)`, passing the root component directly and an `ApplicationConfig` object (usually imported from `app.config.ts`) that supplies the app-wide providers.

  2. 02Where did the providers that used to sit in `app.module.ts` go?

    Into `app.config.ts`, inside the `providers` array of an `ApplicationConfig` object — things like `provideRouter(routes)` or `provideHttpClient()` replace the old `imports: [RouterModule.forRoot(routes), HttpClientModule]`.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark