This template creates production-ready NestJS npm packages with complete CI/CD, testing, and code quality enforcement.
{
"name": "@ciscode/YOUR_PACKAGE_NAME",
"version": "0.0.0",
"description": "YOUR_PACKAGE_DESCRIPTION",
"repository": {
"url": "git+https://github.com/CISCODE-MA/YOUR_REPO_NAME.git"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts"
}env:
SONAR_PROJECT_KEY: "CISCODE-MA_YOUR_REPO_NAME"src/example-kit.*→src/your-package-name.*src/controllers/example.controller.ts→ Your controllersrc/services/example.service.ts→ Your servicesrc/entities/example.entity.ts→ Your entitysrc/repositories/example.repository.ts→ Your repositorysrc/guards/example.guard.ts→ Your guardsrc/decorators/example.decorator.ts→ Your decoratorsrc/dto/create-example.dto.ts→ Your DTOs
README.md- Add your package description, features, and usageCONTRIBUTING.md- Already complete (template-ready)CODE_OF_CONDUCT- Already completeSECURITY- Already complete
- Copy
.env.exampleto.env - Update default values for your needs
src/
├── index.ts # Public API exports
├── your-package-name.module.ts # NestJS module
├── controllers/ # HTTP request handling
├── services/ # Business logic
├── entities/ # Domain models
├── repositories/ # Data access layer
├── guards/ # Authentication/Authorization
├── decorators/ # Custom decorators
├── dto/ # Data Transfer Objects
├── filters/ # Exception filters
├── middleware/ # HTTP middleware
└── config/ # Configuration
Separation of Concerns:
- Controllers → HTTP layer only (routing, validation)
- Services → Business logic (pure, testable)
- Repositories → Database operations (abstracted)
- Entities → Domain models (no logic)
- DTOs → Data validation (with class-validator)
npm run build # Compile TypeScript
npm run build:watch # Watch modenpm run lint # Check code with ESLint
npm run lint:fix # Autofix lint issues
npm run format # Check formatting
npm run format:write # Format all files
npm run typecheck # TypeScript type checkingnpm run test # Run unit tests
npm run test:watch # Watch mode
npm run test:cov # With coverage report
npm run test:debug # Debug modenpm run verify # Full validation: lint + typecheck + test:cov
npm run prepublishOnly # Auto-runs on npm publish- Runs:
npm run lint+npm run typecheck+npm run test+npm run build - Blocks merge if any check fails
- Full validation + coverage + SonarCloud analysis (optional)
- Verifies production readiness
- Auto-runs on
git tag v*.*.* && git push origin master --tags - Publishes to NPM with provenance
Uses changesets for semantic versioning:
npm run changeset # Create changeset
npm run version-packages # Update versions
npm run release # Publish (CI will handle this)- Merge features to
developwith changesets - When ready, create PR to
master - Tag:
git tag v1.0.0 && git push origin master --tags - CI automatically publishes to NPM
class-transformer- DTO serializationclass-validator- Validation decorators
@nestjs/common- NestJS core@nestjs/core- NestJS runtime@nestjs/platform-express- HTTP serverreflect-metadata- Decorator supportrxjs- Reactive streams
- Testing: Jest + ts-jest + @nestjs/testing
- Linting: ESLint + @typescript-eslint
- Formatting: Prettier
- TypeScript: Strict mode with path aliases
- Git Hooks: Husky + lint-staged
- Publishing: semantic-release + changesets
- Runs lint-staged:
prettier --write+eslint --fix - Prevents commits with formatting/lint issues
- Runs
npm run typecheck+npm run test - Prevents pushing broken code
| File | Purpose |
|---|---|
tsconfig.json |
TypeScript compilation (includes path aliases) |
tsconfig.build.json |
Build-specific settings |
tsconfig.eslint.json |
ESLint-specific settings |
jest.config.ts |
Jest test runner config |
eslint.config.js |
ESLint rules (flat config format) |
.prettierrc |
Prettier formatting rules |
.editorconfig |
Editor settings (cross-IDE) |
.npmrc |
NPM behavior (strict engines) |
.npmignore |
Exclude from published package |
.env.example |
Environment template |
.husky/ |
Git hooks setup |
lint-staged.config.js |
Pre-commit tasks |
# Initial setup
git clone <repo> && cd <repo> && npm install
# Development
npm run build # Build once
npm run build:watch # Build on file change
# Quality assurance
npm run verify # Full validation
# Testing
npm run test:cov # Coverage report
# Preparing release
npm run changeset # Document changes
npm run version-packages # Update package.jsonIf using SonarCloud for code quality:
- Repository secret - Add
SONAR_TOKENto GitHub - Trigger - Manually in Actions tab or via workflow_dispatch
- Project Key - Already configured in
.github/workflows/release-check.yml
- Documentation → README.md, CONTRIBUTING.md
- Issues → GitHub Issues
- Security → See SECURITY file