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

Angular Application Architecture

Angular Application Architecture

Talk from BASTA! Spring 2018 in Frankfurt, Germany.

Source Code:
https://github.com/manfredsteyer/basta-spring-2018-angular-architektur

Blog:
https://www.softwarearchitekt.at

Manfred Steyer

February 21, 2018
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @BASTAcon & @ManfredSteyer About me… • Manfred Steyer • SOFTWAREarchitekt.at

    • Angular Trainings and Consultancy • Google Developer Expert (GDE) • Microsoft MVP Page ▪ 3 Manfred Steyer
  2. @BASTAcon & @ManfredSteyer Questions • How to structure an Angular

    application? • How to subdivide an Angular application into smaller parts?
  3. @BASTAcon & @ManfredSteyer Typical Module Structure Page ▪ 7 AppModule

    … … … SharedModule Root Module Feature Modules Shared Module
  4. @BASTAcon & @ManfredSteyer Idea behind Barrels • ES Module: File

    == Modul • Far too fine-grained for consumers of a lib • Barrel == Façade for those files == Public API
  5. @BASTAcon & @ManfredSteyer index.ts as Barrel export * from './src/demo.service';

    export { OtherDemoService } from './src/other-demo.service'; @NgModule({ … }) export class LibStarterModule { }
  6. @BASTAcon & @ManfredSteyer Generator • npm install -g yo •

    npm install -g generator-angular2-library • yo angular2-library
  7. @BASTAcon & @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?
  8. @BASTAcon & @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, …
  9. @BASTAcon & @ManfredSteyer Two Flavors •Like Workspaces/Solutions in different IDEs

    Project Monorepo •E. g. used at Google or Facebook Company-wide Monorepo
  10. @BASTAcon & @ManfredSteyer Why Microservices? Small Teams and hence less

    coordination Less Complexity Separate Development Simpler Deployment Different Technologies Replace µServices on time
  11. @BASTAcon & @ManfredSteyer UI Composition w/ Hyperlinks µService SPA µService

    SPA µService SPA + Easy + Isolation + Separate Deployment + Separate Development - Nesting - No SPA - Loosing state
  12. @BASTAcon & @ManfredSteyer µService UI Composition w/ iframes µService iframe

    µService iframe µService iframe + Isolation + SPA + Can hold state + Messaging API + Separate Deployment + Separate Development - iframes ;-) - Nesting - Overlapping elements Shell
  13. @BASTAcon & @ManfredSteyer µService Bootstrapping several Frameworks µService Element µService

    Element µService Element + SPA - Nesting (different Apps) + Separate Deployment + Seperate Development - Communication + Isolation (Shadow DOM) Shell Shadow Dom: Own Css + Isolated from the rest
  14. @BASTAcon & @ManfredSteyer µService UI Composition w/ Web Components µService

    Element µService Element µService Element Shell Widget from other µService + SPA + Nesting + Separate Deployment + Seperate Development + Communication (DOM) + Isolation (Shadow DOM)
  15. @BASTAcon & @ManfredSteyer Shadow DOM in Angular @Component({ [...] encapsulation:

    ViewEncapsulation.Native }) class MyComponent { [...] }
  16. @BASTAcon & @ManfredSteyer How to find the right solution? •

    You need to know your architectural goal • You need to prioritize them --> Bring them in an order! • One Approach: https://goo.gl/soigHm
  17. @BASTAcon & @ManfredSteyer Some general advice • Easiest when no

    shared state: Hyperlinks • Otherwise: Integrating legacy solutions + Isolation: iframes • Otherwise: Just one (optimized) UI but no separate deployment: No Microservices but Libs and/ or Monorepo • Otherwise: Modern and some isolation: Multiple SPAs in one browser and/ or Web Components
  18. @BASTAcon & @ManfredSteyer Blog • 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 • Microservice Clients With Web Components Using Angular Elements: Dreams Of The (Near) Future?