How danwahlin/angular-architecture works
Project Type and Purpose
• This is a front-end Angular “monorepo” (single workspace) hosting multiple self-contained sample/demo applications plus one shared library.
• Its purpose is educational: demonstrating Angular architecture patterns and best practices (core/shared/feature modules, state mgmt, view-models, component communication, routing, standalone components, etc.).
Top-Level Structure (Monorepo)
• Workspace root
• angular.json (workspace configuration listing all projects)
• package.json (shared dev-dependencies, scripts)
• tsconfig.json
• folders:
– demos (primary sample app with many feature modules)
– cloning, input-output-demo (smaller isolated apps)
– labs (bite-size guided “begin” & “end” exercises)
– state-management (DIY store, NgRx, ngrx-data, Observable Store)
– shared-library-abc-logging (Angular library project + demo app)
Main Components (high level)
• Angular CLI (ng serve, ng build)
• Build System (webpack under the hood via Angular CLI)
• Each Angular App project:
• src/app/app.module.ts (root module)
• CoreModule: singleton services (e.g., ClonerService, in-memory data services, interceptors, guards, logger)
• SharedModule: common directives, pipes, components, interfaces
• Feature Modules: e.g., customer, heroes, orders, communication, view-models, routing modules, state modules
• AppRoutingModule (routes.ts)
• Main at src/main.ts → bootstrap(AppModule)
• Assets & environments (static JSON, env configs)
• Shared Library project:
• browser-logger library (ng-packagr output)
• exported as a normal NPM package within the workspace
Relationships and Data Flow
• Developer invokes Angular CLI → builds requested project → passes through
→ RootModule → loads CoreModule & SharedModule → lazily or eagerly loads Feature Modules
• Components ← dependency injection ← Services from CoreModule/feature modules
• Services may call:
• HttpClient → real or in-memory-web-api back end (JSON files under assets or db.json)
• RxJS streams/Subjects → propagate data to components or other services
• State-management: components dispatch actions → NgRx Store/Effects or custom observable store → selectors → components
Key Architectural Patterns
• Monorepo with Angular CLI multi-project workspace
• Modularization: separation of concerns via Core, Shared, Feature modules
• Lazy loading (feature routes) vs eager loading
• Dependency Injection for services, interceptors, guards
• State management patterns: DIY store, Subject-based store, NgRx, NgRx-Data, Observable Store
• View-model pattern: container vs presentational components with CustomerVM, OrderVM, entity cache
• Standalone components (in standalone labs)
Essential Elements
• Labels for Workspace, Projects, Modules, Components, Services
• Annotation of lazy vs eager loaded feature modules