agentleFS
Hive-AcademyHive-Academy/ptah-extension/.claude/skills/nx-workspace-architect/SKILL.md

nx-workspace-architect

Skill29 starsChanged 2 months agoMITView on GitHub

Nx monorepo architecture for Angular and NestJS. Use when creating a workspace, organizing or naming libraries, tags and module boundaries, custom generators or TypeScript paths. Not for React in Nx — use react-nx-patterns; not for .NET — use nx-dotnet-workspace.

  • Installs packages

The file

Files
SKILL.md

Nx Workspace Architect

Guide for building scalable, maintainable Nx monorepos with Angular and NestJS.

Activation scope

This skill activates twice in the SaaS bootstrap: once in Stage A, Step a2 of saas-workspace-initializer (derives the initial lib layout and tags from the discovery answers and bounded contexts, before scaffolding), and again per-module during Stage B (one roadmap item per chat session) when adding a new library, enforcing module boundaries on a specific module, or restructuring an existing area. Neither activation redesigns the whole workspace from scratch — Stage A sets the initial layout once; Stage B extends it per module.

Core Principle: Libs Over Apps

  • Apps: Thin shells that bootstrap and expose libraries. Minimal code.
  • Libs: Where 90%+ of code lives. Organized by domain and type.

Library Type Quick Reference

TypePlatformPurposeNamingTags
featureAngularSmart components, routes, pagesfeature-[name]type:feature
feature-apiNestJSControllers, API endpointsfeature-api-[name]type:feature
uiAngularPresentational components (dumb)ui-[name]type:ui
data-accessBothState, services, repositoriesdata-access-[name]type:data-access
utilBothPure functions, helpersutil-[name]type:util
api-interfacesBothShared DTOs, types, contractsapi-interfacestype:api-interfaces
domainBothDomain models, value objectsdomaintype:domain

Domain-Based Organization Pattern

libs/
├── [domain]/                    # e.g., user-management, inventory
│   ├── feature/                 # Angular smart components
│   ├── feature-api/             # NestJS controllers
│   ├── ui/                      # Shared UI for this domain
│   ├── data-access/             # State + API clients
│   ├── domain/                  # Domain models (if DDD)
│   └── util/                    # Domain-specific utilities
├── shared/
│   ├── ui/                      # Cross-domain UI components
│   ├── util/                    # Cross-domain utilities
│   ├── data-access/             # Cross-domain state/services
│   └── api-interfaces/          # Shared DTOs and types
└── core/
    ├── auth/                    # Authentication infrastructure
    └── config/                  # App configuration

Module Boundary Rules

Configure in eslint.config.mjs (flat config):

import nx from '@nx/eslint-plugin';

export default [
  {
    files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
    plugins: { '@nx': nx },
    rules: {
      '@nx/enforce-module-boundaries': [
        'error',
        {
          depConstraints: [
            {
              sourceTag: 'type:feature',
              onlyDependOnLibsWithTags: ['type:feature', 'type:ui', 'type:data-access', 'type:util', 'type:api-interfaces', 'type:domain'],
            },
            {
              sourceTag: 'type:ui',
              onlyDependOnLibsWithTags: ['type:ui', 'type:util', 'type:api-interfaces'],
            },
            {
              sourceTag: 'type:data-access',
              onlyDependOnLibsWithTags: ['type:data-access', 'type:util', 'type:api-interfaces', 'type:domain'],
            },
            { sourceTag: 'type:util', onlyDependOnLibsWithTags: ['type:util'] },
            {
              sourceTag: 'type:api-interfaces',
              onlyDependOnLibsWithTags: ['type:api-interfaces'],
            },
            {
              sourceTag: 'scope:shared',
              onlyDependOnLibsWithTags: ['scope:shared'],
            },
            {
              sourceTag: 'scope:*',
              onlyDependOnLibsWithTags: ['scope:shared', 'scope:*'],
            },
          ],
        },
      ],
    },
  },
];

Workspace Initialization Commands

# Create workspace
npx create-nx-workspace@latest my-workspace --preset=apps

# Add capabilities
npm install -D @nx/angular @nx/nest @nx/js

# Create apps
nx g @nx/angular:app web --style=scss --standalone --routing
nx g @nx/nest:app api

# Create domain library structure
nx g @nx/angular:lib feature --directory=user-management --standalone
nx g @nx/nest:lib feature-api --directory=user-management
nx g @nx/js:lib data-access --directory=user-management
nx g @nx/js:lib domain --directory=user-management
nx g @nx/angular:lib ui --directory=shared --standalone
nx g @nx/js:lib api-interfaces --directory=shared

TypeScript Path Configuration

In tsconfig.base.json:

{
  "compilerOptions": {
    "paths": {
      "@my-org/user-management/feature": ["libs/user-management/feature/src/index.ts"],
      "@my-org/user-management/data-access": ["libs/user-management/data-access/src/index.ts"],
      "@my-org/shared/ui": ["libs/shared/ui/src/index.ts"],
      "@my-org/shared/api-interfaces": ["libs/shared/api-interfaces/src/index.ts"]
    }
  }
}

Tagging Strategy

In each library's project.json:

{
  "tags": ["scope:user-management", "type:feature", "platform:angular"]
}

Tag Dimensions:

  • scope: - Business domain (user-management, inventory, shared)
  • type: - Library type (feature, ui, data-access, util)
  • platform: - Target platform (angular, nest, shared)

Decision Matrix

NeedAction
New workspaceSee workspace-setup.md
New domain/featureSee library-creation.md
Import errorsCheck module boundaries in eslint.config.mjs
Automate generationSee custom-generators.md
Understand lib typesSee library-types.md

References

Load these as needed for detailed guidance:

  • workspace-setup.md - Full workspace initialization guide
  • library-types.md - Deep dive on each library type
  • library-creation.md - Step-by-step library creation
  • module-boundaries.md - Boundary enforcement details
  • custom-generators.md - Building Nx generators

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.