A NestJS-based foundation package for building scalable applications. This package provides a set of common utilities, configurations, and best practices for NestJS applications.
- Installation
- Configuration
- Features
- Framework Implementation
- Messaging with NATS
- Contributing
- License
# Using npm
npm install @vechr/vechr-base
# Using yarn
yarn add @vechr/vechr-base
# Using pnpm
pnpm add @vechr/vechr-base- First, create a
.npmrcfile in your project root with the following content:
@vechr:registry=https://npm.pkg.github.com- Authenticate with GitHub Packages:
npm login --registry=https://npm.pkg.github.com- Built-in tracing and monitoring
- Database integration with Prisma
- Caching support
- Authentication and authorization
- API documentation with Swagger
- Health checks
- Logging with Winston
- And more...
The package includes a comprehensive shared framework implementation that provides common utilities and patterns for building NestJS applications. Here's an overview of the available components:
src/frameworks/shared/
├── controllers/ # Base controllers and RPC implementations
├── decorators/ # Custom decorators for metadata and configuration
├── exceptions/ # Custom exception handlers
├── filters/ # Exception filters
├── guards/ # Authentication and authorization guards
├── interceptors/ # Request/response interceptors
├── middlewares/ # Custom middleware implementations
├── pipes/ # Data transformation and validation pipes
├── responses/ # Standardized response formats
└── utils/ # Utility functions and helpers
- Base controllers with common CRUD operations
- RPC-extended controllers for microservice communication
- Custom decorators for metadata handling
- Configuration decorators
- Authentication decorators
- Authentication guards
- Role-based access control
- Permission guards
- Request/response transformation
- Logging interceptors
- Error handling interceptors
- Request validation
- Authentication middleware
- Logging middleware
- Data validation pipes
- Transformation pipes
- Custom validation rules
- Standardized response formats
- Error response handling
- Success response templates
import { Controller, Get } from '@nestjs/common';
import { RpcExtendedController } from '@vechr/vechr-base';
@RpcExtendedController('service')
export class ExampleController {
@Get()
async getData() {
// Your implementation
}
}The package includes built-in support for NATS messaging with authentication and context handling. Here are some examples of how to interact with the messaging endpoints using NATS CLI:
nats --tlsca=./certificate/self-signed/yourCA.pem \
--tlscert=./certificate/self-signed/nats/yourCert.crt \
--tlskey=./certificate/self-signed/nats/yourKey.key \
--server=nats://localhost:4222 \
--trace \
req "Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getSystemProperties.A001" \
'{}' \
-H "Authorization: Bearer <your-access-token>" \
-H "refresh-token: <your-refresh-token>"Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.exit.A001`
Body: `'{}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getConfiguration.A001`
Body: `'{"body": {"name": "default"}}'` (default, system, environment)
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getConfigurationNames.A001`
Body: `'{}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getConfigurationParameter.A001`
Body: `'{"body": {"paramName": "NATS_URL"}}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getControlList.A001`
Body: `'{"body": {"handlerType": "SystemMonitor"}}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getManifestData.A001`
Body: `'{}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getMemoryInfo.A001`
Body: `'{}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getStatus.A001`
Body: `'{}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.getSystemProperties.A001`
Body: `'{}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemControl.restart.A001`
Body: `'{}'`
Subject: `Autocar.ID_KWG.Molding.Dev.Service.Auth.SystemMonitor.health.A001`
Body: `'{}'`
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.