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

November 30, 2022
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

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

    … SharedModule Root Module Feature Modules Shared Modules SharedModule
  2. @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
  3. @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
  4. @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.
  5. @ManfredSteyer Finegrained Libraries • Unit of recompilation • Unit of

    retesting • Access restrictions • Information Hiding • Easy: Just ng g lib … • Future replacement for NgModules?
  6. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature …

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

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

    … … … … … … … … Booking App Boarding App Option 1: One App per Domain Monorepo
  9. @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
  10. @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!
  11. @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')
  12. @ManfredSteyer How to Get the Microfrontend's URL? Shell (Host) Microfrontend

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

    [ "@angular/core", "…" ] shared: [ "@angular/core", "…" ]
  14. @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
  15. @ManfredSteyer Challanges • Bundle Size • Multiple Routers • Bootstrapping

    Several Angular Instances • Share Platform-Object when same version is reused • Share ngZone
  16. @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