Lead Frontend Engineer
NG Rome MMXXIΒ - 09 July 2021
Hi, My name is Trung π
What is Nx?
Angular Spotify
Nx App vs Lib
Nx Lib Types
Sample Structure
Principles
Nx is a suite of dev tools to help you architect, test, and build at any scale.
Nx has fully integrated support for modern libraries like Jest, Cypress, ESLint, and more.
Β
Nx works especially well for monorepos
A single git repository that holds the source code for multiple applications and libraries, along with the tooling for them.
Isn't it the same as putting multiple folders/projects within a repo?
API
Core
Web
Mobile
.
βββ api
β βββ package.json
β βββ package-lock.json
β βββ node_modules
β βββ tsconfig.json
βββ web
β βββ package.json
β βββ package-lock.json
β βββ node_modules
β βββ tsconfig.json
βββ mobile
βββ package.json
βββ package-lock.json
βββ node_modules
βββ tsconfig.json
.
βββ api
β βββ types
β βββ album.ts
βββ web
β βββ api
β β βββ album-api.ts
β βββ types
β βββ album.ts
βββ mobile
βββ api
β βββ album-api.ts
βββ types
βββ album.ts
API
Core
Core
SDK
Web
Mobile
@spotify/sdk
.
βββ core
β βββ types
β βββ album.ts
βββ sdk (publish to npm)
β βββ interfaces
β β βββ album.ts
β βββ api
β βββ album-api.ts
βββ web
β βββ import { Album } from "@spotify/sdk"
βββ mobile
βββ import { Album } from "@spotify/sdk"
.
βββ apps
β βββ api
β β βββ import { Album } from "@spotify/shared/interfaces"
β βββ web
β β βββ import { Album } from "@spotify/shared/interfaces"
β β βββ import { PlayButtonComponent } from "@spotify/shared/components"
β β βββ import { VisualizationComponent } from "@spotify/web"
β βββ mobile
β β βββ import { Album } from "@spotify/shared/interfaces"
β β βββ import { Button } from "@spotify/mobile/button"
β βββ sdk
β βββ import { Album } from "@spotify/shared/interfaces"
βββ libs
β βββ api
β βββ web
β β βββ visualization
β βββ mobile
β βββ button
βββ shared
β βββ components
β β βββ play-button
β βββ interfaces
β βββ album.ts
βββ package.json
βββ package-lock.json
βββ node_modules
npm run affected:dep-graph
Applications and libraries are two fundamental building blocks within Nx workspace
βββ apps
βββ libs
βββ tools
βββ nx.json
βββ package.json
βββ tsconfig.base.json
.
βββ apps
βββ angular-spotify (web)
βββ electron-spotify (desktop)
βββ ionic-spotify (mobile)
βββ libs
βββ web (angular-spotify)
β βββ album
β βββ browse
β βββ playlist
βββ electron-spotify
βββ ionic-spotify
βββ shared
Libraries require classifiers to describe their contents and intended purpose. These classifiers help to organize the libraries and to provide a way to locate them.
βββ libs
βββ web (angular-spotify)
β βββ album
β β βββ data-access
β β βββ feature
β β βββ ui
β βββ browse
β βββ playlist
βββ electron-spotify
βββ ionic-spotify
βββ shared
scope:web
Lib type | Description |
---|---|
Feature | Routable components |
UI | Presentational and container components |
Data-access | Interact with backend and state management related |
Utility | Low-level utilitiesΒ |
Original Nx documentationΒ with modification π
βββ libs
βββ web (angular-spotify)
β βββ album
β β βββ data-access
β β βββ feature
β β βββ ui
β βββ browse
β βββ playlist
βββ electron-spotify
βββ ionic-spotify
βββ shared
scope:web,
type:feature
Every library should be:
scope:SCOPE,type:TYPE
βββ libs
βββ web (angular-spotify)
β βββ album <-- grouping folder
β β βββ data-access <-- angular lib
β β βββ feature <-- grouping folder
β β β βββ detail <-- angular lib
β β β βββ list <-- angular lib
β β β βββ shell <-- angular lib
β β βββ ui <-- grouping folder
β β βββ album-track <-- angular lib
β βββ browse
β βββ playlist
βββ electron-spotify
βββ ionic-spotify
βββ shared
βββ libs
βββ client <-- grouping folder (dir)
βββ shell <-- grouping folder (dir)
β βββ feature <-- angular:lib (3)
βββ feature-1 <-- grouping folder (dir)
β βββ data-access <-- angular:lib, service, API calls, state management)
β βββ feature <-- grouping folder (dir) or lib (4)
β β βββ list <-- angular:lib e.g. ProductList
β β βββ detail <-- angular:lib e.g. ProductDetail
β βββ ui <-- grouping folder (dir)
β βββ comp-1 <-- angular:lib, SCAM for Component
β βββ pipe-1 <-- angular:lib, SCAM for Pipe
βββ shared <-- grouping folder (dir)
βββ data-access <-- angular:lib, any Service or State management to share across the Client app)
βββ ui <-- grouping folder (dir) (5)
βββ utils <-- angular:lib, usually shared Guards, Interceptors, Validators...)
View the full notes
Enterprise Monorepo Angular Patterns, by Nitin Vericherla & Victor Savkin.
Thanks everyone for your support!