Skip to content

CISCODE-MA/MailKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

NestJS Developer Kit (Template)

A professional template for creating reusable NestJS npm packages with best practices, standardized structure, and AI-friendly development workflow.

🎯 What You Get

  • βœ… CSR Architecture - Controller-Service-Repository pattern
  • βœ… TypeScript - Strict mode with path aliases
  • βœ… Testing - Jest with 80% coverage threshold
  • βœ… Code Quality - ESLint + Prettier + Husky
  • βœ… Versioning - Changesets for semantic versioning
  • βœ… CI/CD - GitHub Actions workflows
  • βœ… Documentation - Complete Copilot instructions
  • βœ… Examples - Full working examples for all layers

πŸ“¦ Installation

# Clone this template
git clone https://github.com/CISCODE-MA/NestJs-DeveloperKit.git my-module
cd my-module

# Install dependencies
npm install

# Start developing
npm run build
npm test

πŸ—οΈ Architecture

src/
  β”œβ”€β”€ index.ts                    # PUBLIC API exports
  β”œβ”€β”€ {module-name}.module.ts     # NestJS module definition
  β”‚
  β”œβ”€β”€ controllers/                # HTTP Layer
  β”‚   └── example.controller.ts
  β”‚
  β”œβ”€β”€ services/                   # Business Logic
  β”‚   └── example.service.ts
  β”‚
  β”œβ”€β”€ entities/                   # Domain Models
  β”‚   └── example.entity.ts
  β”‚
  β”œβ”€β”€ repositories/               # Data Access
  β”‚   └── example.repository.ts
  β”‚
  β”œβ”€β”€ guards/                     # Auth Guards
  β”‚   └── example.guard.ts
  β”‚
  β”œβ”€β”€ decorators/                 # Custom Decorators
  β”‚   └── example.decorator.ts
  β”‚
  β”œβ”€β”€ dto/                        # Data Transfer Objects
  β”‚   β”œβ”€β”€ create-example.dto.ts
  β”‚   └── update-example.dto.ts
  β”‚
  β”œβ”€β”€ filters/                    # Exception Filters
  β”œβ”€β”€ middleware/                 # Middleware
  β”œβ”€β”€ config/                     # Configuration
  └── utils/                      # Utilities

πŸš€ Usage

1. Customize Your Module

// src/example-kit.module.ts
import { Module, DynamicModule } from "@nestjs/common";
import { ExampleService } from "@services/example.service";

@Module({})
export class ExampleKitModule {
  static forRoot(options: ExampleKitOptions): DynamicModule {
    return {
      module: ExampleKitModule,
      providers: [ExampleService],
      exports: [ExampleService],
    };
  }
}

2. Create Services

// src/services/example.service.ts
import { Injectable } from "@nestjs/common";

@Injectable()
export class ExampleService {
  async doSomething(data: string): Promise<string> {
    return `Processed: ${data}`;
  }
}

3. Define DTOs

// src/dto/create-example.dto.ts
import { IsString, IsNotEmpty } from "class-validator";

export class CreateExampleDto {
  @IsString()
  @IsNotEmpty()
  name: string;
}

4. Export Public API

// src/index.ts
export { ExampleKitModule } from "./example-kit.module";
export { ExampleService } from "./services/example.service";
export { CreateExampleDto } from "./dto/create-example.dto";

πŸ“ Scripts

# Development
npm run build          # Build the package
npm run build:watch    # Build in watch mode
npm run typecheck      # TypeScript type checking

# Testing
npm test               # Run tests
npm run test:watch     # Run tests in watch mode
npm run test:cov       # Run tests with coverage

# Code Quality
npm run lint           # Run ESLint
npm run format         # Check formatting
npm run format:write   # Fix formatting

# Release
npx changeset          # Create a changeset
npm run release        # Publish to npm (CI does this)

πŸ”„ Release Workflow

This template uses Changesets for version management.

1. Create a Feature

git checkout develop
git checkout -b feature/my-feature
# Make your changes

2. Create a Changeset

npx changeset

Select the change type:

  • patch - Bug fixes
  • minor - New features (backwards compatible)
  • major - Breaking changes

3. Commit and PR

git add .
git commit -m "feat: add new feature"
git push origin feature/my-feature
# Create PR β†’ develop

4. Release

  • Automation opens "Version Packages" PR
  • Merge to master to publish

πŸ§ͺ Testing

Tests are MANDATORY for all public APIs.

// src/services/example.service.spec.ts
describe("ExampleService", () => {
  let service: ExampleService;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      providers: [ExampleService],
    }).compile();

    service = module.get(ExampleService);
  });

  it("should be defined", () => {
    expect(service).toBeDefined();
  });

  it("should process data correctly", async () => {
    const result = await service.doSomething("test");
    expect(result).toBe("Processed: test");
  });
});

Coverage threshold: 80%

πŸ“š Path Aliases

Configured in tsconfig.json:

import { ExampleService } from "@services/example.service";
import { CreateExampleDto } from "@dtos/create-example.dto";
import { Example } from "@entities/example.entity";
import { ExampleRepository } from "@repos/example.repository";

Available aliases:

  • @/* β†’ src/*
  • @controllers/* β†’ src/controllers/*
  • @services/* β†’ src/services/*
  • @entities/* β†’ src/entities/*
  • @repos/* β†’ src/repositories/*
  • @dtos/* β†’ src/dto/*
  • @guards/* β†’ src/guards/*
  • @decorators/* β†’ src/decorators/*
  • @config/* β†’ src/config/*
  • @utils/* β†’ src/utils/*

πŸ”’ Security Best Practices

  • βœ… Input validation on all DTOs (class-validator)
  • βœ… Environment variables for secrets
  • βœ… No hardcoded credentials
  • βœ… Proper error handling
  • βœ… Rate limiting on public endpoints

πŸ€– AI-Friendly Development

This template includes comprehensive Copilot instructions in .github/copilot-instructions.md:

  • Module architecture guidelines
  • Naming conventions
  • Testing requirements
  • Documentation standards
  • Export patterns
  • Security best practices

πŸ“– Documentation

πŸ› οΈ Customization

  1. Rename the module: Update package.json name
  2. Update description: Modify package.json description
  3. Configure exports: Edit src/index.ts
  4. Add dependencies: Update peerDependencies and dependencies
  5. Customize structure: Add/remove directories as needed

⚠️ Important Notes

What to Export

βœ… DO export:

  • Module
  • Services
  • DTOs
  • Guards
  • Decorators
  • Types/Interfaces

❌ DON'T export:

  • Entities
  • Repositories

Entities and repositories are internal implementation details.

Versioning

  • MAJOR (x.0.0) - Breaking changes
  • MINOR (0.x.0) - New features (backwards compatible)
  • PATCH (0.0.x) - Bug fixes

πŸ“‹ Checklist Before Publishing

  • All tests passing (80%+ coverage)
  • No ESLint warnings
  • TypeScript strict mode passing
  • All public APIs documented (JSDoc)
  • README updated
  • Changeset created
  • Breaking changes documented
  • .env.example updated (if needed)

πŸ“„ License

MIT

🀝 Contributing

See CONTRIBUTING.md

πŸ†˜ Support


Made with ❀️ by CisCode

About

Transactional email for NestJS. SMTP and SendGrid and Resend adapters. Typed template system with defineTemplate. Distinct from NotificationKit.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors