DFD
Programmers Picnic
AI-ML Classes by Champak Roy
Angular Design Lesson

Angular DFD: Data Flow Diagram from Level 0 to Infinity

Learn how data moves inside an Angular application: from user action to component, from component to service, from service to API, from API back to UI, and finally into scalable expert architecture.

Start Lesson

Lesson Goal

This lesson teaches DFD for Angular. Here DFD means both:

Data Flow Diagram A visual diagram showing how data moves.
Data Flow Design A planning method for Angular apps.
Debugging Map A way to trace bugs from UI to API and back.
Final goal: before writing Angular code, you should be able to draw how the data will move.

1. Level 0 Meaning

A DFD shows where data comes from, where it goes, where it is processed, and where it is stored.

Simple idea: In Angular, data usually starts from the user or API. Then it moves through components, services, routes, stores, and templates.

Example

Suppose a student clicks a button called Load Courses. What happens?

  1. User clicks the button.
  2. Angular component receives the click event.
  3. Component calls a service.
  4. Service calls an API.
  5. API sends course data.
  6. Component receives data.
  7. HTML template displays courses.
User Click
  ↓
Component Method
  ↓
Service Method
  ↓
API Call
  ↓
Response Data
  ↓
Component Property
  ↓
HTML Template

2. Why DFD Is Important in Angular

Angular apps can become confusing when components, services, forms, routes, API calls, and state management are mixed without planning.

Without DFD With DFD
Students write code randomly. Students know where data should go.
API logic is placed inside components. API logic is placed inside services.
Parent and child components become confusing. Inputs and outputs are clear.
Debugging takes a long time. Bugs can be traced step by step.
Large projects become messy. Large projects can be divided into features.
DFD is useful before coding, during coding, during debugging, and during project explanation.

3. DFD Symbols for Angular

Traditional DFD has external entities, processes, data stores, and data flows. For Angular, we can map them to real Angular parts.

DFD Symbols Mapped to Angular External Entity User, Browser, API Process Component Service Business/API logic Data Flow Data Store State, Local Storage, DB Template HTML View
DFD Symbol Angular Meaning Example
External Entity Something outside the Angular app. User, API server, browser storage.
Process Where data is changed or handled. Component method, service method.
Data Store Where data is saved. Component property, signal, store, localStorage, database.
Data Flow Movement of data. Click event, HTTP response, input binding.

4. Context Diagram: Angular App as One System

A context diagram is the highest-level DFD. It shows the Angular app as one box.

Context DFD: Angular App as One System User clicks, forms Angular App components, services routes, state API Server data source Storage token, cache User input UI output HTTP request JSON response save token
Context DFD does not show every component. It only shows the Angular app as one complete system.

5. Level 1 DFD: Break Angular App into Parts

Level 1 DFD opens the Angular app box and shows its main internal parts.

Level 1 Angular DFD User actions Component UI logic Service business logic API server data Store app state View HTML event method call HTTP data save state bind component property to template

6. Angular Internal Data Flow

This is the basic Angular internal flow.

HTML Template
  ↓ user event
Component Class
  ↓ calls
Service
  ↓ calls
API
  ↓ returns
Service
  ↓ returns
Component Class
  ↓ binding
HTML Template

Example: Button Click to Data Display

Input Data User clicks a button.
Output Data Courses appear on the screen.

Component HTML

<button (click)="loadCourses()">Load Courses</button>

<ul>
  @for (course of courses; track course.id) {
    <li>{{ course.title }}</li>
  }
</ul>

Component TypeScript

import { Component } from '@angular/core';

@Component({
  selector: 'app-courses',
  templateUrl: './courses.html',
  styleUrl: './courses.css'
})
export class Courses {
  courses = [
    { id: 1, title: 'Angular Level 0' },
    { id: 2, title: 'Angular Components' },
    { id: 3, title: 'Angular Services' }
  ];

  loadCourses() {
    console.log('Courses loaded');
  }
}

7. Component Data Flow

In Angular, a component has two main sides:

Template Side HTML, bindings, buttons, input fields, lists.
Class Side Variables, functions, conditions, service calls.
Style Side CSS that makes the component look good.
Data Flow Inside One Component Template app.html clicks, forms, bindings Class app.ts properties, methods Event Binding: click, input, submit Property Binding and Interpolation

Four Important Binding Types

