A CLI tool to generate backend structures for Node.js applications with support for multiple databases and a visually appealing user interface.
BackTool simplifies the process of setting up a Node.js backend by generating a complete project structure, including a server entry point, models, database configuration, controllers, routes, middleware, and a customized package.json
. It supports MongoDB, PostgreSQL, MySQL, and SQLite, allowing developers to quickly scaffold a backend tailored to their preferred database.
- Database Support: Generates configurations and models for MongoDB, PostgreSQL, MySQL, and SQLite.
- Language Support: Generates projects in both JavaScript and TypeScript with proper configurations.
- Interactive Prompts: Uses
inquirer
for styled, user-friendly prompts with custom prefixes and validation. - Visual Feedback: Includes an ASCII art banner (
figlet
), colored output (chalk
), and progress spinners (ora
). - Non-Interactive Mode: Supports command-line arguments for automation (e.g.,
backtool --project my-app --database MongoDB
). - Complete Backend Structure: Creates
server.js
,package.json
, and directories formodels
,config
,controllers
,routes
, andmiddleware
. - Customized package.json: Generates a
package.json
with the project name, scripts (start
,dev
), and dependencies. - Automatic Package Installation: Installs required dependencies (e.g.,
express
,mongoose
,pg
,mysql2
,sqlite3
) andnodemon
as a dev dependency. - File Overwrite Protection: Prompts users before overwriting existing files (e.g.,
server.js
,package.json
, model files). - Extensible: Easily add new databases or structure components by updating the template folder.
Install BackTool globally to use it from any directory:
npm install -g backtool
Alternatively, clone the repository and link it locally:
git clone https://github.com/Amanbig/backtool.git
cd backtool
npm install
npm link
Run BackTool without arguments to use interactive prompts:
backtool
or directly using:
npx backtool@latest
This will display an ASCII banner and prompt for:
- Project name (e.g.,
my-app
) - Database choice (MongoDB, MySQL, PostgreSQL, or SQLite)
Specify options directly to skip prompts:
backtool --project my-app --database MongoDB
-p, --project <name>
: Specify the project name (default:my-app
).-d, --database <type>
: Specify the database (MongoDB, MySQL, PostgreSQL, SQLite).-l, --language <type>
: Specify the language (JavaScript, TypeScript).-f, --force
: Force overwrite of existing files without prompting.-u, --uri <uri>
: Specify database connection URI.-v, --version
: Display the version number.-h, --help
: Show help information.
Running BackTool creates one of the following directory structures based on the chosen language:
my-app/
├── server.js
├── package.json
├── config/
│ └── database.js
├── models/
│ └── user.<database>.js
├── controllers/
│ └── authController.js
├── routes/
│ └── auth.js
├── middleware/
│ └── auth.js
├── node_modules/
└── .env
my-app/
├── server.ts
├── package.json
├── tsconfig.json
├── src/
│ ├── config/
│ │ └── database.ts
│ ├── models/
│ │ └── user.<database>.ts
│ ├── controllers/
│ │ └── authController.ts
│ ├── routes/
│ │ └── auth.ts
│ ├── middleware/
│ │ └── auth.ts
│ └── types/
│ └── express.d.ts
├── dist/ # Compiled JavaScript
├── node_modules/
└── .env
- server.[js|ts]: Entry point for the Node.js application, setting up the Express server and routes.
- package.json: Includes project configuration, scripts, and dependencies. For TypeScript projects, includes additional scripts for building and type checking.
- tsconfig.json: (TypeScript only) TypeScript compiler configuration.
- config/database.[js|ts]: Database connection and table initialization.
- models/: Database models with database-specific implementations.
- controllers/: Request handling logic including authentication.
- routes/: API route definitions.
- middleware/: Custom middleware (e.g., authentication).
- types/: (TypeScript only) Type definitions and declarations.
- dist/: (TypeScript only) Compiled JavaScript output.
The users
table/model includes fields: id
, username
, email
, password
, and created_at
.
After generating the project, navigate to the project directory and run:
# For JavaScript projects
npm start
# For TypeScript projects
npm start # Runs with ts-node
npm run build # Compiles TypeScript to JavaScript
npm run start:prod # Runs the compiled JavaScript
For development with auto-restart on file changes:
npm run dev # Works for both JavaScript and TypeScript
- MongoDB: Uses
mongoose
for schema-based modeling. - PostgreSQL: Uses
pg
with a connection pool and SQL queries. - MySQL: Uses
mysql2
with a promise-based connection pool. - SQLite: Uses
sqlite3
andsqlite
for lightweight, file-based storage.
BackTool installs the following dependencies in the generated project:
- Core Dependencies:
express
,dotenv
,cors
,jsonwebtoken
- Database-specific Dependencies:
- MongoDB:
mongoose
,bcryptjs
- PostgreSQL:
pg
,bcryptjs
- MySQL:
mysql2
,bcryptjs
- SQLite:
sqlite3
,bcryptjs
- MongoDB:
- Common:
nodemon
- TypeScript-specific (when TypeScript is selected):
typescript
ts-node
@types/node
@types/express
@types/cors
@types/jsonwebtoken
@types/bcryptjs
- Database-specific types (e.g.,
@types/mongoose
,@types/pg
)
To contribute or modify BackTool:
- Clone the repository:
git clone https://github.com/Amanbig/backtool.git
- Install dependencies:
npm install
- Update the
backtool_folder
directory with custom templates (e.g.,server.js
, models). - Test locally:
npm link backtool --project test-app --database SQLite
MIT License
For issues or feature requests, open a ticket on the GitHub repository.