We use cookies to enhance your experience on the site
CodeWorlds

Angular Architecture

Angular's architecture resembles the structure of feudal Japan - it is hierarchical, well-organized, and every element has its role.

Core Architectural Elements

1. Components (武士 - Bushi/Samurai)

Components are the heart of Angular - the basic UI unit, like a samurai in an army.

1@Component({
2  selector: 'app-samurai',
3  standalone: true,
4  template: \`<div class="samurai">{{ name }}</div>\`
5})
6export class SamuraiComponent {
7  name = 'Musashi';
8}

2. Modules (θ—© - Han/Clans)

Modules group related components, services, and other elements - like clans grouping samurai.

1@NgModule({
2  declarations: [],
3  imports: [CommonModule],
4  exports: []
5})
6export class SamuraiModule { }

Note: Since Angular 17+, Standalone Components without NgModules are preferred!

3. Services (職人 - Shokunin/Craftsmen)

Services contain business logic and are shared between components.

1@Injectable({
2  providedIn: 'root'
3})
4export class KatanaService {
5  forge(): string {
6    return 'A new katana has been forged!';
7  }
8}

4. Directives (θ‘“ - Jutsu/Techniques)

Directives modify the behavior of DOM elements - like special combat techniques.

5. Pipes (ι€šθ¨³ - Tsuuyaku/Interpreters)

Pipes transform data in templates - like interpreters at the shogun's court.

Data Flow

1β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
2β”‚              AppComponent               β”‚
3β”‚  (Shogun - supreme commander)           β”‚
4β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
5β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
6β”‚  β”‚ HeaderComp   β”‚  β”‚ SidebarComp  β”‚     β”‚
7β”‚  β”‚ (General)    β”‚  β”‚ (Advisor)    β”‚     β”‚
8β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
9β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
10β”‚  β”‚        MainContentComponent      β”‚   β”‚
11β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚   β”‚
12β”‚  β”‚  β”‚ ListComp   β”‚ β”‚ DetailComp β”‚   β”‚   β”‚
13β”‚  β”‚  β”‚ (Squad)    β”‚ β”‚ (Samurai)  β”‚   β”‚   β”‚
14β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚   β”‚
15β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
16β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data flows top-down through @Input(), and events flow bottom-up through @Output() - like the shogun's orders and the samurai's reports.

Go to CodeWorlds→