{"id":17051626,"url":"https://github.com/mangesh-balkawade/express-sequelize-kit-mb","last_synced_at":"2026-01-08T09:03:31.433Z","repository":{"id":257803546,"uuid":"863111343","full_name":"mangesh-balkawade/express-sequelize-kit-mb","owner":"mangesh-balkawade","description":"A reusable package for backend development using Node.js, Express, and Sequelize, featuring customizable CRUD operations and commonly used API and repository functions. It promotes clean code, encapsulation, and DRY principles for easy integration into various projects.","archived":false,"fork":false,"pushed_at":"2024-09-28T17:07:58.000Z","size":4078,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-18T23:15:57.349Z","etag":null,"topics":["backend","crud","express","mvc","mysql","nodejs","orm","repository-pattern","rest-api","sequelize"],"latest_commit_sha":null,"homepage":"","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/mangesh-balkawade.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-25T18:23:19.000Z","updated_at":"2025-05-08T14:05:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"bd421fed-db5f-4641-b3a7-42b4c4c29a3f","html_url":"https://github.com/mangesh-balkawade/express-sequelize-kit-mb","commit_stats":null,"previous_names":["mangesh-balkawade/express-sequelize-kit-mb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mangesh-balkawade/express-sequelize-kit-mb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mangesh-balkawade%2Fexpress-sequelize-kit-mb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mangesh-balkawade%2Fexpress-sequelize-kit-mb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mangesh-balkawade%2Fexpress-sequelize-kit-mb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mangesh-balkawade%2Fexpress-sequelize-kit-mb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mangesh-balkawade","download_url":"https://codeload.github.com/mangesh-balkawade/express-sequelize-kit-mb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mangesh-balkawade%2Fexpress-sequelize-kit-mb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266135316,"owners_count":23881796,"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","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","crud","express","mvc","mysql","nodejs","orm","repository-pattern","rest-api","sequelize"],"created_at":"2024-10-14T10:06:41.187Z","updated_at":"2026-01-08T09:03:26.395Z","avatar_url":"https://github.com/mangesh-balkawade.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n---\n\n# express-sequelize-kit-mb\n\n**express-sequelize-kit-mb** is a reusable package for backend development using **Node.js**, **Express**, and **Sequelize**, featuring customizable CRUD operations and commonly used API and repository functions. It promotes clean code, encapsulation, and **DRY** (Don't Repeat Yourself) principles for easy integration into various projects.\n\n## Features\n\n- **CRUD operations**: Easily implement Create, Read, Update, and Delete operations.\n- **Repository pattern**: Simplifies database interactions using Sequelize models.\n- **API utilities**: Includes commonly used functionalities such as pagination and filtering.\n- **Encapsulation**: Keeps the logic modular and maintainable.\n\n## Installation\n\n```bash\nnpm install express-sequelize-kit-mb\n```\n\nAlso, install dependencies:\n\n```bash\nnpm install express sequelize mysql2 dotenv cors\n```\n\n## Getting Started\n\n### Example Project Structure\n\n```bash\n├── config\n│   └── dbConfig.js\n├── controllers\n│   └── UserController.js\n├── models\n│   └── userModel.js\n├── repository\n│   └── userRepository.js\n├── services\n│   └── userService.js\n├── routes\n│   └── userRoutes.js\n├── index.js\n```\n\n### 1. Database Configuration (`dbConfig.js`)\n\nConfigure your database connection using Sequelize:\n\n```javascript\nconst { Sequelize } = require(\"sequelize\");\nrequire(\"dotenv\").config();\n\nconst sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {\n  host: process.env.DB_HOST,\n  dialect: \"mysql\"\n});\n\nsequelize\n  .authenticate()\n  .then(() =\u003e {\n    console.log(\"Connection has been established successfully.\");\n  })\n  .catch((err) =\u003e {\n    console.error(\"Unable to connect to the database:\", err);\n  });\n\nmodule.exports = sequelize;\n```\n\n### 2. Define a Model (`userModel.js`)\n\nCreate a Sequelize model for `User`:\n\n```javascript\nconst { DataTypes } = require(\"sequelize\");\nconst sequelize = require(\"../config/dbConfig\");\n\nconst UserModel = sequelize.define(\"User\", {\n  userId: {\n    type: DataTypes.INTEGER,\n    autoIncrement: true,\n    primaryKey: true\n  },\n  name: {\n    type: DataTypes.STRING(100),\n    allowNull: false\n  },\n  age: {\n    type: DataTypes.INTEGER\n  },\n  deleteFlag: {\n    type: DataTypes.TINYINT,\n    defaultValue: 0\n  }\n}, {\n  timestamps: true\n});\n\nmodule.exports = UserModel;\n```\n\n### 3. Create Repository (`userRepository.js`)\n\n```javascript\n// Import the User model\nconst UserModel = require(\"../models/userModel\");\n\n// Import the Repository class from express-sequelize-kit-mb package\nconst { Repository } = require(\"express-sequelize-kit-mb\");\n\n// Define the UserRepository class extending the generic Repository\nclass UserRepository extends Repository {\n    constructor() {\n        // Call the parent Repository constructor and pass necessary parameters:\n        // 1. UserModel: The Sequelize model for the User table\n        // 2. Soft delete field: Leave as an empty string if not using soft delete\n        // 3. Soft delete option: Set to false to disable soft deletion\n\n        // If soft delete is required, set the field name (e.g., \"deleteFlag\") and true as the second and third arguments.\n        super(UserModel, \"deleteFlag\", true);\n    }\n}\n\n// Create an instance of the UserRepository\nconst userRepository = new UserRepository();\n\n// Export the userRepository instance to be used in the service layer\nmodule.exports = { userRepository };\n\n```\n\n### 4. Create Service (`userService.js`)\n\n```javascript\n// Import the userRepository instance from the userRepository file\nconst { userRepository } = require(\"../repository/userRepository\");\n\n// Import the generic Service class from the express-sequelize-kit-mb package\nconst { Service } = require(\"express-sequelize-kit-mb\");\n\n// Define the UserService class extending the generic Service\nclass UserService extends Service {\n    constructor() {\n        // Call the parent Service constructor and pass the userRepository instance\n        // This allows the service layer to utilize the repository's methods\n        super(userRepository);\n    }\n}\n\n// Create an instance of the UserService\nlet userService = new UserService();\n\n// Export the userService instance to be used in the controller layer\nmodule.exports = { userService };\n\n```\n\n### 5. Create Controller (`UserController.js`)\n\nHandle incoming requests in the controller:\n\n```javascript\n// Import the generic Controller class from the express-sequelize-kit-mb package\nconst { Controller } = require(\"express-sequelize-kit-mb\");\n\n// Import the userService instance from the userService file\nconst { userService } = require(\"../service/userService\");\n\n\n// Define the UserController class extending the generic Controller\nclass UserController extends Controller {\n  constructor() {\n    // Call the parent Controller constructor and pass the following:\n    // 1. userService: The service layer object to handle business logic and repository interaction\n    // 2. Enable logs: Set to true if you want to enable logging for actions within the controller\n    super(userService, true);\n  }\n}\n\n// Create an instance of the UserController\nlet userController = new UserController();\n\n// Export the userController instance to be used in the route layer\nmodule.exports = { userController };\n\n\n```\n\n### 6. Define Routes (`userRoutes.js`)\n\nRoute API requests to the correct controller methods:\n\n```javascript\n// Import Express framework\nconst express = require(\"express\");\n\n// Create a new router instance\nconst route = express.Router();\n\n// Import the userController instance from the UserController file\nconst { userController } = require(\"../controllers/UserController\");\n\n// Import middlewares for validation and assigning organization data\nconst { validateFields } = require(\"../middlewares/validationMiddleware\");\nconst { assignOrgInfo } = require(\"../middlewares/routeMiddlewares\");\n\n// Define routes for user-related operations\n\n// POST route to save user data\n// Uses the validateFields middleware to ensure 'name' and 'age' are provided\n// The assignOrgInfo middleware can be used to assign user-related data such as organizationId from the JWT token\n// If you want to modify or assign additional data (like roles, user permissions), you can use middlewares to do so before passing the data to the controller same like given below\nroute.post(\"/User-Save\", validateFields(\"name\", \"age\"), assignOrgInfo, userController.saveData);\n\n// PATCH route to update user data by ID\n// You can add middlewares here if you need to modify the request data before updating the user record\nroute.patch(\"/User-Update/:id\", userController.updateData);\n\n// DELETE route to delete user data by ID\n// Middlewares can be used here to apply additional checks before deletion (e.g., role-based access control)\nroute.delete(\"/User-Delete/:id\", userController.deleteData);\n\n// GET route to fetch user data by ID\n// If you need to filter or modify the response, use a middleware before calling the controller method\nroute.get(\"/User-Get-Data-By-Id/:id\", userController.getDataById);\n\n// GET route to fetch all users\n// Middlewares can be added to modify or limit the data being fetched (e.g., based on user roles, organizations, etc.)\nroute.get(\"/User-Get-All-Data\", userController.getAllData);\n\n// GET route to fetch all users with pagination\n// If you want to customize pagination or filtering criteria dynamically, middlewares can handle those assignments before the controller processes the request\nroute.get(\"/User-Get-All-Data-By-Pagination\", userController.getAllDataWithPagination);\n\n// Export the route to be used in other parts of the application\nmodule.exports = route;\n\n\n```\n\n### 7. Main Application (`index.js`)\n\nIntegrate everything into the main app:\n\n```javascript\n// Load environment variables from .env file\nrequire(\"dotenv\").config();\n\n// Import Express and CORS modules\nconst express = require(\"express\");\nconst cors = require(\"cors\");\n\n// Initialize Express app\nconst app = express();\n\n// Middleware to parse JSON requests\napp.use(express.json());\n\n// Enable CORS (Cross-Origin Resource Sharing) for all origins\napp.use(cors({ origin: \"*\" }));\n\n// Import and configure the database connection\nrequire(\"./config/dbConfig\");\n\n// Import User routes\nconst UserRoutes = require(\"./routes/userRoutes\");\n\n// Use the imported User routes for all requests to /User endpoint\napp.use(\"/User\", UserRoutes);\n\n// Load relationships between models (associations)\nrequire(\"./models/relationships\");\n\n// Start the Express server on port 3000\napp.listen(3000, () =\u003e {\n  console.log(\"Server is started on port 3000\");\n});\n\n\n```\n\n### 8. **Running the App**:\n   Start the server by running:\n   ```bash\n   npm start\n   ```\n\n   Your API will be available at `http://localhost:3000/`.\n   \n## Demo\n\nFor a complete demo, check out the [demo repository](https://github.com/mangesh-balkawade/express-sequelize-kit-mb-package-usage-demo).\n\n## API Documentation\n\nYou can explore and test the API using Postman. Click the link below to view the Postman collection:\n\n[Postman Collection for express-sequelize-kit-mb](https://www.postman.com/restless-rocket-723917/express-sequelize-kit-mb/collection/ddqu6wt/express-sequelize-kit-mb-api)\n\n## Author\n\n**Mangesh Balkawade**  \n[GitHub](https://github.com/mangesh-balkawade)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmangesh-balkawade%2Fexpress-sequelize-kit-mb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmangesh-balkawade%2Fexpress-sequelize-kit-mb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmangesh-balkawade%2Fexpress-sequelize-kit-mb/lists"}