Save 37% off PRO during our Black Friday Sale! »

Structure for huge Angular Applications @AngularDays2022 Berlin

Structure for huge Angular Applications @AngularDays2022 Berlin

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

October 07, 2021
Tweet

Transcript

  1. @BASTAcon & @ManfredSteyer

  2. @BASTAcon & @ManfredSteyer

  3. @BASTAcon & @ManfredSteyer

  4. @BASTAcon & @ManfredSteyer

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

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

    and DDD • Microfrontends
  7. @ManfredSteyer Manfred Steyer

  8. @ManfredSteyer npm Packages

  9. @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
  10. @ManfredSteyer Folder Structure

  11. @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
  12. @ManfredSteyer Publishing

  13. @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
  14. @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/
  15. @ManfredSteyer npm Registries Nexus Artifactory Team Foundation Server Verdaccio npm

    i -g verdaccio verdaccio
  16. @ManfredSteyer DEMO

  17. @ManfredSteyer Advantages • Distribution • Versioning

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

  19. @ManfredSteyer Disadvantages Distribution • Annoying within project Versioning • Conflicts

    • How to force devs to use latest version?
  20. @ManfredSteyer Monorepos

  21. @ManfredSteyer Monorepo Structure

  22. @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, …
  23. @ManfredSteyer Two Flavors • Like Workspaces/Solutions in different IDEs Project

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

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

  26. @ManfredSteyer Visualize Module Structure

  27. @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
  28. @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
  29. @ManfredSteyer DEMO

  30. @ManfredSteyer LAB

  31. @ManfredSteyer DDD in a nutshell

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

    design
  33. @ManfredSteyer

  34. @ManfredSteyer

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

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

    System Design Patterns & Practices
  37. @ManfredSteyer

  38. @ManfredSteyer Example Flight System Flight System

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

    Sub-Domains
  40. @ManfredSteyer Finding Sub-Domains Book Flight Check-in Passenger Check-in Luggage Board

    Plane Pickup Luggage Passenger Travel Agency Check-in Agent Boarding Agent
  41. @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.
  42. @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
  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 Micro Frontends? Short outlook

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

    App Boarding App Luggage App Luggage App Microfrontends
  48. @ManfredSteyer

  49. @ManfredSteyer Booking Booking Boarding Boarding Shared Shared Feature Feature Feature

    Feature Feature Feature Feature Feature Feature Feature … … … … … … … … … … … … … … … … … … @ManfredSteyer Flight App Flight App Deployment Monolith
  50. @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
  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 Option 1: One App per Domain Monorepo
  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 2: One Monorepo per Domain Publish shared libs seperately via npm Repository n Repository 2 Repository 1
  53. @ManfredSteyer Benefits Autonomous Teams Separate Development Separate Deployment Own architecture

    decisions Own technology descisions
  54. @ManfredSteyer Integration via Hyperlinks

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

    SPA
  56. @ManfredSteyer

  57. @ManfredSteyer

  58. @ManfredSteyer Integration via Shell

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

    Shell
  60. @ManfredSteyer

  61. @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!
  62. @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')
  63. @ManfredSteyer How to Get the Microfrontend's URL? Shell (Host) Microfrontend

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

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

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

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

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

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

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

    <11.1.1" } }
  72. @ManfredSteyer

  73. @ManfredSteyer ?

  74. @ManfredSteyer Custom Builder

  75. @ManfredSteyer

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

    ng serve
  77. @ManfredSteyer

  78. @ManfredSteyer Choosing a Solution

  79. @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
  80. @ManfredSteyer

  81. @ManfredSteyer d Slides & Examples Public: Frankfurt, Munich, Vienna In-House:

    everywhere http://softwarearchitekt.at/workshops