Skip to content

connorjs/nx-polyglot-example

Repository files navigation

Nx polyglot example

Example Nx monorepo with multiple languages (polyglot).

codecov Quality Gate Status

Table of contents

Goals

  1. Learn more about Nx.
  2. Showcase a polyglot monorepo and its benefits.
  3. Define (my) standard build targets (tasks).
  4. Learn about industry tools.

About

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.

Workspace structure

Directories

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”.

Project naming conventions

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.

Getting started

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.

  1. Verify installation.

    node --version
    npm --version
    dotnet --version
  2. Install dependencies.

    npm ci
    dotnet tool restore
  3. Install nx globally.

    npm install --global nx@latest

    Installing globally allows running commands without the npx prefix. The global nx will use the locally installed version for consistency.

  4. Build all projects.

    npm run ci-build

    The ci-build npm run script executes a “full” CI build including the .NET projects. It uses nx run-many; see package.json for the full list of targets.

    Running Build solution in Visual Studio or Rider should also work.

Glossary

Application

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”.

Library

A project that is used by applications or other libraries.

Libraries reside in the libs directory. See Nx’s “Applications and libraries”.

Monorepo

A single repository containing multiple projects with well-defined relationships. See monorepo.tools.

Nx

A build system built by Nrwl with first-class monorepo support. See nx.dev.

Polyglot

Multiple programming languages. See “Polyglot (computing)” on Wikipedia.

Project

An individual unit (think module) of functionality. Synonymous with .NET project or npm package. Applications and libraries both represent projects.

Repository

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).
  • Workspace: Used when emphasizing the collection of projects or discussing build orchestration.

Industry tools

Codecov

Codecov project: https://codecov.io/gh/connorjs/nx-polyglot-example

Sunburst Grid Icicle
Codecov sunburst graph Codecov grid graph Codecov icicle graph

SonarCloud

Quality gate

SonarCloud project: https://sonarcloud.io/project/overview?id=connorjs_nx-polyglot-example

Bugs Code Smells Coverage Duplicated Lines (%)