Trung Vo
Trung Vo, web expert with 10 years of experience, Google Developer Expert in Angular, fosters web dev communities and speaks globally, based in Singapore.
Lead Frontend Engineer
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!
By Trung Vo
Deck for NG Rome MMXXI 👉 https://ngrome.io/
Trung Vo, web expert with 10 years of experience, Google Developer Expert in Angular, fosters web dev communities and speaks globally, based in Singapore.