Project Structure

An Angular project starts at src/main.ts, which starts the App component with the settings in app.config.ts. index.html holds the <app-root> tag that App fills. Your code lives in src/app; angular.json and package.json configure the build.

Novice · Angular · Updated

After this lesson you can

  • Find your way around an Angular project, from main.ts and index.html to the App component

Key takeaways

  • index.html is the one page the browser loads, and its <app-root> tag is where Angular puts the app.
  • main.ts is where the app starts, like Program.cs: bootstrapApplication starts the App component with the providers in app.config.ts.
  • Your code lives in src/app, where app.ts, app.html and app.css are the App component's class, template and styles.
  • Never edit or commit node_modules: npm install recreates it, so a fresh clone needs npm install before ng serve.

Here's what ng new created:

northwind-angular/
├── node_modules/          the downloaded packages
├── public/                files copied as they are, such as favicon.ico
├── src/
│   ├── app/
│   │   ├── app.ts         the App component's class
│   │   ├── app.html       its template
│   │   ├── app.css        its styles
│   │   ├── app.spec.ts    its tests
│   │   ├── app.config.ts  the app's settings
│   │   └── app.routes.ts  its pages, for routing
│   ├── index.html         the one HTML page
│   ├── main.ts            where the app starts
│   └── styles.css         styles for the whole app
├── angular.json           how the CLI builds and serves the app
├── package.json           the npm packages and scripts
└── tsconfig.json          TypeScript's settings

You'll spend nearly all your time in src/app.

How the app starts

src/index.html is the single page the browser loads. Its body holds one tag:

<body>
  <app-root></app-root>
</body>

<app-root> isn't real HTML: it's the place where Angular puts the app.

src/main.ts is where the app starts, like Program.cs:

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

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

bootstrapApplication starts the App component, the root of everything, with the settings in appConfig. Angular finds <app-root> in the page, and puts App there.

src/app/app.config.ts holds those settings, as a list of providers: services the app can use, much like builder.Services in ASP.NET Core:

import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
  providers: [
    provideBrowserGlobalErrorListeners(),
    provideRouter(routes)
  ]
};

You'll add to this list later, for example to switch on router features and HTTP interceptors.

src/app/app.ts, app.html and app.css are the App component itself: a TypeScript class, its HTML, and its styles. app.html starts with Angular's welcome page; you'll replace it with your own.

The other files

File What it's for Like in .NET
package.json The npm packages the app uses, and scripts such as npm start The .csproj
node_modules/ The packages themselves. Never edit or commit it: npm install recreates it. The NuGet package cache
angular.json How the CLI builds the app: the styles, the output folder, the settings for each environment Project settings
tsconfig.json TypeScript's settings, strict by default Compiler settings
public/ Files copied into the app as they are: icons, images wwwroot
*.spec.ts Tests, run with ng test A test project

.gitignore already leaves out node_modules, so a fresh clone of the project needs npm install before ng serve.

Check yourself

1 question to try on the lesson page.

So what

index.html has the spot, main.ts starts App with app.config.ts's settings, and everything you build grows out of App, inside src/app.

Key terms

Cheat sheets