Angular Project Structure
ng new creates a workspace: a folder with configuration files at the top and your application code inside src/. Knowing which file does what makes the rest of the course much easier to follow.
The workspace at a glance
task-board/
├── angular.json ← build, serve and test configuration for the CLI
├── package.json ← npm dependencies and scripts
├── tsconfig.json ← TypeScript compiler settings
├── public/ ← static files copied as-is (favicon, images)
└── src/
├── index.html ← the single HTML page the browser loads
├── main.ts ← entry point: starts the app
├── styles.css ← global styles
└── app/
├── app.ts ← the root component class
├── app.html ← its template
├── app.css ← its styles
├── app.spec.ts ← its unit tests
├── app.config.ts ← application-wide providers
└── app.routes.ts ← the route tableHow the app starts
The browser first loads index.html. It contains a custom element that does nothing on its own:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>TaskBoard</title>
<base href="/" />
</head>
<body>
<app-root></app-root>
</body>
</html>The CLI injects the compiled JavaScript, which begins in main.ts:
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 creates the root component App, finds the element matching its selector (app-root) and renders the component inside it. Everything else in the app is a descendant of this component.
The root component
// src/app/app.ts
import { Component, signal } from '@angular/core';
import { RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
imports: [RouterOutlet],
templateUrl: './app.html',
styleUrl: './app.css',
})
export class App {
protected readonly title = signal('task-board');
}
// src/app/app.html
// <h1>Welcome to {{ title() }}</h1>
// <router-outlet />templateUrl and styleUrl point to separate files; for very small components you can use inline template and styles instead. <router-outlet /> is where routed pages will appear later.
Application configuration
app.config.ts lists providers — services and features available to the whole app:
import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZonelessChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideZonelessChangeDetection(),
provideRouter(routes),
],
};Each provideX() function switches on a feature. You will add provideHttpClient() in the HttpClient lesson, for example.
Typed configuration objects
ApplicationConfig is just a TypeScript interface. The same pattern — a typed object with an array of entries — is easy to reproduce in plain TypeScript:
interface Provider {
feature: string;
enabled: boolean;
}
interface AppConfig {
providers: Provider[];
}
const config: AppConfig = {
providers: [
{ feature: 'router', enabled: true },
{ feature: 'http', enabled: false },
{ feature: 'zoneless', enabled: true },
],
};
const active = config.providers.filter((p) => p.enabled).map((p) => p.feature);
console.log('Active features:', active.join(', '));
console.log('Total providers:', config.providers.length);Active features: router, zoneless
Total providers: 3
package.json scripts
The CLI commands are also exposed as npm scripts, so npm start and ng serve do the same thing:
{
"name": "task-board",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test"
},
"private": true
}Valid JSON: object with 3 keys
{
"name": "task-board",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test"
},
"private": true
}
Which file should I edit?
| I want to… | Edit |
|---|---|
| Change what the home page shows | src/app/app.html |
| Add global fonts or a CSS reset | src/styles.css |
| Register a service or feature app-wide | src/app/app.config.ts |
| Add a page with its own URL | src/app/app.routes.ts |
Change the page <title> or add meta tags |
src/index.html |
| Change build options or budgets | angular.json |
Tip: You rarely touch
angular.jsonby hand. Commands likeng addupdate it for you.
Test yourself
Which file contains the call to bootstrapApplication?
- index.html
- app.ts
- main.ts
- angular.json
Why does index.html contain <app-root></app-root>?
- It is a placeholder that the root component with selector
app-rootrenders into - It loads the router
- It is required by HTML5
- It imports styles.css
Where do you register providers that the whole application can use?
- styles.css
- app.config.ts
- tsconfig.json
- app.spec.ts