leo-generator
v1.0.0
Published
Generate Express modules with Mongoose models
Maintainers
Readme
Leo Generate - Module Generator for Express & Mongoose
I'll update the README.md file to change the module generator name from "SIUUU Module Generator" to "Leo Generate" and provide a detailed description.
# Leo Generate
A powerful module generator for Express.js applications with Mongoose models.
## Features
- 🚀 Rapid module scaffolding
- 📁 Complete folder structure
- 🧩 TypeScript interfaces
- 🔄 Mongoose models
- 🎮 Express controllers
- 🛠️ Service layer
- 🛣️ RESTful routes
- ✅ Zod validation
- 🎨 Clean and consistent code structure
- 🔣 Support for enum fields with predefined values
## Installation
```bash
npm install leo-generate --globalOr use with npx:
npx leo-generateQuick Start
Generate a basic module:
leo-generate User name:string email:string age:numberThis creates:
src/app/modules/user/
├── user.interface.ts // TypeScript interfaces
├── user.model.ts // Mongoose model
├── user.controller.ts // CRUD controllers
├── user.service.ts // Business logic
├── user.route.ts // Express routes
├── user.validation.ts // Zod validation
└── user.constants.ts // ConstantsConfiguration
Via package.json
{
"moduleGenerator": {
"modulesDir": "src/app/modules",
"routesFile": "src/routes/index.ts"
}
}Via CLI
leo-generate User --modules-dir src/modules --routes-file src/routes.tsExamples
Basic CRUD Module
leo-generate Product name:string price:number description:stringModule with Required Fields
leo-generate User name!:string email!:string age:numberThe ! marks a field as required in the model and validation.
Module with Optional Fields
leo-generate Post title:string content:string author?:stringThe ? marks a field as optional.
Module with References
leo-generate Order items:array:objectid:Product customer:objectid:UserModule with Enum Values
leo-generate Product name:string category:enum[Electronics,Clothing,Food] status:enum[Active,Inactive]Module with Nested Objects
leo-generate Order customer:object customerId:string name:string address:stringModule with Array of Objects
leo-generate Product name:string variants:array:object name:string price:number stock:numberModule with File Upload
leo-generate Product name:string price:number image:stringGenerated Files
Interfaces
- TypeScript interfaces for type safety
- Support for nested objects and arrays
- Proper MongoDB typing with ObjectId
Models
- Mongoose schema definitions
- Proper field types and validations
- Support for references and nested schemas
Controllers
- Full CRUD operations
- File upload handling
- Proper error handling
- Response formatting
Routes
- RESTful endpoints
- Validation middleware
- File upload middleware
- Authentication hooks
Validation
- Request body validation
- Type checking
- Custom error messages
- Required/optional fields
API Endpoints
For a module named "Product":
POST /api/v1/products - Create product
GET /api/v1/products - Get all products
GET /api/v1/products/:id - Get single product
PATCH /api/v1/products/:id - Update product
DELETE /api/v1/products/:id - Delete productBest Practices
- Use singular names for modules (e.g., "User" not "Users")
- Mark required fields with "!"
- Use descriptive field names
- Follow naming conventions for file fields (image, file, media)
- For enum fields, use the format
fieldname:enum[VALUE1,VALUE2,VALUE3]
Common Patterns
File Upload Module
leo-generate Media title:string description:string file:stringUser Authentication Module
leo-generate User name!:string email!:string password!:string role:enum[admin,user,editor]Blog Post Module
leo-generate Post title!:string content!:string author:objectid:User tags:array:string status:enum[draft,published,archived]Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
