armert-dto-for-nestjs
v1.0.1
Published
Reusable, framework-agnostic DTO package with validation rules for NestJS and TypeScript-based backend applications.
Maintainers
Readme
Armert NestJS DTO Package 🚀
🇹🇷 TANRI TÜRK'Ü KORUSUN VE YÜCELTSİN 🐺
📖 Overview
Armert DTO is an enterprise-grade, strict, and modular Data Transfer Object (DTO) library designed specifically for scalable NestJS applications. It abstracts standard e-commerce patterns into reusable, validated, and type-safe classes, ensuring your backend is robust from day one.
Unlike simple DTO collections, this package implements Domain-Driven Design (DDD) principles, strictly validating business rules at the transport layer (e.g., verifying that a product cannot have both 'Limited Stock' type and 'Unlimited' quantity simultaneously).
✨ Key Features
- 🛡️ Strict Type Safety: Full TypeScript support with
class-validatorintegration. - 🧠 Domain Logic Validation: Custom decorators to validate complex business rules cross-fields.
- 🌍 Internationalization Ready: Built-in
LocalizedTextDTOfor multi-language support. - 🏗️ Modular Architecture: Decoupled modules for
Auth,Product,Order,Cart, andPayment. - 🚀 Production Ready: Includes standard
Pagination,API Response, andBase Entitystructures.
📦 Installation
Install the package alongside its peer dependencies:
npm install armert-dto-for-nestjs class-validator class-transformer @nestjs/mapped-types @nestjs/swagger🛠️ Usage Guide
1. Authentication & User Management
Streamline your auth controller with pre-validated DTOs.
import { Body, Controller, Post } from '@nestjs/common';
import { LoginDTO, AuthResponseDTO } from 'armert-dto-for-nestjs';
@Controller('auth')
export class AuthController {
@Post('login')
async login(@Body() payload: LoginDTO): Promise<AuthResponseDTO> {
// payload.email -> validated as email
// payload.password -> validated for complexity
return this.authService.validateUser(payload);
}
}2. Advanced Product Validation
The package prevents invalid states before they reach your business logic.
import { CreateProductDTO, StockType } from 'armert-dto-for-nestjs';
const product = new CreateProductDTO();
// ❌ Error: Discount price cannot be higher than the regular price.
product.price = 100;
product.discountPrice = 150;
// ❌ Error: Stocks cannot be defined if the product creates explicit variants.
product.variants = [{ sku: 'V1', price: 10, stock: 5 }];
product.stock = 100;
// ✅ Success: Valid product structure
product.stockType = StockType.LIMITED;
product.stock = 50; 3. Order & Checkout Flow
Standardize your order processing with rigid Enums and nested object validation.
import { CreateOrderDTO, PaymentMethod } from 'armert-dto-for-nestjs';
// Automatically validates addresses UUIDs and Payment Method enums
const orderData: CreateOrderDTO = {
shippingAddressId: 'uuid-1',
billingAddressId: 'uuid-2',
paymentMethod: PaymentMethod.CREDIT_CARD,
items: [...]
};4. Pagination & filtering
Easily implement standardized pagination in your controllers.
// Controller
import { PaginationQueryDTO, PaginatedResponseDTO } from 'armert-dto-for-nestjs';
@Get()
async getAll(@Query() query: PaginationQueryDTO): Promise<PaginatedResponseDTO<UserDTO>> {
// query.page, query.limit, query.sortBy are automatically parsed & validated.
return this.userService.findAll(query);
}📂 Module Structure
| Module | Description |
| :--- | :--- |
| Common | PaginatedResponse, ApiError, BaseEntity |
| User | Auth, Profile, Role Management |
| Product | SEO, Variants, Attributes, Stock Logic |
| Order | Checkout, Status Workflow, Shipment |
| Cart | Basket Operations, Coupons |
| Review | Ratings, Comments, Moderation |
| Payment | Provider Integration, 3D Secure Handling |
🤝 Contribution & Development
We love contributions! This project is open for any kind of improvement. Whether you want to add new DTOs, improve validation logic, or fix bugs, your help is welcome.
How to contribute:
- Fork the repository.
- Clone your fork to your local machine:
git clone https://github.com/MertcanMert/armert-dto-for-nestjs.git - Create a new branch for your feature or fix:
git checkout -b feature/amazing-feature - Make your changes and commit them:
git commit -m 'feat: Add amazing feature' - Push to your branch:
git push origin feature/amazing-feature - Open a Pull Request against the
mainbranch.
Suggestions?
If you have an idea but don't know how to implement it, feel free to open a Discussion or an Issue. We are actively looking for feedback to make this the standard DTO library for NestJS e-commerce projects.
📝 License
Distributed under the ISC License. See LICENSE for more information.
