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.
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
- π 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.
- Node.js: v18.0.0 or higher (LTS recommended)
- NPM, Yarn, or PNPM
Install NMG globally to access the command from any project.
npm install -g @saulpaulus17/node-module-generatorRun it on-the-fly without a permanent installation:
npx @saulpaulus17/node-module-generator <command> <name>To ensure the modules generated by NMG function correctly, your main project must have the following core dependencies installed:
npm install express awilix @prisma/clientnpm install --save-dev jestTip
These dependencies are essential because the generated code relies on Express for routing, Awilix for Dependency Injection, and Prisma for the data layer.
Scaffolds a complete standard architecture with all 4 layers and initial unit tests.
nmg module AuthQuickly 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=AuthScaffolding 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
To finalize your new module integration, follow these standard steps:
- DI Registration: Open
src/container.jsand register any specific repository aliases or scoped usecases. - Route Mounting: Mount the generated router in
src/app.js:app.use('/api/v1/product', container.resolve('productRoutes'));
- Detailed Implementation: Build out the specific logic in the generated templates (which are already integrated via Awilix).
We welcome contributions from the community!
- Fork the project.
- Create your Feature Branch (
git checkout -b feat/NewFeature). - Commit your changes (
git commit -m 'feat: Add some NewFeature'). - Push to the Branch (
git push origin feat/NewFeature). - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more information.
Built with β€οΈ for modern Node.js developers
Copyright Β© 2024 saul-paulus