module-scaffold
Use when creating a new feature module in libs/. Triggers on "create a module", "add a feature module", "scaffold module for X", or "new library for Y"
When & Why to Use This Skill
This Claude skill automates the end-to-end scaffolding process for new feature modules within a monorepo environment. It streamlines developer workflows by automatically creating standardized directory structures, generating boilerplate code from templates (including package.json, tsconfig, and Prisma schemas), and performing necessary registrations in root configurations. By enforcing project-specific naming conventions and architectural patterns, it significantly reduces manual setup errors and accelerates the transition from planning to development.
Use Cases
- Case 1: Rapidly scaffolding a full-stack feature module including frontend pages, backend routes, and database models with a single command.
- Case 2: Creating a shared utility library or business logic module to be consumed by multiple applications within a monorepo.
- Case 3: Automating the complex registration process of new modules in root TypeScript configurations and application entry points (e.g., Vite or Express apps).
- Case 4: Ensuring architectural consistency across a large engineering team by using standardized templates for new domain areas like 'payments' or 'authentication'.
| name | module-scaffold |
|---|---|
| description | Use when creating a new feature module in libs/. Triggers on "create a module", "add a feature module", "scaffold module for X", or "new library for Y" |
Module Scaffolding Skill
This skill automates creation of new feature modules in the libs/ directory, following the project's conventions and patterns.
When to Use
- User asks to create a new feature/module
- User wants to add a new library to the monorepo
- User needs a new domain area (e.g., "authentication", "payments", "notifications")
Module Types
| Type | Description | Includes |
|---|---|---|
| Full | Complete feature module | pages + routes + database + assets |
| Pages only | Web frontend only | pages + assets |
| API only | Backend API only | routes |
| Shared | Reusable code | business logic, no routes |
Step-by-Step Instructions
Step 1: Gather Requirements
Ask the user for:
- Module name (kebab-case, e.g.,
user-management) - Module type (full/pages/api/shared)
- Whether it needs database models (yes/no)
Step 2: Create Directory Structure
# For full module:
mkdir -p libs/{name}/src/pages
mkdir -p libs/{name}/src/routes
mkdir -p libs/{name}/src/locales
mkdir -p libs/{name}/src/assets/css
mkdir -p libs/{name}/src/assets/js
mkdir -p libs/{name}/prisma
# For pages-only:
mkdir -p libs/{name}/src/pages
mkdir -p libs/{name}/src/locales
mkdir -p libs/{name}/src/assets/css
# For API-only:
mkdir -p libs/{name}/src/routes
# For shared library:
mkdir -p libs/{name}/src
Step 3: Generate Files
Use the templates in assets/ to create:
libs/{name}/package.json - from
package.json.template- Replace
{{MODULE_NAME}}with the kebab-case module name - Remove
build:nunjucksscript if no pages directory
- Replace
libs/{name}/tsconfig.json - from
tsconfig.json.template- No modifications needed
libs/{name}/src/config.ts - from
config.ts.template- Remove unused exports based on module type:
- No pages? Remove
pageRoutes - No routes? Remove
apiRoutes - No database? Remove
prismaSchemas - No assets? Remove
assets
- No pages? Remove
- Remove unused exports based on module type:
libs/{name}/src/index.ts - from
index.ts.template- Add business logic exports as they're created
libs/{name}/prisma/schema.prisma - from
schema.prisma.template(if database needed)- Replace
{{MODULE_NAME}}with module name - Replace
{{ModelName}}with PascalCase model name (e.g.,PaymentTransaction) - Replace
{{table_name}}with snake_case table name (e.g.,payment_transaction)
- Replace
Step 4: Register Module
4a. Root tsconfig.json
Add to compilerOptions.paths:
"@hmcts/{name}": ["libs/{name}/src"]
4b. Web App (if module has pages)
In apps/web/src/app.ts, add import:
import { pageRoutes as {camelName}Pages } from "@hmcts/{name}/config";
Add to createSimpleRouter call or router setup.
4c. API App (if module has routes)
In apps/api/src/app.ts, add import:
import { apiRoutes as {camelName}Routes } from "@hmcts/{name}/config";
Add to createSimpleRouter call.
4d. Vite Config (if module has assets)
In apps/web/vite.config.ts, add import:
import { assets as {camelName}Assets } from "@hmcts/{name}/config";
Add to createBaseViteConfig array.
4e. Prisma Schema Discovery (if module has database)
In libs/postgres-prisma/src/schema-discovery.ts, add import:
import { prismaSchemas as {camelName}Schemas } from "@hmcts/{name}/config";
Add to schemaPaths array.
Step 5: Verify Setup
Run these commands to verify the module is set up correctly:
yarn # Install dependencies
yarn build # Verify TypeScript compiles
yarn lint # Check for lint errors
Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Module directory | kebab-case | libs/user-management/ |
| Package name | @hmcts/{kebab} | @hmcts/user-management |
| Import alias | @hmcts/{kebab} | @hmcts/user-management |
| Config variable | camelCase + type | userManagementPages |
| File names | kebab-case | user-service.ts |
Conversion Helper
kebab-case to camelCase for imports:
user-management→userManagementcouncil-tax→councilTaxfooter-pages→footerPages
Template Files
Templates are located in .claude/skills/module-scaffold/assets/:
package.json.template- Package configurationtsconfig.json.template- TypeScript configurationconfig.ts.template- Module config exportsindex.ts.template- Business logic exportsschema.prisma.template- Database model template (for modules with database)
Example: Full Module Creation
Creating a payment-gateway module:
Create directories:
mkdir -p libs/payment-gateway/src/{pages,routes,locales,assets/css} mkdir -p libs/payment-gateway/prismaCreate package.json with name
@hmcts/payment-gatewayCreate tsconfig.json extending root
Create src/config.ts with all exports
Create src/index.ts placeholder
Create prisma/schema.prisma with model:
model PaymentTransaction { id String @id @default(cuid()) amount Int status String createdAt DateTime @default(now()) @map("created_at") @@map("payment_transaction") }Register in tsconfig.json:
"@hmcts/payment-gateway": ["libs/payment-gateway/src"]Register in apps/web/src/app.ts:
import { pageRoutes as paymentGatewayPages } from "@hmcts/payment-gateway/config";Run verification:
yarn && yarn build && yarn lint