Binding Direction Example
Interpolation Class to template {{ title }}
Property binding Class to template [src]="imageUrl"
Event binding Template to class (click)="save()"
Two-way binding Template to class and class to template [(ngModel)]="name"

8. Parent to Child and Child to Parent Data Flow

Angular components often communicate with each other.

Parent Child Data Flow Parent Component owns data handles events Child Component receives input emits output @Input data @Output event

Parent HTML

<app-student-card
  [student]="selectedStudent"
  (removeStudent)="onRemoveStudent($event)">
</app-student-card>

Child TypeScript

import { Component, EventEmitter, Input, Output } from '@angular/core';

@Component({
  selector: 'app-student-card',
  templateUrl: './student-card.html',
  styleUrl: './student-card.css'
})
export class StudentCard {
  @Input() student: any;

  @Output() removeStudent = new EventEmitter();

  remove() {
    this.removeStudent.emit(this.student.id);
  }
}
Parent to child uses @Input. Child to parent uses @Output.

9. Form Data Flow

Form data flow is very important in Angular because users enter data through forms.

User types in form
  ↓
Form control receives value
  ↓
Component validates data
  ↓
Component calls service
  ↓
Service sends data to API
  ↓
API stores data
  ↓
Success message appears
Angular Form Data Flow User types data Form controls Component validation Service send API save

Reactive Form Example

import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';

@Component({
  selector: 'app-student-form',
  imports: [ReactiveFormsModule],
  templateUrl: './student-form.html'
})
export class StudentForm {
  studentForm = new FormGroup({
    name: new FormControl(''),
    email: new FormControl('')
  });

  submitForm() {
    console.log(this.studentForm.value);
  }
}

Form HTML

<form [formGroup]="studentForm" (ngSubmit)="submitForm()">
  <input formControlName="name" placeholder="Student name" />
  <input formControlName="email" placeholder="Email" />

  <button type="submit">Save Student</button>
</form>

10. Routing Data Flow

Routing data flow means how the URL decides which Angular page should be shown.

Browser URL
  ↓
Angular Router
  ↓
Route Match
  ↓
Page Component
  ↓
Template Display

Route Example

import { Routes } from '@angular/router';

export const routes: Routes = [
  {
    path: '',
    loadComponent: () =>
      import('./pages/home/home').then(m => m.Home)
  },
  {
    path: 'courses',
    loadComponent: () =>
      import('./pages/courses/courses').then(m => m.Courses)
  }
];

Router Outlet

<app-header></app-header>

<router-outlet></router-outlet>

<app-footer></app-footer>
router-outlet is the place where Angular displays the currently selected page.

11. API Data Flow

Most real Angular apps get data from APIs. The service should handle API calls.

API Data Flow in Angular Component asks for data Service API logic HttpClient request Backend API JSON response Response returns to component and updates UI

Service Example

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class CourseService {
  private apiUrl = 'https://example.com/api/courses';

  constructor(private http: HttpClient) {}

  getCourses() {
    return this.http.get(this.apiUrl);
  }
}

Component Example

import { Component } from '@angular/core';
import { CourseService } from './course.service';

@Component({
  selector: 'app-courses',
  templateUrl: './courses.html'
})
export class Courses {
  courses: any[] = [];

  constructor(private courseService: CourseService) {}

  loadCourses() {
    this.courseService.getCourses().subscribe((data: any) => {
      this.courses = data;
    });
  }
}

12. Service Layer Data Flow

Services are used to keep components clean. A component should focus on UI. A service should focus on data and business logic.

Layer Responsibility Should Not Do
Component Display data and handle UI events. Should not contain complex API rules.
Service Fetch, save, transform, and share data. Should not contain page layout HTML.
API Store and return server data. Should not know Angular component design.

Clean Service Pattern

Component asks:
  "Please give me courses."

Service decides:
  "I know where courses come from."

API responds:
  "Here is the course data."

Component says:
  "I will display it."

13. State Management Data Flow

State means data that the app remembers while running.

Local State Data used inside one component.
Shared State Data used by many components.

Simple State Example

export class Counter {
  count = 0;

  increase() {
    this.count++;
  }
}

Shared State with Service

import { Injectable, signal } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class AppStateService {
  userName = signal('Guest');

  setUserName(name: string) {
    this.userName.set(name);
  }
}
Shared State Data Flow Header shows username State Service single source of shared data Profile updates username reads updates

