{"id":13526932,"url":"https://github.com/blacksmithstudio/blockbase","last_synced_at":"2025-04-01T08:30:38.657Z","repository":{"id":48033170,"uuid":"134829262","full_name":"blacksmithstudio/blockbase","owner":"blacksmithstudio","description":"Lightweight MVC Framework for Node.js","archived":false,"fork":false,"pushed_at":"2023-01-11T01:47:08.000Z","size":211,"stargazers_count":31,"open_issues_count":10,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-14T15:44:11.059Z","etag":null,"topics":["blockbase","es6","framework","javascript","mvc","mvc-framework","node","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blacksmithstudio.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}},"created_at":"2018-05-25T08:43:07.000Z","updated_at":"2024-12-03T20:28:09.000Z","dependencies_parsed_at":"2023-02-08T21:45:35.759Z","dependency_job_id":null,"html_url":"https://github.com/blacksmithstudio/blockbase","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacksmithstudio%2Fblockbase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacksmithstudio%2Fblockbase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacksmithstudio%2Fblockbase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacksmithstudio%2Fblockbase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blacksmithstudio","download_url":"https://codeload.github.com/blacksmithstudio/blockbase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246607097,"owners_count":20804515,"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":["blockbase","es6","framework","javascript","mvc","mvc-framework","node","nodejs"],"created_at":"2024-08-01T06:01:37.886Z","updated_at":"2025-04-01T08:30:38.208Z","avatar_url":"https://github.com/blacksmithstudio.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\n![Blockbase](https://s3-eu-west-1.amazonaws.com/blockbase/assets/blockbase-logo.svg)\n# Blockbase\nLightweight MVC Framework for Node.\n\n[![Travis Blockbase](https://travis-ci.org/blacksmithstudio/blockbase.svg?branch=master)](https://travis-ci.org/blacksmithstudio/blockbase)\n[![NPM Version](https://img.shields.io/npm/v/blockbase.svg)](https://www.npmjs.com/package/blockbase)\n![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)\n\n### Version\nv1.0.20\n\n### Summary\n- [Install](#install)\n- [Namespace Architecture](#namespace)\n- [Drivers](#drivers)\n- [Controllers](#controllers)\n- [Models](#models)\n- [Sample App](https://github.com/blacksmithstudio/blockbase-sample)\n\n### Install\nYou need first to have Node.JS on your machine. If not [please folllow the install instructions here](https://nodejs.org)\n\nThen let's move on :\n\n1. Install Blockbase\n``` shell\n$ npm install -g blockbase\n```\n\n2. Create a project using the CLI \n``` shell\n$ blockbase create MySuperProject\n```\n\n3. Discover the architecture \n\nBlockbase is based on an hybrid MVC+Drivers architecture to build complete projects and scalable architectures.\n```\n/config (required, where you'll push your configuration)\n/drivers\n/controllers\n/models\napp.js\n```\n\n4. Edit your `app.js`\nBlockbase is using a simple instance method : `blockbase(options, callback)`\nIn options, the only mandatory property is `root` handling the path of the current project (see example below).\n``` js\nconst blockbase = require('blockbase')\n\nblockbase({ root : __dirname }, async (app) =\u003e {\n    app.drivers.logger.success('App', `${app.config.name} is alive !`)\n    // let's code !\n})\n```\n\n#### Namespace\nIf you log the `app` variable from the callback, you'll get the following architecture :\n* `app.config`: contains the config JSON from /config/{env}.yml (see [config](https://www.npmjs.com/package/config) package)\n* `app.root`: path where the app is launched\n* `app.drivers`: drivers namespace, by default is containing only `app.drivers.logger` handling the console logs. You can install more drivers (see more [Drivers Install](#drivers))\n* `app.controllers`: will be automatically populated by the files from /controllers/* (see more [Managing Controllers](#controllers))\n* `app.models`: will be automatically populated by the files from /models/* (see more [Managing Models](#models))\n\n#### Drivers\n\nBlockbase is build with a driver linked logic to build connectors to other tools or customer traversal methods across your app. \nWe offer a list of [official drivers here](https://github.com/blacksmithstudio/blockbase/blob/master/docs/DRIVERS.md) to install connectors such as [MySQL](https://github.com/blacksmithstudio/blockbase-mysql), [PostgreSQL](https://github.com/blacksmithstudio/blockbase-postgresql), ... \n\n##### Automatic install for official drivers.\nYou can easily install [official drivers](https://github.com/blacksmithstudio/blockbase/blob/master/docs/DRIVERS.md) by using `npm i` in your project. This will automatically add the driver to the blockbase namespace `app.drivers.*`\n``` shell\n$ npm i --save blockbase-express\n```\nIn the example above, the driver will be install under the `app.drivers.express` namespace\n\n##### Manual Install for your custom drivers.\nYou can create your own drivers by adding them to the /drivers/ folder using the CLI.\n```\n$ blockbase add driver custom\n```\n\nBlockbase structure allows you to pass the entire `app.*` namespace to your drivers, controllers, etc...\nHere is an example of a custom driver :\n\nexample below : /drivers/custom.js\n```js\nconst something = require('something')\n\nmodule.exports = (app) =\u003e {\n    // setup of your driver\n    return {\n        foo(arg1, arg2) {\n            // do something\n        },\n\n        bar() {\n            // do something\n        }\n    }\n}\n```\n\nFollowing that you'll be able to use anywere the driver by calling `app.drivers.custom.foo(arg1, arg2)` for example.\n!!! Please don't call any controller or model in the driver above the `return` statement as it is instanciated at the application initialization.\n\n#### Controllers\nControllers will follow the same rules, you want to create a controller ? Just add it under /controllers, but there are some differences.\n- Controllers could have an optional `init` method, triggered on the creation of the app.\n- Controllers can have sub namespaces (2 dimensions max) like `app.controllers.sub.foo.bar`\n\nExample of Architecture :\n```\n/config\n/drivers\n/controllers\n---/custom.js\n---/foo/bar.js\n/models\napp.js\n```\nFollowing the construction above, Blockbase will render `app.controllers.custom.*` and `app.controllers.foo.bar.*`\n\nTo create a controller\n```\n$ blockbase add controller foo\n```\nTo create a sub.controller\n```\n$ blockbase add controller foo.bar\n```\n\n#### Models\n\nModels follow a slight different approach, using `class` and `extends` properties of ES6.\n\n##### Building a custom model from scratch\n\nYou can build a custom model with no inherited properties and submethods.\nAdding it directly to /models/ will add it to the `app.models.*` namespace\n\nTo create a model with the CLI\n```\n$ blockbase add model user\n```\n\nExample : /models/user.js\n\n```js\nmodule.exports = (app) =\u003e {\n    return class User {\n        constructor(data){\n            // init my model\n        }\n\n        example(){\n            // model sub method\n        }\n    }\n}\n```\nHowever this model is limited, having only its declared subproperties.\nBlockbase has by default a serie of classic methods powered in the models (create, read, update, delete, etc.) useful in your API build-up. To activate these methods, use the inheritance below :\n\n##### Building a custom model with Blockbase inheritance\n\nExample : /models/user.js\n\n```js\nmodule.exports = (app) =\u003e {\n    // we call the \"super model\" from the namespace\n    const Model = app.models._model\n    \n    // we extend the super model in our user model so it will receive all the default methods.\n    return class User extends Model {\n        constructor(data){\n            super({ type : 'awesome', authenticated : false })\n\n            if(data)\n                this.data = data\n        }\n\n        example(){\n            // example of an additional method\n        }\n    }\n}\n```\n\nThe main change is on the `Model` inheritance.\n\n```js\n    const Model = app.models._model\n    [...]\n    return class Awesome extends Model {\n```\nThanks to this extend, you'll get access to a lot of default methods in the model.\n```js\n   const User = app.models.user\n   let user = new User({ firstname : 'John', lastname : 'Doe' })\n   \n   console.log(user.body()) // will show you the data \n   console.log(user.clean()) // will remove null/empty data from the object\n   etc...\n```\n\n###### Default methods in the model\n- `{model}.body()` allowing you to access the data (if your model has a`.data`object)\n- `{model}.clean()` remove all the null and empty values from your data\n- `{model}.validate()` returns the Joi validation of your model\n- `{model}.valid()` returns a boolean if your object data is Joi validated or not\n\n###### Default methods in the model (be careful : a DBMS driver is required, for example blockbase-postgresql)\n- `await {model}.create()` returns a new saved object in your database\n- `await {model}.read()` returns an object from your database (search by id)\n- `await {model}.update()` returns an updated object from your database\n- `await {model}.delete()` returns a boolean on deletion of your object (by id)\n\n#### Run tests\nBlockbase has some unit tests (with [Mocha](https://mochajs.org)) written run them often !\n\n```sh\n$ npm test\n```\n\nLicense\n----\n(Licence [MIT](https://github.com/blacksmithstudio/blockbase/blob/master/LICENCE))\nCoded by [Blacksmith](https://www.blacksmith.studio)\n\n**Free Software, Hell Yeah!**\n\n[Node.js]:https://nodejs.org/en\n[NPM]:https://www.npmjs.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacksmithstudio%2Fblockbase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblacksmithstudio%2Fblockbase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacksmithstudio%2Fblockbase/lists"}