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

Structure for big Angular Applications -- Packages, Monorepos & Micro Apps @AngularDays in Berlin, Oct 2018

Structure for big Angular Applications -- Packages, Monorepos & Micro Apps @AngularDays in Berlin, Oct 2018

Contains:
- npm Packages
- Monorepo
- Micro Apps

# Library Example
https://github.com/manfredsteyer/logger_lib_sample

# Monorepo Example
https://github.com/manfredsteyer/monorepo-demo

# Micro Apps Example
https://github.com/manfredsteyer/Angular_MicroApps_Different_Technologies

# More Blog-Articles & Angular Trainings
https://www.softwarearchitekt.at

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

October 11, 2018
Tweet

Transcript

  1. @ManfredSteyer Structure for big Angular Applications Packages, Monorepos & Micro

    Apps Manfred Steyer SOFTWAREarchitekt.at ManfredSteyer
  2. @ManfredSteyer About me… • Manfred Steyer • SOFTWAREarchitekt.at • Angular

    Trainings and Consultancy • Google Developer Expert (GDE) Page ▪ 3 Manfred Steyer Public: Vienna, München, Zürich In-House: everywhere http://softwarearchitekt.at/workshops
  3. @ManfredSteyer Goal Get to know three concepts for structuring big

    Angular based enterprise application
  4. @ManfredSteyer Contents 1) npm Packages 2) Monorepos 3) Micro Apps

    4) How to choose?
  5. @ManfredSteyer 1) npm Packages

  6. @ManfredSteyer Structure of an npm Package • /node_modules • your-stuff

    • package.json
  7. @ManfredSteyer Angular Package Format https://goo.gl/hjt7G3

  8. @ManfredSteyer Lots of DETAILS

  9. @ManfredSteyer Angular CLI 6+ supports Packages

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

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

  12. @ManfredSteyer DEMO

  13. @ManfredSteyer Deployment

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

    • ng build --project flight-booking-lib • npm publish --registry http://localhost:4873 • npm install --registry http://localhost:4873
  15. @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
  16. @ManfredSteyer npm Registries Nexus Artifactory Team Foundation Server Verdaccio npm

    i -g verdaccio verdaccio
  17. @ManfredSteyer DEMO

  18. @ManfredSteyer Advantages • Distribution • Versioning • Decoupling between lib

    authors and app authors
  19. @ManfredSteyer Disadvantages • Distribution • Versioning • Decoupling between lib

    authors and app authors ;-)
  20. @ManfredSteyer Disadvantages Distribution • Annoying within project • Prevents gritting

    further libs Versioning • Old versions • Conflicts • How to force devs to use latest version? Decoupling • What if lib authors == app authors?
  21. @ManfredSteyer 2) Monorepos

  22. @ManfredSteyer Workspace

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

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

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

  27. @ManfredSteyer Visualize Module Structure

  28. @ManfredSteyer DEMO

  29. @ManfredSteyer Advantages Sub Project Sub Project Sub Project Sub Project

    Sub Project Sub Project Sub Project Sub Project
  30. @ManfredSteyer Disadvantages Sub Project Sub Project Sub Project Sub Project

    Sub Project Sub Project Sub Project Sub Project
  31. @ManfredSteyer Disadvantages Sub Project Sub Project Sub Project Sub Project

    Sub Project Sub Project Sub Project Sub Project Team A Team B Contract
  32. @ManfredSteyer Disadvantages More Coordination Blocking Tasks Complex Overall System One

    Architecture One Technology Stack Hard to change One size fits all?
  33. @ManfredSteyer 3) Micro Apps

  34. @ManfredSteyer Idea System

  35. @ManfredSteyer Idea µService µService µService

  36. @ManfredSteyer Idea µApp µApp µApp

  37. @ManfredSteyer Folie▪ 43 Pro Contra

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

    SPA
  39. @ManfredSteyer

  40. @ManfredSteyer

  41. @ManfredSteyer

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

    Shell ✓ iframes ✓ Web Components ✓ Bootstrapping several SPAs
  43. @ManfredSteyer µService Providing a (SPA based) Shell µApp µApp µApp

    Shell ✓ iframes ✓ Web Components ✓ Bootstrapping several SPAs
  44. @ManfredSteyer Angular Elements

  45. @ManfredSteyer MicroApp with Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { }
  46. @ManfredSteyer MicroApp with Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { }
  47. @ManfredSteyer MicroApp with Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { } }
  48. @ManfredSteyer MicroApp with Angular Elements @NgModule({ imports: [BrowserModule], declarations: [MicroAppComponent],

    bootstrap: [], entryComponents: [MicroAppComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { const MicroAppElement = createCustomElement( MicroAppComponent, { injector: this.injector }); customElements.define('micro-app', MicroAppElement); } }
  49. @ManfredSteyer Loading MicroApps <script src="micro-app.bundle.js"></script> <micro-app></micro-app>

  50. @ManfredSteyer DEMO

  51. @ManfredSteyer 4) Choosing a Solution

  52. @ManfredSteyer Some General Advice for Macro-Architecture Shared state, navigation b/w

    apps Hyperlinks Legacy Apps or *very very* strong isolation? iframes Separate Deployment/ mix Technologies? Web Components Monolith w/ Libs and Monorepo little much yes no yes no Not a good fit for public web sites
  53. @ManfredSteyer Micro-Architecture Packages Web Components Monorepo Inner Sourcing …

  54. @ManfredSteyer Blog > SOFTWAREarchitekt.at • A Software Architect's Approach Towards

    Using Angular (And SPAs In General) For Microservices Aka Microfrontends • A Lightweight And Solid Approach Towards Micro Frontends (Micro Service Clients) With Angular And/Or Other Frameworks • Micro Apps With Web Components Using Angular Elements
  55. @ManfredSteyer Conclusion Packages: Reuse Monorepo: Structure Microservices: Decoupling CLI 6+

    CLI 6+/ Nx Links, iframes, Web Comp.
  56. @ManfredSteyer Contact and Downloads [mail] manfred.steyer@SOFTWAREarchitekt.at [web] SOFTWAREarchitekt.at [twitter] ManfredSteyer

    d http://softwarearchitekt.at/workshops Slides & Examples