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

Angular Architecture: Monorepos and Micro Front...

Angular Architecture: Monorepos and Micro Frontends

Manfred Steyer

October 17, 2023
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

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

    … SharedModule Root Module Feature Modules Shared Modules SharedModule
  2. @ManfredSteyer Contents • Monorepos • Strategic Design and DDD •

    Nx & Incremental Compilation • Microfrontends
  3. @ManfredSteyer Two Flavors • Like Workspaces/Solutions in different IDEs Project

    Monorepo • E. g. used at Google or Facebook Company-wide Monorepo
  4. @ManfredSteyer Further Selected Features of Nx • Restricting access b/w

    apps and libs • Just recompile changed apps • Parallel compilation in the cloud • Integration of tooling: Cypress, Playwright, Storybook, …
  5. @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
  6. @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
  7. @ManfredSteyer Finding Sub-Domains Book Flight Check-in Passenger Check-in Luggage Board

    Plane Pickup Luggage Passenger Travel Agency Check-in Agent Boarding Agent
  8. @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.
  9. @ManfredSteyer Finegrained Libraries • Units for dep graph • Unit

    of recompilation* • Unit of retesting • Access restrictions • Information Hiding • Easy: Just ng g lib …
  10. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature …

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

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

    … … … … … … … … Booking App Boarding App Option 1: One App per Domain Monorepo
  13. @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
  14. @ManfredSteyer Idea const Component = import('other-app/xyz') Does not work with

    webpack/ Angular CLI Even lazy parts must be known at compile time!
  15. @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')
  16. @ManfredSteyer Dynamic Module Federation Shell (Host) Microfrontend (Remote) remotes: {

    } exposes: { Cmp: './my.cmp.ts' } loadRemoteModule({ type: 'module', remoteEntry: 'http://…', exposedModule: './Cmp' })
  17. @ManfredSteyer How to Get the Microfrontend's URL? Shell (Host) Microfrontend

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

    [ "@angular/core", "…" ] shared: [ "@angular/core", "…" ]
  19. @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