Example Nx monorepo with multiple languages (polyglot).
Table of contents
- Learn more about Nx.
- Showcase a polyglot monorepo and its benefits.
- Define (my) standard build targets (tasks).
- Learn about industry tools.
This repository contains npm (TypeScript) and .NET (C#) projects.
Nx orchestrates the build process across both build tools (npm
and dotnet
).
Nx caches task results, handles execution order, and can run only “affected” tasks; all of which speed up local development.
An overview of the root directories follows. Refer to the § Glossary for clarity on any terms.
-
.github
: GitHub files including workflows -
apps
: Applications -
docs/decisions
: Any decision records (ADRs) -
husky
: Git hooks -
libs
: Libraries -
tools
: Custom build tools -
Repository-wide configuration files live in the root directory or in
.config
Note
apps
and libs
represent a flat, two-tier structure of projects.
However, a more complex repository may prefer a three-tier structure that groups based on application (or technology).
See “Using Nx at Enterprises”.
Projects reside within the apps
and libs
directories.
They all use kebab-case
naming.
.NET Nx projects consist of two .NET projects: *-main.csproj
and *-test.csproj
.
This allows Nx to treat it as a single project to match build semantics regardless of .NET separating test files.
To build and run the projects, you need npm
(node
) and dotnet
installed.
Refer to the official docs (below) or follow your personal preference or company’s guidance.
Complete the following steps to build and run an application.
-
Verify installation.
node --version npm --version dotnet --version
-
Install dependencies.
npm ci dotnet tool restore
-
Install
nx
globally.npm install --global nx@latest
Installing globally allows running commands without the
npx
prefix. The globalnx
will use the locally installed version for consistency. -
Build all projects.
npm run ci-build
The
ci-build
npm run script executes a “full” CI build including the .NET projects. It usesnx run-many
; see package.json for the full list of targets.Running Build solution in Visual Studio or Rider should also work.
A project that runs on its own; a deployed unit (along with its dependent libraries). It matches the Container term in the C4 model.
Applications reside in the apps
directory.
See Nx’s “Applications and libraries”.
A project that is used by applications or other libraries.
Libraries reside in the libs
directory.
See Nx’s “Applications and libraries”.
A single repository containing multiple projects with well-defined relationships. See monorepo.tools.
A build system built by Nrwl with first-class monorepo support. See nx.dev.
Multiple programming languages. See “Polyglot (computing)” on Wikipedia.
An individual unit (think module) of functionality. Synonymous with .NET project or npm package. Applications and libraries both represent projects.
The git repository and all of its code/files. Also known as Solution and Workspace.
- Repository used when emphasizing the git (raw files) aspect.
- Solution used when emphasizing the library and application code, given they solve problems (provide value).
- .NET Solution: Used when explicitly referencing the .NET (C#) concept: “What are solutions and projects?”
- Workspace: Used when emphasizing the collection of projects or discussing build orchestration.
Codecov project: https://codecov.io/gh/connorjs/nx-polyglot-example
Sunburst | Grid | Icicle |
---|---|---|
SonarCloud project: https://sonarcloud.io/project/overview?id=connorjs_nx-polyglot-example