Professional Documents
Culture Documents
AppModule … SharedModule
SharedModule
Page ▪ 3 @ManfredSteyer
Contents
• (npm-)Packages
• Nx Monorepos
• Strategic Design and DDD
• Microfrontends
@ManfredSteyer
Manfred Steyer
@ManfredSteyer
Monorepos
@ManfredSteyer
Monorepo
Structure
@ManfredSteyer
Advantages
No version conflicts
@ManfredSteyer
Tooling & Generator
https://nrwl.io/nx
@ManfredSteyer
Visualize
Module
Structure
@ManfredSteyer
Creating a Workspace
npm install -g @angular/cli
ng new workspace
cd workspace
@ManfredSteyer
Creating a Workspace
npm install -g @angular/cli
cd workspace
@ManfredSteyer
DEMO
@ManfredSteyer
DDD
in a nutshell
@ManfredSteyer
Methodology for
bridging the gap b/w
requirements and
architecture/ design
@ManfredSteyer
@ManfredSteyer
@ManfredSteyer
Domain Driven Design
Design Patterns
Decomposing a System
& Practices
Flight System
@ManfredSteyer
Example
Booking Check-in
Sub-Domains
Luggage Boarding
@ManfredSteyer
Finding Sub-Domains
@ManfredSteyer
Booking Boarding
Flight
Flight Ticket
Price
Passenger
@ManfredSteyer
Context Map
Check-in
@ManfredSteyer
Shared Kernel (if really needed) & other libs
Smart
Comp. Booking Boarding Shared
Dumb Comp.
Feature Feature Feature Feature Feature
UI UI UI UI UI UI UI UI UI
@ManfredSteyer
@ManfredSteyer
Finegrained Libraries
• Unit of recompilation
• Unit of retesting
• Access restrictions
• Information Hiding
• Easy: Just ng g lib …
• Future replacement for
NgModules?
@ManfredSteyer
Micro
Frontends?
Short outlook
@ManfredSteyer
Microfrontends
@ManfredSteyer
@ManfredSteyer
Deployment Monolith
Flight App
… … … … … … … … …
@ManfredSteyer @ManfredSteyer
Microfrontends
… … … … … … … … …
@ManfredSteyer
Option 1: One App per Domain
… … … … … … … … …
Monorepo
@ManfredSteyer
Option 2: One Monorepo per Domain
… … … … … … … … …
Repository 1 Repository 2
@ManfredSteyer Repository n
Benefits
Autonomous Teams
Separate Development
Separate Deployment
@ManfredSteyer
Integration via
Hyperlinks
@ManfredSteyer
UI Composition
w/ Hyperlinks
@ManfredSteyer
@ManfredSteyer
@ManfredSteyer
Integration via
Shell
@ManfredSteyer
Providing a (SPA based) Shell
Shell
µApp µService
µApp µApp
@ManfredSteyer
@ManfredSteyer
Idea
Does not work with
webpack/ Angular CLI
@ManfredSteyer
Webpack 5 Module Federation
import('mfe1/Cmp')
@ManfredSteyer
How to Get the Microfrontend's URL?
@ManfredSteyer
How to Share Libs?
shared: [ shared: [
"@angular/core", "…" "@angular/core", "…"
] ]
@ManfredSteyer
@ManfredSteyer
Default Behavior
Selecting the highest compatible version
10.0 10.1
@ManfredSteyer
Default Behavior
Conflict: No highest compatible version
11.0 10.1
@ManfredSteyer
Example
• Shell: my-lib: ^10.0
• MFE1: my-lib: ^10.1
• MFE2: my-lib: ^9.0
• MFE3: my-lib: ^9.1
Result:
• Shell and MFE1 share ^10.1
• MFE2 and MFE3 share ^9.1
@ManfredSteyer
Configuring Singletons
shared: {
"my-lib": {
singleton: true
}
}
11.0 10.1
@ManfredSteyer
Configuring Singletons
shared: {
"my-lib": {
singleton: true,
strictVersion: true // Error instead of warning!
}
}
11.0 10.1
@ManfredSteyer
Relaxing Version Requirements
shared: {
"my-lib": {
requiredVersion: ">=1.0.1 <11.1.1"
}
}
@ManfredSteyer
@ManfredSteyer
?
@ManfredSteyer
Custom Builder
@ManfredSteyer
@ManfredSteyer
1) ng add @angular-architects/module-federation
2) Adjust generated configuration
3) ng serve
@ManfredSteyer
1) npm i @angular-architects/module-federation -D
2) ng g @angular-architects/module-federation:init
3) Adjust generated configuration
4) ng serve
@ManfredSteyer
@ManfredSteyer
@ManfredSteyer
Wrap them into Web Components
@ManfredSteyer
@ManfredSteyer
await import('other-app/web-cmp');
@ManfredSteyer
const rootElm = document.createElement('web-cmp')
document.body.appendChild(rootElm);
await import('other-app/web-cmp');
@ManfredSteyer
WrapperComponent
const rootElm = document.createElement('web-cmp')
document.body.appendChild(rootElm);
await import('other-app/web-cmp');
@ManfredSteyer
@ManfredSteyer
https://red-ocean-0fe4c4610.azurestaticapps.net
@ManfredSteyer
Challanges
• Bundle Size
• Multiple Routers
• Bootstrapping Several Angular Instances
• Share Platform-Object when same version is reused
• Share ngZone
@ManfredSteyer
@ManfredSteyer
Choosing a Solution
@ManfredSteyer
Some General Advice
Module Federation
little
Hyperlinks
Shared state,
navigation b/w yes iframes
apps Legacy Apps or
yes Load Bundles on
*very very* strong
much Demand
isolation? Separate
no Deployment/ mix
Technologies?
no Monolith
@ManfredSteyer