Skip to content

saul-paulus/node-module-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Node Module Generator Banner

πŸš€ Node Module Generator (NMG)

The ultimate CLI companion for rapid, enterprise-grade Node.js scaffolding.

CI Status NPM Version NPM Downloads License


πŸ›οΈ Architecture Overview

Node Module Generator (NMG) enforces Clean Architecture principles to ensure your backend remains scalable, testable, and decoupled. It is purpose-built for high-performance Express.js environments using Awilix for Dependency Injection.

Layered Structure

graph TD
    UI[Interfaces Layer: Controllers & Routes] --> APP[Application Layer: Use Cases & DTOs]
    APP --> DOM[Domain Layer: Entities & Repository Interfaces]
    INF[Infrastructure Layer: Repository Impl & External Services] --> DOM
    
    subgraph "Inner Layers"
    DOM
    APP
    end
    
    subgraph "Outer Layers"
    UI
    INF
    end
Loading

πŸ”₯ Key Features

  • πŸ’Ž Clean Architecture by Design: Strict separation into Domain, Application, Infrastructure, and Interface layers.
  • πŸ’‰ Native Dependency Injection: Fully pre-configured for Awilix, providing seamless DI management.
  • πŸ§ͺ Test-Ready Scaffolding: Automatically generates Jest test suites for Controllers and Use Cases.
  • πŸš€ Modern Tooling: Native support for ES Modules (ESM), Prisma ORM, and Joi/Zod DTO patterns.
  • πŸ€– Granular Control: Generate full modules or individual components (UseCases, Repos, DTOs) without disrupting existing code.

πŸ“¦ Installation

Prerequisites

  • Node.js: v18.0.0 or higher (LTS recommended)
  • NPM, Yarn, or PNPM

Global Installation (Recommended)

Install NMG globally to access the command from any project.

npm install -g @saulpaulus17/node-module-generator

Direct Execution

Run it on-the-fly without a permanent installation:

npx @saulpaulus17/node-module-generator <command> <name>

πŸ› οΈ Target Project Dependencies

To ensure the modules generated by NMG function correctly, your main project must have the following core dependencies installed:

Production Dependencies

npm install express awilix @prisma/client

Development Dependencies

npm install --save-dev jest

Tip

These dependencies are essential because the generated code relies on Express for routing, Awilix for Dependency Injection, and Prisma for the data layer.


πŸš€ Detailed Usage

1. Generating a Full Module

Scaffolds a complete standard architecture with all 4 layers and initial unit tests.

nmg module Auth

2. Generating Individual Components

Quickly add specific components to an existing module structure.

# Add a new UseCase (e.g., login) to the Auth module
nmg usecase login --module=Auth

# Add a Repository Interface and Implementation (Prisma)
nmg repository User

# Add a DTO validation schema
nmg dto userRegistration --module=Auth

πŸ“‚ Project Blueprint

Scaffolding a module (e.g., nmg module Product) produces the following industry-standard structure:

src/modules/Product/
β”œβ”€β”€ application/                 
β”‚   β”œβ”€β”€ dtos/                    # DTO schemas (e.g., product.dto.js)
β”‚   └── usecases/                # Business orchestration
β”‚       β”œβ”€β”€ ProductUseCase.js    # Logic implementation
β”‚       └── ProductUseCase.test.js # Unit tests
β”œβ”€β”€ domain/                      
β”‚   β”œβ”€β”€ entities/                # Business entity definitions
β”‚   β”‚   └── Product.js
β”‚   └── repositories/            # Repository Interface (Contracts)
β”‚       └── ProductRepository.js
β”œβ”€β”€ infrastructure/              
β”‚   β”œβ”€β”€ repositories/            # Implementation (default: Prisma)
β”‚   β”‚   └── PrismaProductRepository.js
β”œβ”€β”€ interfaces/                  
β”‚   β”œβ”€β”€ controllers/             # Express handlers
β”‚   β”‚   β”œβ”€β”€ ProductController.js
β”‚   β”‚   └── ProductController.test.js
β”‚   └── routes/                  # Express routes & method binding
β”‚       └── product.routes.js
└── Product.module.js            # Central Awilix Module Registration

πŸ› οΈ Post-Scaffolding Integration

To finalize your new module integration, follow these standard steps:

  1. DI Registration: Open src/container.js and register any specific repository aliases or scoped usecases.
  2. Route Mounting: Mount the generated router in src/app.js:
    app.use('/api/v1/product', container.resolve('productRoutes'));
  3. Detailed Implementation: Build out the specific logic in the generated templates (which are already integrated via Awilix).

🀝 Contributing & Support

We welcome contributions from the community!

  1. Fork the project.
  2. Create your Feature Branch (git checkout -b feat/NewFeature).
  3. Commit your changes (git commit -m 'feat: Add some NewFeature').
  4. Push to the Branch (git push origin feat/NewFeature).
  5. Open a Pull Request.

πŸ“ License

Distributed under the MIT License. See LICENSE for more information.


Built with ❀️ for modern Node.js developers

Copyright Β© 2024 saul-paulus

About

A robust CLI tool for scaffolding Express.js projects using Clean Architecture & Dependency Injection

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors