Skip to content

NX Tag Strategy

Overview

This document outlines our strategy for using NX project tags to better organize the monorepo, enable better dependency management, and facilitate more targeted task execution.

Tag Categories

Each project should have multiple tags in the following categories:

1. Type Tags

Indicate the project's type:

  • type:application - Deployable service
  • type:library - Shared code library
  • type:tool - Developer tooling
  • type:config - Configuration package

2. Language Tags

Indicate the primary language:

  • language:typescript - TypeScript project
  • language:python - Python project
  • language:solidity - Solidity/Blockchain project
  • language:mixed - Mixed language project

3. Scope Tags

Indicate the project's area of responsibility:

  • scope:api - API-related project
  • scope:blockchain - Blockchain interaction
  • scope:data - Data processing
  • scope:exchange - Exchange core functionality
  • scope:risk - Risk management
  • scope:tools - Development tools
  • scope:testing - Testing utilities
  • scope:security - Security-related

4. Status Tags

Indicate the project's status:

  • status:stable - Production-ready
  • status:experimental - Experimental features
  • status:deprecated - Planned for deprecation
  • status:maintenance - Only receiving maintenance updates

5. Team Tags

Indicate the responsible team:

  • team:core - Core development team
  • team:platform - Platform team
  • team:devops - DevOps team
  • team:security - Security team

Tag Implementation

Tags should be added to each project's project.json file:

{
  "name": "my-project",
  "tags": ["type:application", "language:typescript", "scope:api", "status:stable", "team:core"]
}

Tag Usage

In NX Commands

Tags can be used to target specific groups of projects:

# Run tests for all TypeScript applications
nx run-many --target=test --tag=language:typescript --tag=type:application

# Build all stable libraries
nx run-many --target=build --tag=type:library --tag=status:stable

# Check all API projects
nx run-many --target=lint --tag=scope:api

In CI/CD

Tags can be used in CI/CD pipelines to target specific types of projects:

- name: Test TypeScript Applications
  run: nx affected --target=test --tag=language:typescript --tag=type:application

- name: Lint API Projects
  run: nx affected --target=lint --tag=scope:api

In Dependencies

Tags can be used to enforce dependency constraints:

{
  "name": "my-project",
  "implicitDependencies": ["@scope/type:library"]
}

Tag Maintenance

  • Periodic Review: Tags should be reviewed quarterly to ensure they remain accurate
  • New Project Setup: New projects must include appropriate tags from each category
  • Migration: Existing projects should be updated to include appropriate tags

Implementation Plan

  1. Update all existing projects with appropriate tags
  2. Update CI/CD pipelines to use tags for targeting
  3. Create documentation for developers on tag usage
  4. Update project creation templates to include tags
  5. Implement tag-based dependency constraints

By consistently applying this tagging strategy, we can improve organization, build performance, and dependency management in our monorepo.