
Modern applications rarely remain small.
A project may start with a single frontend application and a simple backend. Over time, it can grow into multiple applications, shared UI components, authentication libraries, API clients, utilities, domain logic, and even multiple backend services.
At that point, teams usually face an important architectural question:
Should we keep everything in one repository, or split the system into multiple repositories?
This is where Monorepos and tools like Nx become extremely useful.
In this article, we'll explore Nx from both a practical and architectural perspective.
We'll cover:
- What a monorepo is
- Monorepo vs polyrepo
- What Nx actually does
- Nx workspace architecture
- Applications vs libraries
- Project boundaries
- Dependency graphs
- Affected commands
- Task caching
- Generators
- Code sharing
- Angular + Node.js monorepos
- CI/CD optimization
- Common mistakes
- A practical production-style example
1. What Is a Monorepo?
A monorepo is a repository that contains multiple applications and/or libraries.
For example:
company-platform/
│
├── apps/
│ ├── web/
│ ├── admin/
│ ├── api/
│ └── worker/
│
├── libs/
│ ├── auth/
│ ├── ui/
│ ├── database/
│ ├── api-client/
│ └── shared/
│
├── package.json
└── nx.json
Instead of having:
web-repository
admin-repository
api-repository
shared-ui-repository
auth-repository
everything can live inside one repository.
The important idea is:
A monorepo is not simply "one big project."
It is one repository containing multiple independently structured projects.
2. Monorepo vs Polyrepo
There are two common approaches.
Polyrepo
Each application has its own repository.
web/
admin/
api/
mobile/
shared-ui/
Each repository has its own:
- Git history
- CI pipeline
- dependencies
- configuration
- releases
This can work well for loosely connected systems.
But sharing code becomes more complicated.
For example:
web ───────> shared-ui repository
admin ─────> shared-ui repository
api ───────> shared-types repository
You may need to publish packages or synchronize versions.
3. The Monorepo Approach
With a monorepo:
platform/
│
├── apps/
│ ├── web
│ ├── admin
│ └── api
│
└── libs/
├── ui
├── auth
└── shared-types
Now applications can directly consume internal libraries.
For example:
web
│
├── ui
├── auth
└── api-client
And:
admin
│
├── ui
├── auth
└── api-client
This makes code sharing much easier.
4. What Is Nx?
Nx is a build system and developer platform designed for managing large repositories containing multiple applications and libraries.
Nx provides capabilities such as:
- Project management
- Dependency graphs
- Code generators
- Task orchestration
- Computation caching
- Affected project detection
- Workspace organization
- Plugin integrations
- CI optimization
Nx supports many technologies, including:
- Angular
- React
- Node.js
- NestJS
- Next.js
- Express
- Vite
- Jest
- Cypress
- Playwright
The important distinction is:
Nx is not a programming framework.
It sits above your applications and helps manage how your projects are organized, built, tested, and deployed.
5. Why Do We Need Nx?
Imagine a repository with:
apps/
├── customer-web
├── admin-web
├── api
├── worker
└── mobile-api
libs/
├── ui
├── auth
├── database
├── shared
├── validation
└── api-client
Suppose you change:
libs/auth
Which applications are affected?
Potentially:
customer-web
admin-web
api
But maybe:
worker
doesn't depend on authentication.
Without dependency awareness, you might run:
npm test
npm build
for everything.
That's inefficient.
Nx understands the relationship between projects.
6. Nx Dependency Graph
One of the most powerful Nx concepts is the project graph.
Imagine:
shared
/ \
/ \
auth ui
| |
| |
web admin
Nx knows these relationships.
For example:
web
├── auth
├── ui
└── shared
When you change auth, Nx can determine which projects depend on it.
This becomes extremely useful in large repositories.
7. The Nx Workspace
An Nx workspace is the environment where your projects live.
A simplified structure might look like:
my-workspace/
│
├── apps/
├── libs/
├── nx.json
├── package.json
├── tsconfig.base.json
└── node_modules/
The exact structure can vary depending on the Nx version and plugins you're using.
The important part is that Nx knows about the projects inside the workspace.
8. Creating an Nx Workspace
You can create an Nx workspace using:
npx create-nx-workspace@latest
Nx will ask questions about the type of workspace you want.
For example, you may choose:
Angular
React
Node
Integrated Monorepo
Package-based
The choice depends on your architecture.
9. Integrated vs Package-Based Monorepo
This distinction is important.
Integrated Monorepo
Nx manages applications and libraries as projects inside one workspace.
Example:
apps/
libs/
Applications can consume libraries using workspace aliases.
For example:
import { User } from '@company/shared';
This approach is particularly convenient for large application platforms.
Package-Based Monorepo
Another approach is to structure projects more like independently publishable packages.
For example:
packages/
├── ui
├── auth
├── api-client
└── utils
Each package may have its own:
package.json
This can be useful when libraries need stronger package boundaries or may eventually be published externally.
10. Applications vs Libraries
A good Nx architecture separates applications from reusable libraries.
For example:
apps/
├── web
├── admin
└── api
libs/
├── auth
├── ui
├── database
└── shared
Applications represent deployable products.
Libraries represent reusable functionality.
11. What Should Go Inside an App?
An application should contain application-specific behavior.
For example:
apps/web/
├── src/
│ ├── app/
│ ├── main.ts
│ └── styles.css
The application should not become a giant dumping ground for reusable code.
Instead of:
apps/web/src/app/
├── auth/
├── users/
├── products/
├── shared/
├── ui/
└── utils/
you can move reusable functionality into libraries.
12. Libraries
Libraries allow you to isolate functionality.
For example:
libs/
├── auth/
├── users/
├── products/
├── ui/
└── shared/
Now multiple applications can reuse them.
web ───────> auth
├── ui
└── shared
admin ─────> auth
├── ui
└── shared
This reduces duplication.
13. Example: Angular + Node.js Nx Monorepo
A very realistic architecture could look like this:
company-platform/
│
├── apps/
│ ├── web/
│ ├── admin/
│ ├── api/
│ └── worker/
│
├── libs/
│ ├── auth/
│ ├── users/
│ ├── products/
│ ├── database/
│ ├── api-client/
│ ├── ui/
│ └── shared-types/
│
├── nx.json
├── package.json
└── tsconfig.base.json
Here:
web
could be Angular.
admin
could also be Angular.
api
could be NestJS.
worker
could be a Node.js background worker.
And they can share libraries.
14. Shared Types
Suppose the backend returns:
interface User {
id: string;
name: string;
email: string;
}
Instead of defining this independently in:
web
admin
api
we can create:
libs/shared-types
Then:
export interface User {
id: string;
name: string;
email: string;
}
The frontend can consume it:
import { User } from '@company/shared-types';
The backend can consume the same type:
import { User } from '@company/shared-types';
Now both sides use the same contract.
15. Generators
One of Nx's most useful features is its generators.
Instead of manually creating:
library
components
services
tests
configuration
Nx can generate them consistently.
For example:
nx generate library auth
or:
nx g lib auth
Depending on the installed plugins and configuration, Nx will create the appropriate project structure.
Generators help enforce consistency across teams.
16. Why Generators Matter
Imagine ten developers working on a large monorepo.
Without standards, one developer creates:
libs/auth/src/
another creates:
shared/auth/
another creates:
packages/auth/
another uses a different naming convention.
Over time, architecture becomes inconsistent.
Generators help establish a standard.
17. Nx Tasks
Nx manages tasks such as:
build
test
lint
serve
e2e
For example:
nx build web
or:
nx test auth
or:
nx lint api
You can also run tasks across multiple projects.
nx run-many -t build
This tells Nx to execute the build target across projects.
18. The affected Concept
This is one of the most important concepts in Nx.
Suppose you modify:
libs/auth
and these applications depend on it:
web
admin
But:
worker
doesn't.
Instead of rebuilding everything, Nx can determine the affected projects.
For example:
nx affected -t build
This effectively means:
Build the projects affected by the changes.
Similarly:
nx affected -t test
can run tests only where they are needed.
19. Why affected Is Important in CI
Imagine a monorepo with:
20 applications
100 libraries
A developer changes:
libs/button
Running every test could be expensive.
Nx can analyze the dependency graph and focus on affected projects.
Conceptually:
Git changes
↓
Nx project graph
↓
Affected projects
↓
Build / Test / Lint
This can dramatically improve CI efficiency.
20. Nx Caching
Another powerful feature is task caching.
Imagine you run:
nx test auth
The test takes:
30 seconds
Later you run the exact same task without changing its inputs.
Nx can reuse the previous result.
Conceptually:
Task
↓
Calculate inputs
↓
Check cache
↓
Cache hit?
├── Yes → Restore result
└── No → Execute task
Instead of:
30 seconds
you may get the result almost immediately.
21. Local Cache
Nx can cache results locally.
For example:
.nx/
contains Nx-related workspace data and cache information.
The exact cache structure depends on the Nx version and configuration.
The important idea is:
If Nx knows the task inputs haven't changed, it can reuse the previous result.
22. Distributed / Remote Caching
For teams, local caching isn't always enough.
Imagine:
Developer A
↓
build
↓
cache
Developer B pulls the same code.
Without shared caching:
Developer B
↓
build again
With remote caching:
Developer A
↓
Remote Cache
↑
Developer B
Developer B can reuse results generated by Developer A.
This can significantly reduce CI and developer build times.
23. Project Boundaries
Large monorepos have another problem:
What prevents developers from importing everything everywhere?
For example:
admin
↓
database
Maybe the admin frontend should never directly access database code.
You want architectural rules such as:
UI
↓
Feature
↓
Data Access
↓
Backend
Nx supports mechanisms such as tags and module boundary enforcement to help control these relationships.
24. Example of Architectural Boundaries
Imagine these tags:
type:app
type:feature
type:data-access
type:ui
type:util
And domains:
scope:users
scope:products
scope:shared
Now you can define rules such as:
feature → ui
feature → data-access
data-access → util
app → feature
But prevent:
ui → feature
or:
frontend → database
This transforms the monorepo from simply being a shared folder into an architecture with enforceable rules.
25. Domain-Driven Organization
A large Nx workspace can benefit from domain-based organization.
Instead of:
libs/
├── components
├── services
├── models
├── utils
you could have:
libs/
├── users/
│ ├── feature/
│ ├── data-access/
│ ├── ui/
│ └── util/
│
├── products/
│ ├── feature/
│ ├── data-access/
│ └── ui/
│
└── shared/
├── ui/
└── util/
This keeps related functionality together.
26. Nx and Angular
Nx works particularly well with Angular.
For example:
apps/
├── customer
└── admin
libs/
├── users
├── products
├── auth
└── ui
Angular applications can consume shared Angular libraries.
For example:
import { UserCardComponent } from '@company/ui';
And:
import { AuthService } from '@company/auth';
This becomes very useful when multiple Angular applications share the same design system and business logic.
27. Nx and React
The same architectural principles apply to React.
For example:
apps/
├── storefront
└── dashboard
libs/
├── ui
├── auth
├── api-client
└── shared
A shared React component:
export function Button() {
return <button>Click me</button>;
}
can be consumed by multiple applications.
28. Nx and Node.js
Nx isn't only for frontend applications.
You can have:
apps/
├── api
├── worker
├── notifications
└── cron
with shared libraries:
libs/
├── database
├── auth
├── config
├── logging
└── shared-types
For example:
api
↓
database
↓
shared
and:
worker
↓
database
↓
shared
This is particularly useful for backend platforms containing multiple services.
29. A Production-Style Architecture
Consider an e-commerce platform.
We might have:
apps/
├── storefront
├── admin
├── api
├── worker
└── notification-service
libs/
├── auth/
├── users/
├── products/
├── orders/
├── payments/
├── database/
├── messaging/
├── api-client/
├── shared-types/
└── ui/
Dependency relationships could look like:
shared-types
/ | \
/ | \
storefront admin api
| | |
ui auth database
\ | /
\ | /
shared libs
This creates a structured development platform.
30. Monorepo Does Not Mean Microservices
This is an important distinction.
You can have:
Monorepo + Monolith
or:
Monorepo + Microservices
For example:
apps/
├── api
└── web
could be a simple full-stack monorepo.
But:
apps/
├── users-service
├── orders-service
├── payments-service
├── notification-service
└── web
could represent microservices in a monorepo.
The repository strategy and deployment architecture are separate concepts.
31. Monorepo + Microservices
One of the most interesting architectures is:
Nx Monorepo
|
┌────────────┼────────────┐
↓ ↓ ↓
Users Service Orders Service Payments Service
| | |
└────────────┼────────────┘
↓
Shared Libraries
Each service can be deployed independently.
For example:
users-service → Docker container
orders-service → Docker container
payments-service → Docker container
while all source code remains in one repository.
32. What Should You NOT Share?
A common monorepo mistake is sharing too much.
For example:
libs/shared
can become a giant dumping ground:
shared/
├── constants
├── models
├── services
├── database
├── auth
├── ui
├── random-utils
└── everything-else
This creates hidden coupling.
A better approach is to create focused libraries:
libs/
├── auth
├── database
├── ui
├── users
├── orders
└── shared-types
Each library should have a clear responsibility.
33. The Danger of Circular Dependencies
Consider:
auth → users
users → auth
Now we have:
auth
↑ ↓
users
This creates a circular dependency.
Circular dependencies make systems harder to understand, test, and evolve.
Nx's project graph can help identify these relationships.
A good architecture generally aims for directional dependencies.
For example:
UI
↓
Feature
↓
Data Access
↓
Infrastructure
rather than cycles.
34. Nx in CI/CD
A strong CI pipeline might look like:
Pull Request
↓
Detect changed files
↓
Nx affected
↓
Lint
↓
Test
↓
Build
↓
Deploy affected applications
Instead of rebuilding the entire monorepo for every pull request.
For example:
nx affected -t lint
nx affected -t test
nx affected -t build
This is one of the biggest advantages of Nx for large teams.
35. Nx and Docker
Nx can also work well with Docker-based deployments.
Suppose:
apps/
├── web
├── api
└── worker
You may create separate Docker images:
web → web image
api → api image
worker → worker image
The repository remains unified while deployment remains independent.
This gives you:
Single source repository
+
Independent deployment
36. When Should You Use Nx?
Nx is particularly valuable when:
- You have multiple applications
- You share libraries between applications
- You have Angular/React/Node projects together
- Your repository is becoming large
- CI builds are becoming slow
- You need architectural boundaries
- Multiple teams work on the same codebase
- You want standardized project generation
- You want dependency-aware builds
37. When Nx Might Be Overkill
If you have:
one small React application
with:
10 components
and no shared libraries, Nx may provide more infrastructure than you actually need.
A simple Vite/Angular/Next.js project might be enough.
The goal isn't:
"Use Nx because large companies use it."
The goal is:
"Use Nx when repository complexity justifies centralized project orchestration."
38. A Useful Mental Model
Think about Nx as a layer above your applications.
Without Nx:
Git
|
Applications
|
Libraries
With Nx:
Nx
|
┌───────────┼───────────┐
↓ ↓ ↓
Projects Tasks Graph
↓ ↓ ↓
Applications Build/Test Dependencies
|
Libraries
Nx doesn't replace Angular, React, Node.js, TypeScript, or your backend framework.
It coordinates them.
39. The Real Value of Nx
The biggest benefit of Nx isn't the CLI.
It's the combination of:
Project Graph
+
Task Orchestration
+
Caching
+
Affected Detection
+
Generators
+
Architectural Boundaries
Together, these features allow a monorepo to scale without becoming completely chaotic.
40. Final Architecture
A mature Nx monorepo might eventually look like:
platform/
│
├── apps/
│ ├── storefront/
│ ├── admin/
│ ├── api/
│ ├── worker/
│ └── notification-service/
│
├── libs/
│ ├── users/
│ │ ├── feature/
│ │ ├── data-access/
│ │ └── ui/
│ │
│ ├── orders/
│ │ ├── feature/
│ │ ├── data-access/
│ │ └── ui/
│ │
│ ├── auth/
│ ├── payments/
│ ├── database/
│ ├── messaging/
│ ├── api-client/
│ ├── shared-types/
│ └── ui/
│
├── nx.json
├── package.json
└── tsconfig.base.json
And the development workflow becomes:
Developer changes code
↓
Nx analyzes dependencies
↓
Affected projects identified
↓
Only necessary tasks execute
↓
Cache reused where possible
↓
CI becomes faster
↓
Applications deploy independently
Conclusion
Nx is much more than a tool for putting multiple projects inside one Git repository.
It provides an architectural and build-system layer that helps teams manage complexity as their codebase grows.
The most important concepts to understand are:
- Monorepo — multiple applications and libraries in one repository.
- Project Graph — understanding relationships between projects.
- Libraries — reusable and isolated functionality.
- Generators — consistent project creation.
- Affected Commands — execute work only where changes matter.
- Caching — avoid repeating expensive work.
- Boundaries — enforce architectural rules.
- CI Optimization — reduce unnecessary builds and tests.
- Independent Deployment — keep one repository without forcing one deployment unit.
- Scalable Architecture — organize applications around domains and responsibilities.
The real power of Nx appears when a codebase becomes large enough that dependency management, CI performance, code sharing, and architectural consistency become difficult to handle manually.
That's where Nx turns a growing monorepo from a collection of projects into a managed development platform.
A monorepo gives you one repository. Nx gives you the tools to make that repository scalable.
What's Next?
If you're learning Nx seriously, the next step is to build a real project rather than only learning the commands.
A great practical project would be:
Angular Storefront
+
Angular Admin Dashboard
+
NestJS API
+
Node.js Worker
+
Shared Authentication
+
Shared UI Library
+
Shared TypeScript Contracts
+
Docker
+
CI/CD
That project will demonstrate why Nx becomes valuable when the architecture starts getting large.
Top comments (0)