14. Authentication DFD

Authentication data flow is used when a user logs in.

Login Form
  ↓ email and password
Auth Component
  ↓
Auth Service
  ↓
Login API
  ↓ token
Auth Service
  ↓ save token
Local Storage / State
  ↓
Router redirects to Dashboard

Auth Service Sketch

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  login(email: string, password: string) {
    // call API here
  }

  saveToken(token: string) {
    localStorage.setItem('token', token);
  }

  getToken() {
    return localStorage.getItem('token');
  }

  logout() {
    localStorage.removeItem('token');
  }
}
Never store sensitive private secrets in frontend code. Frontend code is visible to users after deployment.

15. CRUD DFD

CRUD means Create, Read, Update, Delete. Most admin dashboards use CRUD.

Action User Does Angular Does API Does
Create Submits new form. Sends POST request. Saves new record.
Read Opens list page. Sends GET request. Returns records.
Update Edits existing item. Sends PUT/PATCH request. Updates record.
Delete Clicks delete. Sends DELETE request. Deletes record.

CRUD Service Skeleton

export class StudentService {
  getStudents() {
    // GET /students
  }

  getStudentById(id: number) {
    // GET /students/:id
  }

  createStudent(student: any) {
    // POST /students
  }

  updateStudent(id: number, student: any) {
    // PUT /students/:id
  }

  deleteStudent(id: number) {
    // DELETE /students/:id
  }
}

16. DFD to Angular Folder Map

A good DFD helps decide folder structure.

src/app/
├── core/
│   ├── auth/
│   ├── interceptors/
│   └── services/
│
├── shared/
│   ├── components/
│   ├── pipes/
│   └── directives/
│
├── features/
│   ├── students/
│   │   ├── pages/
│   │   ├── components/
│   │   ├── services/
│   │   ├── models/
│   │   └── students.routes.ts
│   │
│   └── courses/
│       ├── pages/
│       ├── components/
│       ├── services/
│       ├── models/
│       └── courses.routes.ts
│
├── app.config.ts
├── app.routes.ts
└── app.ts
DFD Element Angular Folder/File Example
External entity API service or auth service course.service.ts
Process Component or service method loadCourses()
Data store State service, signal, localStorage app-state.service.ts
Data flow Binding, route, HTTP, event (click), http.get()

17. Expert-Level Angular DFD

Expert Angular DFD includes feature modules, lazy routes, guards, interceptors, state management, API boundaries, caching, error handling, and deployment.

Expert Angular DFD User browser Router lazy routes Feature Page dashboard Guard auth check State signals/store Service business logic Interceptor token/errors Backend API server Database persistent data

Expert Checklist

18. Common DFD Mistakes

Mistake Problem Better Design
Putting API calls directly everywhere Code becomes repeated and hard to debug. Use services.
Child directly changes parent data Data flow becomes confusing. Use @Input and @Output.
Every component stores its own copy of shared data Data becomes inconsistent. Use shared state service.
No loading or error flow User does not know what is happening. Add loading, success, and error states.
Component does too much Component becomes huge. Move logic into services.
No route planning Navigation becomes messy. Plan routes and pages first.

19. Student Assignment

Design a DFD for a Student Dashboard Angular app.

App Features

Required DFDs

Expected Folder Structure

src/app/
├── core/
│   ├── auth/
│   │   ├── auth.service.ts
│   │   └── auth.guard.ts
│   └── interceptors/
│
├── shared/
│   └── components/
│       ├── header/
│       └── footer/
│
├── features/
│   ├── dashboard/
│   └── students/
│       ├── pages/
│       ├── components/
│       ├── services/
│       └── models/
│
├── app.routes.ts
├── app.config.ts
└── app.ts
Final learning: DFD is not only a diagram. It is the thinking process behind clean Angular architecture.

Final Summary

Question Answer
What is Angular DFD? A diagram and design method for showing how data moves in an Angular app.
Where does user data start? Usually from a click, input, route, or form.
Where should API logic go? Inside services.
How does parent send data to child? Using @Input.
How does child send event to parent? Using @Output.
Where does route data flow? URL → Router → Route Match → Page Component → Template.
What is expert DFD? A complete architecture map with routes, guards, interceptors, services, state, API, and database.