Monday, 6 October 2025

Angular Application Structure

low-level Angular architecture diagram showing what happens internally when you create and run an app (ng new sampleapp + ng serve), and how execution flows through files like main.ts, app.module.ts, app.component.ts, app.html, etc., especially where debugging breakpoints (step over, step into) are effective.

Here’s a detailed breakdown and flow + diagram explanation 👇


🧩 1. Angular Application Structure (after ng new sampleapp)

sampleapp/ ├── src/ │ ├── main.ts │ ├── index.html │ ├── styles.css │ ├── app/ │ │ ├── app.module.ts │ │ ├── app.component.ts │ │ ├── app.component.html │ │ ├── app.component.css │ │ ├── app.routes.ts (or app-routing.module.ts) │ │ ├── app.component.spec.ts ├── angular.json ├── package.json ├── tsconfig.json

⚙️ 2. Runtime Flow (Execution Order)

(A) ng serve

  • Compiles and serves your Angular app in development mode.

  • Uses Webpack Dev Server to bundle TS → JS → browser.


(B) main.ts

Entry Point

platformBrowserDynamic() .bootstrapModule(AppModule) .catch(err => console.error(err));

👉 Starts the Angular app by bootstrapping AppModule.

🟩 Breakpoints:
Set breakpoints here to debug initial app bootstrap (first executed file).


(C) app.module.ts

Root Module Definition

@NgModule({ declarations: [AppComponent], imports: [BrowserModule, AppRoutingModule], bootstrap: [AppComponent] }) export class AppModule {}

👉 Registers components and modules.

🟩 Breakpoints:
Place in constructor or ngOnInit() (if any service injected).


(D) app.component.ts

Root Component

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'sampleapp'; constructor() { } ngOnInit() { console.log('AppComponent loaded'); } }

🟩 Breakpoints:

  • constructor()

  • ngOnInit()
    This is where runtime logic starts when UI is rendered.


(E) app.component.html

Template for AppComponent

<h1>{{ title }}</h1> <router-outlet></router-outlet>

👉 UI rendering happens here.

🟩 Breakpoints:
No TS breakpoints — but inspect DOM via browser DevTools.


(F) app.routes.ts (or app-routing.module.ts)

Routing setup

const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'about', component: AboutComponent } ];

👉 Controls navigation paths.

🟩 Breakpoints:
In constructor of routed components or ngOnInit().


(G) app.spec.ts

Unit Testing File

describe('AppComponent', () => { it('should create the app', () => { ... }); });

👉 Runs only during testing (ng test), not ng serve.


(H) index.html

Root HTML

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

👉 Angular replaces <app-root> with AppComponent content.


(I) styles.css

Global Styles

Affects all components (like body font, layout, etc.).


🧠 3. Debugging Step-by-Step (VS Code)

🧩 To enable debugging:

  1. Open project in VS Code

  2. Go to Run → Add Configuration → Chrome Launch

  3. It creates .vscode/launch.json

  4. Run app: ng serve

  5. Press F5 to launch debugger

🟩 Set breakpoints in:

  • main.ts → Entry point

  • app.module.ts → Module load

  • app.component.ts → Component init

  • Any other service or lifecycle hook

Use Step Over (F10), Step Into (F11), Continue (F5).


📊 4. Low-Level Angular Flow Diagram (Text Version)

Browser loads index.html │ ▼ main.ts (bootstrap Angular) │ ▼ AppModule initialized │ ▼ AppComponent created │ ▼ app.component.html rendered │ ▼ Routing activated (if any) │ ▼ Other components load (as per routes) │ ▼ UI displayed and ready for interaction

If you’d like, I can generate a professional diagram (with arrows, modules, and lifecycle flow) showing exactly:

  • Entry points (main.ts → AppModule → AppComponent)

  • Routing

  • HTML/CSS connection

  • Debugging breakpoint icons (🟥 for active breakpoints)