Smarter and faster Angular Development
with Nrwl’s Nx
October 6th, 2020
JURI STRUMPFLOHNER
�Architect @ Nrwl�@juristr
ISAAC MANN
�Architect @ Nrwl�@MannIsaac
What are we going to
talk about?
nx.dev
🏛 Driving good architecture with Nx
👨💻👩💻 Modern tools and improved Dx
🚀 Scalability and Speed with Nx
🍿 Live Demos!
💡 Q&A
@nrwl_io
Driving good architecture
🏛
Driving good architecture
🏛
folder organization
LIFT principle�Style 04-01*
* https://angular.io/guide/styleguide#lift
nx.dev
@nrwl_io
Locate, Identify, Flattest structure, Try to be Dry
nx.dev
@nrwl_io
Locate, Identify, Flattest structure, Try to be Dry
Style 04-07
Folders by feature�Style 04-07*
* https://angular.io/guide/styleguide#folders-by-feature-structure
nx.dev
@nrwl_io
Source: https://medium.com/@v_r_a_w/angular-8-folder-structure-c4315b944c7b
nx.dev
@nrwl_io
Source: https://medium.com/@v_r_a_w/angular-8-folder-structure-c4315b944c7b
Infrastructure
nx.dev
@nrwl_io
Source: https://medium.com/@v_r_a_w/angular-8-folder-structure-c4315b944c7b
Features
Source: https://twitter.com/toddmotto/status/900506442804989952/photo/1
Source: https://twitter.com/toddmotto/status/900506442804989952/photo/1
Features
Potential Issues?
🤔
Feature Boundaries
Source: https://twitter.com/toddmotto/status/900506442804989952/photo/1
What’s intended to be “public” outside of the feature?
What’s private and should not be re-used across features?
🤔
nx.dev
@nrwl_io
Nx building blocks: Apps & Libs
app
core
shared
courses
sales
coupons
One big monolith with a set of folders, functioning as feature boundaries
nx.dev
@nrwl_io
Nx building blocks: Apps & Libs
app
courses
sales
coupons
core
shared
nx.dev
@nrwl_io
Nx building blocks: Apps & Libs
app
courses
sales
coupons
core
shared
thin app
Lots of well defined “workspace” libraries
nx.dev
@nrwl_io
Nx building blocks: Apps & Libs
app
courses
sales
coupons
core
shared
Libs
Shareable�(90% of your code)
Apps
Deployables
nx.dev
@nrwl_io
Nx building blocks: Apps & Libs
public
courses
sales
coupons
core
shared
Libs
Shareable�(90% of your code)
Apps
Deployables
admin
nx.dev
@nrwl_io
Nx Library structure
nx.dev
@nrwl_io
Nx Library structure
Export what should be public api
💡
nx.dev
@nrwl_io
Public API
nx.dev
@nrwl_io
TypeScript Path Mappings
nx.dev
@nrwl_io
Libraries represent stronger boundaries compared to folders and help you think more about their APIs
💡
Restricting Access
with Nx Lint rules
Source: https://twitter.com/toddmotto/status/900506442804989952/photo/1
What prevents someone from (accidentally) importing a component into his/her own feature?
🤔
nx.dev
@nrwl_io
public
courses
sales
coupons
core
shared
admin
type:app
type:app
nx.dev
@nrwl_io
public
courses
sales
coupons
core
shared
admin
type:app
type:app
type:feature
type:feature
type:feature
nx.dev
@nrwl_io
public
courses
sales
coupons
core
shared
admin
type:app
type:app
type:feature
type:feature
type:feature
type:util
type:util
nx.dev
@nrwl_io
public
courses
sales
coupons
core
shared
admin
type:app
type:app
type:feature
type:feature
type:feature
type:util
type:util
scope:�store
scope:�store
nx.dev
@nrwl_io
public
courses
sales
coupons
core
shared
admin
type:app
type:app
type:feature
type:feature
type:feature
type:util
type:util
scope:�store
scope:�store
scope:�admin
scope:�admin
scope:�admin
nx.dev
@nrwl_io
public
courses
sales
coupons
core
shared
admin
type:app
type:app
type:feature
type:feature
type:feature
type:util
type:util
scope:�store
scope:�store
scope:�admin
scope:�admin
scope:�admin
scope:�shared
scope:�core
Defining Rules
👮♀️
nx.dev
@nrwl_io
Restricting dependencies
type:app
type:feature
type:util
only depend on
public
admin
type:app
type:app
❌
nx.dev
@nrwl_io
Restricting dependencies
type:app
type:feature
type:util
only depend on
type:util
type:util
only depend on
courses
shared
type:feature
type:util
❌
nx.dev
@nrwl_io
Restricting dependencies
type:app
type:feature
type:util
only depend on
only depend on
scope:�store
scope:�store
scope:�shared
scope:�core
type:util
type:util
only depend on
public
sales
scope:�admin
scope:�store
❌
Feature Reusability
nx.dev
@nrwl_io
Nx building blocks: Apps & Libs
public
courses
sales
coupons
core
shared
Libs
Shareable�(90% of your code)
Apps
Deployables
admin
lib
app
app
app
app
app
lib
lib
lib
lib
lib
nx.dev
@nrwl_io
Modern tools
Improved Dx for Angular Developers
👨💻👩💻
Nx Architecture
@nrwl/workspace
@angular/cli
@angular-devkit/{core, schematics, *}
@nrwl/tao
Community
Plugins
Core Plugins
nx.dev
@nrwl_io
Nx Architecture
@nrwl/workspace
@angular/cli
@angular-devkit/{core, schematics, *}
@nrwl/tao
Community
Plugins
Core Plugins
This is where you
come into play
nx.dev
@nrwl_io
Workspace Schematics
Code Generation for...
Angular, React, Ngrx, Storybook,...
TSLint, ESLint, Prettier
Protractor, Jest, Cypress
NestJS, NextJS, Node
nx.dev
@nrwl_io
Nx Workspace
Schematics
nx.dev
@nrwl_io
Quality Control
Automated Testing
nx.dev
@nrwl_io
Unit testing
Karma
Jest
E2e Testing
Protractor
Cypress
Nx default
Generation & Setup of e2e tests
@juristr
@nrwl_io
Nx + Storybook + Cypress
nx.dev
@nrwl_io
ui
ui-e2e
Quality Control
Linting & Code Formatting
nx.dev
@nrwl_io
Code formatting & verification
Prettier
Linting
TSLint
ESLint
Just published!
nx.dev
@nrwl_io
Demo!
Nx building blocks
🍿
Scalability &
Speed
🚀
Nx
❤️
Monorepos
What’s wrong with “multi repos”?
Why?
lib
app
app
app
app
app
lib
lib
lib
lib
nx.dev
@nrwl_io
But!
Do you wanna always
{build, test, lint, ...} everything?
That
Won’t scale!
Nx knows what you’re building
lib
app
app
app
app
app
lib
lib
lib
lib
Dependency Graph
nx.dev
@nrwl_io
lib
app
app
app
app
app
lib
lib
lib
lib
Dependency Graph
nx.dev
@nrwl_io
lib
app
app
app
app
app
lib
lib
lib
lib
Dependency Graph
nx.dev
@nrwl_io
nx affected:{test,build,...}
nx.dev
@nrwl_io
{ build, test, lint,... }
Nx
{ build, test, lint,... }
Nx
Local cache
Local cache
Computational Cache
nx.dev
@nrwl_io
Never {build, test,...} twice
distributed cache
{ build, test, lint,... }
Nx
{ build, test, lint,... }
Nx
upload/download command result
Local cache
Local cache
Distributed computational cache
nx.dev
@nrwl_io
distributed cache
{ build, test, lint,... }
Nx
{ build, test, lint,... }
Nx
upload/download command result
Local cache
Local cache
Distributed computational cache
nx.dev
@nrwl_io
distributed cache
{ build, test, lint,... }
Nx
{ build, test, lint,... }
Nx
CI Server
{ build, test, lint,... }
upload/download command result
Local cache
Local cache
Distributed computational cache
nx.dev
@nrwl_io
Demo!
Nx Speed!
🍿
Q & A
💡