Advanced Nx monorepo demonstrating PipeCraft with mixed detection strategies.
This example demonstrates:
- ✅ Nx integration - Automatic affected project detection
- ✅ Mixed detection - Nx projects + path-based domains working together
- ✅ Complex dependencies - 10+ libs with interdependencies, 4 apps
- ✅ Task dependencies - Respects Nx task graph (test WITH/WITHOUT build)
- ✅ Non-Nx code - Infrastructure and migrations as path-based domains
- ✅ 3-branch trunk flow - develop → staging → main
- ✅ Auto-merge enabled - Automatic promotion through all stages
pipecraft-example-nx/
├── .github/workflows/
│ └── pipeline.yml # Generated by PipeCraft
├── apps/
│ ├── frontend/ # Web frontend application
│ ├── backend/ # Backend API server
│ ├── widget/ # Embeddable widget
│ └── client/ # CLI client tool
├── libs/
│ ├── auth/ # Authentication library
│ ├── database/ # Database layer
│ ├── logging/ # Logging utilities
│ ├── config/ # Configuration management
│ ├── user-management/ # User features
│ ├── analytics/ # Analytics tracking
│ ├── billing/ # Billing system
│ ├── notifications/ # Notification service
│ ├── reporting/ # Report generation
│ └── admin-dashboard/ # Admin dashboard
├── infra/
│ ├── pulumi/ # Infrastructure as Code (Pulumi)
│ └── kubernetes/ # Kubernetes manifests
├── migrations/
│ ├── 001-initial-schema/ # Database schema (pgroll)
│ └── 002-add-billing/ # Billing tables (pgroll)
├── nx.json # Nx configuration
├── .pipecraftrc.json # PipeCraft configuration
└── package.json
{
"ciProvider": "github",
"branchFlow": ["develop", "staging", "main"],
"autoMerge": {
"staging": true,
"main": true
},
"domains": {
"migrations": {
"paths": ["migrations/**"],
"description": "Database migrations (pgroll)"
},
"infra": {
"paths": ["infra/**"],
"description": "Infrastructure as code"
}
},
"nx": {
"enabled": true,
"tasks": ["lint", "test", "build", "integration-test"],
"baseRef": "origin/main"
}
}When you change a file in libs/auth/, PipeCraft:
- Runs
nx show projects --affectedto find impacted projects - Discovers that
frontend,backend, anduser-managementdepend onauth - Runs tests/builds for all affected projects automatically
Nx Projects (apps/ and libs/):
- Detected via
nx show projects --affected - Respects Nx dependency graph
- Uses Nx task dependencies (some libs need build before test)
Path-Based Domains (infra/ and migrations/):
- Detected via glob patterns:
infra/**,migrations/** - Not managed by Nx
- Run independently when their paths change
# Edit libs/auth/src/index.ts
git add libs/auth/
git commit -m "feat: add OAuth support to auth"
git push origin developPipeCraft will:
- Detect affected projects:
auth,user-management,admin-dashboard,frontend,backend - Run tests for all 5 projects
- Run builds for all 5 projects
- Auto-promote to staging if tests pass
- Auto-promote to main with version tag
# Edit infra/pulumi/index.ts
git add infra/
git commit -m "feat: add new load balancer"
git push origin developPipeCraft will:
- Detect
infradomain changed - Run infra tests (Pulumi preview)
- NOT run any Nx projects (nothing in apps/libs changed)
- Auto-promote through pipeline
# Edit both frontend and infra
git add apps/frontend/ infra/
git commit -m "feat: deploy frontend to new infrastructure"
git push origin developPipeCraft will:
- Detect
frontendvia Nx affected - Detect
infravia path pattern - Run tests for frontend (and its dependencies)
- Run tests for infra
- Auto-promote if all pass
┌─────────────┐
│ frontend │──┐
└─────────────┘ │
├──► auth
┌─────────────┐ │
│ backend │──┤
└─────────────┘ │
├──► database ──► logging
┌─────────────┐ │
│ widget │──┘
└─────────────┘
┌─────────────┐ ┌──────────┐
│ infra/** │ │migrations│
└─────────────┘ └──────────┘
(path-based) (path-based)
View full graph:
nx graph- Node.js 18+
- Git configured
- GitHub account
# Clone repository
git clone https://github.com/jamesvillarrubia/pipecraft-example-nx.git
cd pipecraft-example-nx
# Install dependencies
npm install
# View Nx graph
npm run graph# Run all tests
npm test
# Run affected tests
npm run affected:test
# Run specific project
npx nx test auth- Click "Use this template" on GitHub
- Clone your repo
- Customize:
- Update
nx.jsonwith your project structure - Update
.pipecraftrc.jsondomains - Add your apps and libs
- Update
- Regenerate workflows:
npx pipecraft generate
- Push and test!
git checkout develop
git pull origin develop
# Make changes to any project
echo "export const newFeature = () => {}" >> libs/auth/src/index.ts
# Commit with conventional format
git add .
git commit -m "feat(auth): add new authentication feature"
git push origin develop- Nx Affected Analysis - Determines which projects changed
- Parallel Testing - Runs tests for affected projects
- Version Calculation - Calculates semantic version
- Auto-Promote to Staging - Fast-forwards if tests pass
- Auto-Promote to Main - Fast-forwards with version tag
develop ───────────► staging ───────────► main
│ │ │
│ feat: new feature │ │
├─────────────────────┤ │
│ auto-merge │ │
└─────────────────────┼───────────────────┤
│ auto-merge │
└───────────────────► v0.2.0
Most libraries don't need to be built before testing:
- auth, logging, config
- user-management, notifications
- reporting, admin-dashboard
Configured in nx.json:
{
"targetDefaults": {
"test": {
"dependsOn": []
}
}
}Some libraries require build artifacts:
- database - Compiled TypeScript for DB connections
- analytics - Built modules for event tracking
- billing - Compiled payment processing code
Configured in each project.json:
{
"targets": {
"test": {
"dependsOn": ["build"]
}
}
}# Verify Nx can detect changes
npx nx show projects --affected --base=origin/main
# Check git history is available
git log --oneline -10
# Verify base branch exists
git fetch origin
git branch -r | grep main-
Check Nx dependencies:
nx graph
-
Verify project.json dependencies:
{ "implicitDependencies": ["shared-lib"] } -
Check PipeCraft is using correct base: In workflow logs, look for:
NX_BASE=origin/main npx nx show projects --affected
-
Verify paths in
.pipecraftrc.json:{ "domains": { "infra": { "paths": ["infra/**"] // Must match actual directory } } } -
Test path detection locally:
git diff --name-only origin/main | grep "infra/"
Add custom tasks to PipeCraft config:
{
"nx": {
"tasks": ["lint", "test", "build", "e2e", "deploy"]
}
}Add more non-Nx domains:
{
"domains": {
"infra": { "paths": ["infra/**"] },
"migrations": { "paths": ["migrations/**"] },
"docs": { "paths": ["docs/**"] },
"scripts": { "paths": ["scripts/**"] }
}
}Some Nx projects might not have all tasks. PipeCraft handles this gracefully - if a task doesn't exist for a project, it's skipped.
This repository includes an advanced test suite for validating PipeCraft's Nx integration. See:
- PIPECRAFT_INTEGRATION.md - Integration details
- TEST-SUITE-README.md - Test suite documentation
- TEST-REPORT.md - Latest test results
Run the test suite:
npm run test:pipecraft- pipecraft-example-minimal - Simplest setup, quickstart
- pipecraft-example-basic - Multi-domain without Nx
- pipecraft-example-gated - Enterprise gated workflow
MIT © PipeCraft Team