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 servicetype:library
- Shared code librarytype:tool
- Developer toolingtype:config
- Configuration package
2. Language Tags
Indicate the primary language:
language:typescript
- TypeScript projectlanguage:python
- Python projectlanguage:solidity
- Solidity/Blockchain projectlanguage:mixed
- Mixed language project
3. Scope Tags
Indicate the project's area of responsibility:
scope:api
- API-related projectscope:blockchain
- Blockchain interactionscope:data
- Data processingscope:exchange
- Exchange core functionalityscope:risk
- Risk managementscope:tools
- Development toolsscope:testing
- Testing utilitiesscope:security
- Security-related
4. Status Tags
Indicate the project's status:
status:stable
- Production-readystatus:experimental
- Experimental featuresstatus:deprecated
- Planned for deprecationstatus:maintenance
- Only receiving maintenance updates
5. Team Tags
Indicate the responsible team:
team:core
- Core development teamteam:platform
- Platform teamteam:devops
- DevOps teamteam: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:
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
- Update all existing projects with appropriate tags
- Update CI/CD pipelines to use tags for targeting
- Create documentation for developers on tag usage
- Update project creation templates to include tags
- Implement tag-based dependency constraints
By consistently applying this tagging strategy, we can improve organization, build performance, and dependency management in our monorepo.