Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Angular Architecture Workshop: Modulith to Micro Frontends

Angular Architecture Workshop: Modulith to Micro Frontends

Manfred Steyer
PRO

November 30, 2022
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @BASTAcon & @ManfredSteyer

  2. @ManfredSteyer Typical Module Structure Page ▪ 2 AppModule … …

    … SharedModule Root Module Feature Modules Shared Modules SharedModule
  3. @ManfredSteyer Contents • (npm-)Packages • Nx Monorepos • Strategic Design

    and DDD • Microfrontends
  4. @ManfredSteyer Manfred Steyer

  5. @ManfredSteyer Monorepos

  6. @ManfredSteyer Monorepo Structure

  7. @ManfredSteyer Advantages Everyone uses the latest versions No version conflicts

    No burden with distributing libs
  8. @ManfredSteyer Tooling & Generator https://nrwl.io/nx

  9. @ManfredSteyer Visualize Module Structure

  10. @ManfredSteyer Creating a Workspace npm install -g @angular/cli ng new

    workspace cd workspace ng generate app my-app ng generate lib my-lib ng serve --project my-app ng build --project my-app
  11. @ManfredSteyer Creating a Workspace npm install -g @angular/cli npm init

    nx-workspace workspace cd workspace ng generate app my-app ng generate lib my-lib ng serve --project my-app ng build --project my-app
  12. @ManfredSteyer DEMO

  13. @ManfredSteyer DDD in a nutshell

  14. @ManfredSteyer Methodology for bridging the gap b/w requirements and architecture/

    design
  15. @ManfredSteyer Domain Driven Design Strategic Design Tactical Design Decomposing a

    System Design Patterns & Practices
  16. @ManfredSteyer Domain Driven Design Strategic Design Tactical Design Decomposing a

    System Design Patterns & Practices
  17. @ManfredSteyer

  18. @ManfredSteyer Example Flight System

  19. @ManfredSteyer Booking Check-in Boarding Luggage Example Sub-Domains

  20. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature UI

    UI UI UI UI UI UI UI UI Domain Domain Domain Domain Domain Domain Util Util Util Util Util Util Enterprise Monorepo Patterns, Nrwl 2018: https://tinyurl.com/y2jjxld7 @ManfredSteyer Shared Kernel (if really needed) & other libs Smart Comp. Dumb Comp.
  21. @ManfredSteyer DEMO

  22. @ManfredSteyer

  23. @ManfredSteyer Finegrained Libraries • Unit of recompilation • Unit of

    retesting • Access restrictions • Information Hiding • Easy: Just ng g lib … • Future replacement for NgModules?
  24. @ManfredSteyer Micro Frontends? Short outlook

  25. @ManfredSteyer Booking App Check-in App Boarding App Luggage App Microfrontends

  26. @ManfredSteyer

  27. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature …

    … … … … … … … … @ManfredSteyer Flight App Deployment Monolith
  28. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature …

    … … … … … … … … Booking App Boarding App Microfrontends
  29. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature …

    … … … … … … … … Booking App Boarding App Option 1: One App per Domain Monorepo
  30. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature …

    … … … … … … … … Booking App Boarding App Option 2: One Monorepo per Domain Publish shared libs seperately via npm Repository n Repository 2 Repository 1
  31. @ManfredSteyer Benefits Autonomous Teams Separate Development Separate Deployment Own architecture

    decisions Own technology descisions
  32. @ManfredSteyer Integration via Hyperlinks

  33. @ManfredSteyer UI Composition w/ Hyperlinks µApp SPA µApp SPA µApp

    SPA
  34. @ManfredSteyer

  35. @ManfredSteyer

  36. @ManfredSteyer Integration via Shell

  37. @ManfredSteyer µService Providing a (SPA based) Shell µApp µApp µApp

    Shell
  38. @ManfredSteyer

  39. @ManfredSteyer Idea const Component = import('http://other-app/xyz') Does not work with

    webpack/ Angular CLI Even lazy parts must be known at compile time!
  40. @ManfredSteyer Webpack 5 Module Federation Shell (Host) Microfrontend (Remote) //

    Maps Urls in // webpack config remotes: { mfe1: "http://..." } // Expose files in // webpack config exposes: { Cmp: './my.cmp.ts' } import('mfe1/Cmp')
  41. @ManfredSteyer How to Get the Microfrontend's URL? Shell (Host) Microfrontend

    (Remote) RemoteEntrypoint.js <script src="…"></script>
  42. @ManfredSteyer How to Share Libs? Shell (Host) Microfrontend (Remote) shared:

    [ "@angular/core", "…" ] shared: [ "@angular/core", "…" ]
  43. @ManfredSteyer

  44. @ManfredSteyer Default Behavior Selecting the highest compatible version 10.0 10.1

  45. @ManfredSteyer Default Behavior Conflict: No highest compatible version 11.0 10.1

  46. @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
  47. @ManfredSteyer Configuring Singletons shared: { "my-lib": { singleton: true }

    } 11.0 10.1
  48. @ManfredSteyer Configuring Singletons shared: { "my-lib": { singleton: true, strictVersion:

    true // Error instead of warning! } } 11.0 10.1
  49. @ManfredSteyer Relaxing Version Requirements shared: { "my-lib": { requiredVersion: ">=1.0.1

    <11.1.1" } }
  50. @ManfredSteyer

  51. @ManfredSteyer ?

  52. @ManfredSteyer Custom Builder

  53. @ManfredSteyer

  54. @ManfredSteyer 1) ng add @angular-architects/module-federation 2) Adjust generated configuration 3)

    ng serve
  55. @ManfredSteyer 1) npm i @angular-architects/module-federation -D 2) ng g @angular-architects/module-federation:init

    3) Adjust generated configuration 4) ng serve
  56. @ManfredSteyer

  57. @ManfredSteyer

  58. @ManfredSteyer Wrap them into Web Components Angular App (MFE) React

    App (MFE)
  59. @ManfredSteyer

  60. @ManfredSteyer await import('other-app/web-cmp');

  61. @ManfredSteyer await import('other-app/web-cmp'); const rootElm = document.createElement('web-cmp') document.body.appendChild(rootElm);

  62. @ManfredSteyer await import('other-app/web-cmp'); const rootElm = document.createElement('web-cmp') document.body.appendChild(rootElm); WrapperComponent

  63. @ManfredSteyer

  64. @ManfredSteyer https://red-ocean-0fe4c4610.azurestaticapps.net

  65. @ManfredSteyer Challanges • Bundle Size • Multiple Routers • Bootstrapping

    Several Angular Instances • Share Platform-Object when same version is reused • Share ngZone
  66. @ManfredSteyer

  67. @ManfredSteyer Choosing a Solution

  68. @ManfredSteyer Some General Advice Shared state, navigation b/w apps Hyperlinks

    Legacy Apps or *very very* strong isolation? iframes Separate Deployment/ mix Technologies? Load Bundles on Demand Monolith little much yes no yes no Module Federation