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

Architectures for huge Enterprise Applications with Angular @AngularDays 2020

Architectures for huge Enterprise Applications with Angular @AngularDays 2020

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

March 25, 2021
Tweet

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
  4. @ManfredSteyer npm Packages

  5. @ManfredSteyer Create Library with CLI >= 6 npm install -g

    @angular/cli ng new lib-project cd lib-project ng generate library logger-lib ng generate application playground-app ng serve --project playground-app ng build --project logger-lib
  6. @ManfredSteyer Folder Structure

  7. @ManfredSteyer Create Library with CLI >= 6 npm install -g

    @angular/cli ng new lib-project --create-application false cd lib-project ng generate library logger-lib ng generate application playground-app ng serve --project playground-app ng build --project logger-lib
  8. @ManfredSteyer Publishing

  9. @ManfredSteyer Publishing to npm Registry • Increment version in package.json

    • ng build logger-lib --prod • npm publish dist/logger-lib --registry http://localhost:4873 • npm install logger-lib --registry http://localhost:4873
  10. @ManfredSteyer Alternatives for setting the Registry • Global: npm set

    registry http://localhost:4873 • Default: registry.npmjs.org • npm get registry • Project: .npmrc in project root registry=http://localhost:4873/ @my-company:registry=http://my-server:4873/
  11. @ManfredSteyer npm Registries Nexus Artifactory Team Foundation Server Verdaccio npm

    i -g verdaccio verdaccio
  12. @ManfredSteyer Advantages • Distribution • Versioning

  13. @ManfredSteyer Disadvantages • Distribution • Versioning ;-)

  14. @ManfredSteyer Disadvantages Distribution • Annoying within project • Prevents gritting

    further libs Versioning • Old versions • Conflicts • How to force devs to use latest version?
  15. @ManfredSteyer Monorepos

  16. @ManfredSteyer Monorepo Structure

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

    No burden with distributing libs Creating new libs: Adding folder Experience: Successfully used at Google, Facebook, …
  18. @ManfredSteyer Two Flavors • Like Workspaces/Solutions in different IDEs Project

    Monorepo • E. g. used at Google or Facebook Company-wide Monorepo
  19. @ManfredSteyer Moving back and forth Npm Registry

  20. @ManfredSteyer Tooling & Generator https://nrwl.io/nx

  21. @ManfredSteyer Visualize Module Structure

  22. @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
  23. @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 --buildable ng serve --project my-app ng build --project my-app
  24. @ManfredSteyer DEMO

  25. @ManfredSteyer LAB

  26. @ManfredSteyer DDD in a nutshell

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

    design
  28. @ManfredSteyer

  29. @ManfredSteyer

  30. @ManfredSteyer Domain Driven Design Strategic Design Tactical Design Decomposing a

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

    System Design Patterns & Practices
  32. @ManfredSteyer

  33. @ManfredSteyer Example Flight System Flight System

  34. @ManfredSteyer Booking Booking Check-in Check-in Boarding Boarding Luggage Luggage Example

    Sub-Domains
  35. @ManfredSteyer Booking Booking Luggage Luggage Boarding Boarding Check-in Check-in Context

    Map
  36. @ManfredSteyer Luggage Luggage Booking Booking Context Map Check-in Check-in Boarding

    Boarding Shared Kernel Shared Kernel
  37. @ManfredSteyer Booking Booking Check-in Check-in API API

  38. @ManfredSteyer Lots of approaches for cross-domain communication and more …

  39. @ManfredSteyer Booking Booking Boarding Boarding Shared Shared Feature Feature Feature

    Feature Feature Feature Feature Feature Feature Feature UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Util Util Util Util Util Util 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.
  40. @ManfredSteyer Booking Booking Boarding Boarding Shared Shared Feature Feature API

    API Feature Feature Feature Feature Feature Feature Feature Feature UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Util Util Util Util Util Util Util Util Util Util Util Util @ManfredSteyer
  41. @ManfredSteyer Booking Booking Boarding Boarding Shared Shared Feature Feature API

    API Feature Feature Feature Feature Feature Feature Feature Feature UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Domain Util Util Util Util Util Util Util Util Util Util Util Util @ManfredSteyer
  42. @ManfredSteyer Application Domain Model Infrastructure Application Domain Model Infrastructure Isolate

    your domain! Domain Domain e. g. data access Use case specific facades, state management Entities, biz logic
  43. @ManfredSteyer Alternatives to layering • e. g. Hexagonal Architecture, Clean

    Architecture • Anyway: We need to restrict access b/w libraries
  44. @ManfredSteyer DEMO

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

    retesting • Access restrictions • Information Hiding • Easy: Just ng g lib … • Future replacement for NgModules?
  46. @ManfredSteyer Where‘s the Catch? Inofficial Solution Official Solution: Nx Cloud

    Nx Cloud: Far more possibilities
  47. @ManfredSteyer Micro Frontends? Short outlook

  48. @ManfredSteyer Booking App Booking App Check-in App Check-in App Boarding

    App Boarding App Luggage App Luggage App Microfrontends
  49. @ManfredSteyer

  50. @ManfredSteyer Booking Booking Boarding Boarding Shared Shared Feature Feature Feature

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

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

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

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

    decisions Own technology descisions
  55. @ManfredSteyer Integration via Hyperlinks

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

    SPA
  57. @ManfredSteyer

  58. @ManfredSteyer

  59. @ManfredSteyer Integration via Shell

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

    Shell
  61. @ManfredSteyer

  62. @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!
  63. @ManfredSteyer Webpack 5 Module Federation Shell (Host) Microfrontend (Remote) //

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

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

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

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

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

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

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

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

    <11.1.1" } }
  73. @ManfredSteyer

  74. @ManfredSteyer ?

  75. @ManfredSteyer Custom Builder

  76. @ManfredSteyer

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

    ng serve
  78. @ManfredSteyer

  79. @ManfredSteyer

  80. @ManfredSteyer Well … Webpack 5: final @angular-architects/module-federation: final CLI 11:

    Experimental webpack 5 support CLI 12: Official webpack 5 support (May 2021)
  81. @ManfredSteyer Choosing a Solution

  82. @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