NexGenStudioDev/FastKit

Build Pluggable Product Feature Module (CRUD + Clean Architecture)

Aperta

#11 aperta il 27 giu 2025

 (0 commenti) (0 reazioni) (0 assegnatari)TypeScript (0 fork)auto 404
TypeScriptbackenddocumentationenhancementgood first issuenpmquestion

Metriche repository

Star
 (1 stella)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

🛍️ Product Feature Module (FastKit-Style)

🧩 Description

Create a fully modular, reusable Product module that can be plugged into any Express.js app. This feature should support full CRUD operations and follow the FastKit architecture with class-based services, controllers, validators, and constants.

The Product module should:

  • Manage product items (title, description, price, stock, images, etc.)

  • Allow filtering and pagination

  • Be DB-agnostic and testable

  • Be developer-friendly and easy to extend

  • Be usable directly via the ProductController class

🧱 Why This Is Important

  • 🔄 Most real-world apps (ecommerce, rentals, marketplaces) need product listings

  • ✅ Helps avoid writing product logic from scratch

  • ⚙️ Encourages clean separation between service, validation, and controller

  • 🧩 Can be integrated into any project with zero-boilerplate


🟢 Difficulty Level: Intermediate

Requires:

  • Express + TypeScript

  • Understanding of modular coding

  • Knowledge of API design and validation

  • Optional: Pagination and filtering logic

✅ Tasks

📁 Folder Structure

src/
└── features/
    └── Product/
        └── v1/
            ├── Product.controller.ts       # All controller methods
            ├── Product.service.ts          # Business logic
            ├── Product.validators.ts       # Zod/Joi validation
            ├── Product.constant.ts         # Error messages, enums
            ├── Product.model.ts            # Abstract model (DB-agnostic)
            ├── Product.middleware.ts       # Optional middlewares
            ├── Product.demo.ts             # Usage sample
            └── README.md                   # Docs and usage

🎯 Core CRUD Operations

  • Controller (ProductController)

  • Expose bind-safe class methods:

class ProductController {
  createProduct(req, res): Promise<void>;
  getProductById(req, res): Promise<void>;
  getAllProducts(req, res): Promise<void>;
  updateProduct(req, res): Promise<void>;
  deleteProduct(req, res): Promise<void>;
}

Service (ProductService)

Handles logic:

  • Insert/update product

  • Handle pagination & filtering

  • Business checks (e.g., price ≥ 0, stock limits)

Validators

  • Use Zod or Joi for payload validation:

  • createProductSchema

  • updateProductSchema

  • Reusable middleware

Constants

export const PRODUCT_ERRORS = {
  NOT_FOUND: 'Product not found',
  INVALID_ID: 'Invalid product ID',
  ALREADY_EXISTS: 'Product already exists',
};

Model (DB-Agnostic)

  • Interface-based model (can integrate with MongoDb)
interface IProduct {
  id: string;
  title: string;
  description: string;
  price: number;
  stock: number;
  category?: string;
  images?: string[];
}


📘 README.md Content

Include:

  • How to use the controller

  • Example route usage

  • List of methods

  • How to use validation middleware

🧪 Product.demo.ts

Sample:

const productController = new ProductController();

router.post(
  '/products',
  validateCreateProduct,
  productController.createProduct
);

router.get('/products/:id', productController.getProductById);
router.get('/products', productController.getAllProducts);
router.put(
  '/products/:id',
  validateUpdateProduct,
  productController.updateProduct
);
router.delete('/products/:id', productController.deleteProduct);


🎯 Expected Outcome

[x] Fully usable ProductController class

[x] Reusable validation and service logic

[x] Pagination and filtering support

[x] Developer can just import, bind, and use the controller

[x] Can be extended later for search, ratings, etc.


🙋🏻‍♂️ Looking For

Contributors for:

  • Adding filters (by price, category, stock)

  • Adding sorting (price asc/desc, createdAt)

  • Adding bulk insert/update/delete

  • Adding product image upload helper (Cloudinary, S3)

  • Writing sample Prisma or Mongoose model

🛠 Example Usage

import { ProductController } from 'fastkit-product';

const productController = new ProductController();

router.post('/products', productController.createProduct);

Guida contributor