A CLI tool for automating backend component generation in Express.js, including modules, schemas, routes, services, and more.
npm install backend-smithBackend Smith is a custom CLI tool, invoked using the command bs, designed to help automate the creation of various components such as modules, schemas, routes, services, controllers, validations, and DTOs for an Express.js backend. It simplifies backend structure generation.
- Installation
- Usage
- Available Commands
- Command Options
- Examples
- Error Handling
To use Backend Smith, install it globally or locally.
npm install -g backend-smith
To use it locally in your project:
npm install backend-smith --save-dev
Then, you can run it with npx:
npx bs
Run the CLI using the following syntax:
bs
Backend Smith supports the following operations:
| Operation | Description |
|-----------------------|---------------------------------------------|
| create | Creates a base structure for the given name |
| create:module | Creates a module with the specified fields |
| create:schema | Creates a schema with the specified fields |
| create:route | Creates a route |
| create:service | Creates a service |
| create:controller | Creates a controller |
| create:validation | Creates validation logic for the fields |
| create:dto | Creates a Data Transfer Object (DTO) |
- : Specifies the type of component to create (e.g., create:module, create:route, etc.).
- : The name of the component to be created.
- [fields...]: An optional list of fields to be used in schemas, DTOs, or validations. Fields should be provided in the format fieldName:fieldType (e.g., username:String, age:Number).
You can also pass fields as an array or object:
- Array: Pass multiple fields as separate arguments (e.g., username:String age:Number email:String).
- Object: Pass fields in the format { fieldName: fieldType } (e.g., { username:String, age:Number, email:String }).
- enum: Pass fields in the format fieldName:fieldTypes (e.g., role:USER|ADMIN).
To mark a field as required, prepend the field name with an asterisk (e.g., *username:String).
1. Create a base structure:
bs create app-name
2. Create a module with fields:
bs create:module user username:String age:Number email:String *role:USER|ADMIN
3. Create a schema:
bs create:schema user username:String age:Number email:String *role:USER|ADMIN
4. Create a route:
bs create:route user
5. Create a service:
bs create:service user
6. Create a controller:
bs create:controller user
7. Create validation for fields:
bs create:validation user username:String age:Number email:String *role:USER|ADMIN
8. Create a Data Transfer Object (DTO):
bs create:dto user username:String age:Number email:String *role:USER|ADMIN
- If no operation is provided, the CLI will log:
Operation is required!
- If no name is provided for the component, the CLI will log:
Name is required!
- If an invalid operation is provided, the CLI will log:
Invalid
- Bad pattern
When using special characters like [], {} and | in the terminal, make sure to escape them or wrap the entire field in quotes.
Example:
bs create:schema test "tags:[String]" "profile:{bio:String website:String}" "role:USER|ADMIN" "addresses:[{street:String city:String}]"
Contributions are welcome! To contribute to Backend Smith, feel free to fork the repository and submit a pull request.
Repository: Backend Smith GitHub