{"id":15007539,"url":"https://github.com/pranavbarthwal/backend-generator-cli-web","last_synced_at":"2026-02-13T22:51:26.772Z","repository":{"id":257247246,"uuid":"857620843","full_name":"PranavBarthwal/Backend-Generator-CLI-Web","owner":"PranavBarthwal","description":"Backend Generator CLI is a simple yet powerful command-line tool that helps you quickly scaffold a well-structured backend project. With built-in best practices and customizable code snippets, this tool is designed to streamline your development workflow and help you focus on what matters: building your application.","archived":false,"fork":false,"pushed_at":"2024-09-18T18:06:01.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T08:24:45.200Z","etag":null,"topics":["backend","expressjs","mern-stack","nodejs","npm","npm-cli","npm-package","npm-packages","npm-scripts","npmjs","reactjs","tailwindcss"],"latest_commit_sha":null,"homepage":"https://backend-gen-cli.pranavbarthwal.tech/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PranavBarthwal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-15T06:29:16.000Z","updated_at":"2024-09-18T18:06:04.000Z","dependencies_parsed_at":"2024-09-15T14:21:21.801Z","dependency_job_id":"9609251f-e9a5-4e56-9985-b704fd2095c8","html_url":"https://github.com/PranavBarthwal/Backend-Generator-CLI-Web","commit_stats":null,"previous_names":["pranavbarthwal/backend-generator-cli-web"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PranavBarthwal/Backend-Generator-CLI-Web","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PranavBarthwal%2FBackend-Generator-CLI-Web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PranavBarthwal%2FBackend-Generator-CLI-Web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PranavBarthwal%2FBackend-Generator-CLI-Web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PranavBarthwal%2FBackend-Generator-CLI-Web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PranavBarthwal","download_url":"https://codeload.github.com/PranavBarthwal/Backend-Generator-CLI-Web/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PranavBarthwal%2FBackend-Generator-CLI-Web/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278551493,"owners_count":26005388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","expressjs","mern-stack","nodejs","npm","npm-cli","npm-package","npm-packages","npm-scripts","npmjs","reactjs","tailwindcss"],"created_at":"2024-09-24T19:11:05.976Z","updated_at":"2025-10-06T02:52:05.112Z","avatar_url":"https://github.com/PranavBarthwal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/user-attachments/assets/1226438f-19e0-46e4-beff-5483e429ee69\" width=200\u003e\n\n# Backend Generator CLI\n\u003e **Now supporting AI powered code snippet generation!** 🚀\n\n![npm](https://img.shields.io/npm/dt/backend-generator-cli?color=brightgreen\u0026label=Total%20Downloads\u0026style=for-the-badge) ![npm](https://img.shields.io/npm/dw/backend-generator-cli?color=blue\u0026label=Weekly%20Downloads\u0026style=for-the-badge)\n\n**Backend Generator CLI** is a simple yet powerful command-line tool that helps you quickly scaffold a well-structured backend project. With built-in best practices and customizable code snippets, this tool is designed to streamline your development workflow and help you focus on what matters: building your application.\n\n## Key Features\n\n- **Instant Backend Setup**: Generate a clean, well-organized backend project structure with a single command.\n- **Best Practices Built-in**: The generated project follows industry-standard best practices for scalable backend development.\n- **Custom Code Snippets**: Insert predefined code snippets such as API error handling, file uploading, and more using simple CLI commands.\n- **AI-powered Custom Code Snippets**: Generate customizable code snippets using Generative AI with simple CLI commands.\n- **Modular and Extensible**: The tool allows you to customize and expand the project structure to meet your specific needs.\n\n## Index\n- [Installation](#installation)\n- [Commands](#commands)\n  - [1. run create-project](#1-run-create-project)\n  - [2. run generate-snippet](#2-run-generate-snippet-snippet-name)\n  - [3. run generate-ai-snippet](#3-run-generate-ai-snippet-snippetname)\n- [Full User Journey Example](#full-user-journey-example)\n- [Future Enhancements](#future-enhancements)\n- [License](#license)\n\n---\n\n## Installation\n\nTo install the CLI globally, use `npm`:\n\n```bash\nnpm install -g backend-generator-cli\n```\n\nAfter installation, you will have access to two main commands: `create-project` to generate the backend structure and `generate-snippet` to inject code snippets.\n\n## Commands\n\n### 1. `run create-project`\nGenerate a new backend project with a pre-configured folder structure:\n\n```bash\nrun create-project\n```\n\nThis command will create a new backend project structure in your current directory. Here's what the generated structure looks like:\n\n```\n.\n├── src/\n│   ├── controllers/      # Controllers for handling requests and responses\n│   ├── db/               # Database connection and configuration\n│   ├── middlewares/      # Middlewares for handling validation and request processing\n│   ├── models/           # Data models (e.g., Mongoose models, SQL models)\n│   ├── routes/           # API route definitions\n│   ├── utils/            # Utility functions and helpers\n│   ├── app.js            # Main app setup and configuration\n│   ├── constants.js      # Application-wide constants\n│   └── index.js          # Entry point of the backend server\n├── .env.sample           # Sample environment configuration\n├── .gitignore            # Git ignore file for version control\n├── .prettierignore       # Prettier ignore file\n├── .prettierrc           # Prettier configuration\n├── package.json          # Project dependencies and scripts\n└── README.md             # Documentation\n```\n\nThis structure is clean, easy to navigate, and ready to be extended with your own business logic and data models.\n\n### 2. `run generate-snippet \u003csnippet-name\u003e`\n\nGenerate and inject predefined code snippets into your project. Snippets are placed in individual files in your current working directory. \n\nExample:\n\n```bash\nrun generate-snippet multer-file-upload\n```\n\nThis command will create a new file `multer-file-upload.js` in the current working directory, containing a pre-configured snippet for handling file uploads using `multer`.\n\n### Available Snippets\n\n1. **`async-ops-handler`**:\n   Handles asynchronous operations with error handling.\n\n   **Code Snippet**:\n   ```js\n    const asyncHandler = (requestHandler) =\u003e {\n        return (req, res, next) =\u003e {\n            Promise\n            .resolve(requestHandler(req, res, next))\n            .catch((err) =\u003e next(err))\n        }\n    }\n\n    export { asyncHandler }\n   ```\n\n2. **`custom-api-error`**:\n   Standardizes error responses for your API.\n\n   **Code Snippet**:\n   ```js\n   class ApiError extends Error{\n        constructor(\n            statusCode,\n            message= \"Something went wrong\",\n            errors=[],\n            stack=\"\"\n        ){\n            super(message);\n            this.statusCode = statusCode;\n            this.message = message;\n            this.data = null;\n            this.errors = errors;\n            \n            if(stack){\n                this.stack = stack;\n            }else{\n                Error.captureStackTrace(this, this.constructor);\n            }\n        }\n    }\n\n    export { ApiError }\n   ```\n\n3. **`custom-api-response`**:\n   Standardizes successful API responses.\n\n   **Code Snippet**:\n   ```js\n    class ApiResponse{\n        constructor(statusCode, message=\"success\", data){\n            this.statusCode = statusCode;\n            this.message = message;\n            this.data = data;\n            this.success = statusCode \u003c 400;\n        }\n    }\n\n    export {ApiResponse}\n   ```\n\n4. **`multer-file-upload`**:\n   Sets up a file upload service using `multer`.\n\n   **Code Snippet**:\n   ```js\n   import multer from \"multer\";\n\n    const storage = multer.diskStorage({\n    destination: function(req, file, cb){\n        cb(null, './public/temp');\n    },\n    filename: function(req, file, cb){\n        cb(null, file.originalname);\n    }\n    });\n\n    export const upload = multer({ storage });\n\n   ```\n\n### 3. `run generate-ai-snippet \u003csnippetName\u003e`\nWith the new AI-powered code generation feature, you can generate customized code snippets. For instance, to generate a code snippet for a specific backend functionality, you can run:\n\n```bash\nrun generate-ai-snippet \u003csnippetName\u003e\n```\n\nExample:\n\n```bash\nrun generate-ai-snippet login-controller\n```\n\nThis will generate a code snippet for login-controller using AI that looks like :\n```bash\nGenerated Code Snippet for login-controller:\n\nconst User = require('../models/User');\nconst bcrypt = require('bcrypt');\nconst jwt = require('jsonwebtoken');\n\nmodule.exports.login = async (req, res) =\u003e {\n  try {\n    const { email, password } = req.body;\n\n    const user = await User.findOne({ email });\n    if (!user) {\n      return res.status(401).json({ message: 'Invalid credentials' });\n    }\n\n    const isMatch = await bcrypt.compare(password, user.password);\n    if (!isMatch) {\n      return res.status(401).json({ message: 'Invalid credentials' });\n    }\n\n    const token = jwt.sign({ userId: user._id }, process.env.JWT_SECRET, { expiresIn: '1h' });\n    res.json({ token, user: { _id: user._id, name: user.name, email: user.email } });\n  } catch (err) {\n    console.error(err);\n    res.status(500).json({ message: 'Server error' });        \n  }\n};\n\nThe code snippet is generated successfuly and may require some modifications to fit your use case.\n```\n\n## Full User Journey Example\n\nHere’s a complete example of a user journey, from project setup to injecting code snippets into the project.\n\n### Step 1: Install the CLI Globally\n\nFirst, install the tool using npm:\n\n```bash\nnpm install -g backend-generator-cli\n```\n\n### Step 2: Create a New Backend Project\n\nNavigate to your desired directory and run the following command to generate the project structure:\n\n```bash\nrun create-project\n```\n\nThis will create a new backend project with the following structure:\n\n```\n.\n├── src/\n│   ├── controllers/\n│   ├── db/\n│   ├── middlewares/\n│   ├── models/\n│   ├── routes/\n│   ├── utils/\n│   ├── app.js\n│   ├── constants.js\n│   └── index.js\n├── .env.sample\n├── .gitignore\n├── .prettierignore\n├── .prettierrc\n├── package.json\n└── README.md\n```\n\n### Step 3: Move to the `src/utils` Directory\n\nChange your working directory to the `src/utils` folder:\n\n```bash\ncd src\ncd utils\n```\n\nYou are now inside the `utils` folder where you will generate the file upload handler snippet.\n\n### Step 4: Add a Snippet to Handle File Uploads\n\nNext, add a `multer` file upload handler by running the following command:\n\n```bash\nrun generate-snippet multer-file-upload\n```\n\nThis command will create a new file called `multer-file-upload.js` in the `src/utils` directory, which is now your current working directory. The content of this file will look like this:\n\n```js\nimport multer from 'multer';\n\nconst storage = multer.diskStorage({\n  destination: function (req, file, cb) {\n    cb(null, './public/temp');\n  },\n  filename: function (req, file, cb) {\n    cb(null, file.originalname);\n  }\n});\n\nexport const upload = multer({ storage });\n```\n\n### Step 5: Use the Snippet in Your Project\n\nNow that the file upload handler has been generated in the `utils` folder, you can import and use it in your application. For instance, in `src/routes/uploadRoute.js`:\n\n```js\nimport express from 'express';\nimport { upload } from '../utils/multer-file-upload';\n\nconst router = express.Router();\n\nrouter.post('/upload', upload.single('file'), (req, res) =\u003e {\n  res.send('File uploaded successfully');\n});\n\nexport default router;\n```\n\nMake sure that your main `app.js` or `index.js` includes this route:\n\n```js\nimport express from 'express';\nimport uploadRoute from './routes/uploadRoute';\n\nconst app = express();\n\napp.use('/api', uploadRoute);\n\napp.listen(3000, () =\u003e {\n  console.log('Server is running on port 3000');\n});\n```\n\n### Step 6: Continue Building\n\nContinue building your application by adding your business logic, routes, controllers, and any other necessary components. Feel free to generate additional snippets like `custom-api-error` and `async-ops-handler` as needed.\n\nThis flow demonstrates how you can set up your backend project structure and utilize the code snippets generated by `backend-generator-cli` to accelerate your development.\n\n\n## Future Enhancements\n\n- Add more predefined snippets for common backend use cases.\n- Add a controller to get the most in-demand snippets.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n---\n\u003cbr\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cp\u003eMade with ❤️ by Pranav Barthwal\u003c/p\u003e\n  \u003cimg src=\"https://avatars.githubusercontent.com/u/110532770?v=4\" width=\"150\" style=\"border-radius: 50%;\" alt=\"Pranav Barthwal\" /\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://github.com/PranavBarthwal\" target=\"_blank\"\u003eFollow me on GitHub\u003c/a\u003e |\n    \u003ca href=\"https://twitter.com/pranavbarthwal_\" target=\"_blank\"\u003eFollow me on X\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpranavbarthwal%2Fbackend-generator-cli-web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpranavbarthwal%2Fbackend-generator-cli-web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpranavbarthwal%2Fbackend-generator-cli-web/lists"}