Angular Architecture ποΈ
Angular follows a component-based architecture where everything is organized around components, services, and modules. Hereβs how it all fits together.
ποΈ Application Structure
Section titled βποΈ Application StructureβV19 and below
src/βββ app/β βββ app.component.ts # Root componentβ βββ app.component.html # Root templateβ βββ app.component.css # Root stylesβ βββ app.config.ts # App configurationβ βββ main.ts # Bootstrap fileβββ assets/ # Static filesβββ environments/ # Environment configsV20 and above
src/βββ app/β βββ app.ts # Root componentβ βββ app.css # Root stylesβ βββ app.html # Root templateβ βββ app.config.ts # App configurationβ βββ app.routes.ts # App routesβ βββ main.ts # Bootstrap fileβββ assets/ # Static filesβββ environments/ # Environment configsπ§© Core Building Blocks
Section titled βπ§© Core Building BlocksβComponents
Section titled βComponentsβ- Purpose: UI building blocks that combine HTML, CSS, and TypeScript
- Structure: Each component has a class, template, and optional styles
- Example: A header, sidebar, or product card
Services
Section titled βServicesβ- Purpose: Share data and logic across components
- Structure: Injectable classes that handle business logic
- Example: API calls, data storage, authentication
Modules (Traditional)
Section titled βModules (Traditional)β- Purpose: Group related components, services, and other code
- Structure:
@NgModuledecorator with imports, declarations, providers - Note: Being replaced by standalone components
Standalone Components (Modern)
Section titled βStandalone Components (Modern)β- Purpose: Self-contained components without modules
- Structure:
standalone: truewith direct imports and latest version we donβt need to specifystandalone: truewhatever component we create it will be standalone by default - Benefit: Simpler, more flexible architecture
π Data Flow
Section titled βπ Data FlowβParent Component β @Input()Child Component β @Output()Parent ComponentModern Approach with Signals
Parent Component β input()Child Component β output()Parent Component- Input: Data flows down from parent to child
- Output: Events flow up from child to parent
- Services: Share data between any components
β‘ Change Detection
Section titled ββ‘ Change DetectionβAngular automatically updates the UI when data changes:
- Trigger: User clicks, HTTP responses, timers
- Check: Angular scans for data changes
- Update: DOM updates reflect new data
π Bootstrap Process
Section titled βπ Bootstrap Processβmain.tsstarts the application- Root component loads
- Component tree builds
- Change detection begins
π Key Concepts
Section titled βπ Key Conceptsβ- Dependency Injection: Angular provides services to components automatically
- Decorators:
@Component,@Injectable,@Input,@Output - Lifecycle Hooks:
ngOnInit,ngOnDestroy, etc. - Templates: HTML with Angular syntax for data binding
β Quick Checklist
Section titled ββ Quick Checklistβ- Understand component-based architecture
- Know the difference between modules and standalone components
- Grasp input/output data flow
- Recognize the role of services
- Understand change detection basics
π― Next Steps
Section titled βπ― Next Stepsβ- Your First App - Build a simple Angular app
- Components Basics - Deep dive into components
- Services & DI - Learn dependency injection