{"id":18152267,"url":"https://github.com/bsdelf/barebone-js","last_synced_at":"2025-04-06T23:45:57.842Z","repository":{"id":141768586,"uuid":"255489433","full_name":"bsdelf/barebone-js","owner":"bsdelf","description":"Backend boilerplate for Node.js \u0026 TypeScript","archived":false,"fork":false,"pushed_at":"2023-02-09T08:26:53.000Z","size":188,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-13T05:44:54.686Z","etag":null,"topics":["backend","boilerplate","frameworkless","javascript","microservice","nodejs","skeleton","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/bsdelf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-04-14T02:21:07.000Z","updated_at":"2023-08-24T09:35:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"cf48f5a7-6e70-4cad-bad7-85bc6df39662","html_url":"https://github.com/bsdelf/barebone-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdelf%2Fbarebone-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdelf%2Fbarebone-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdelf%2Fbarebone-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdelf%2Fbarebone-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsdelf","download_url":"https://codeload.github.com/bsdelf/barebone-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247569130,"owners_count":20959758,"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","boilerplate","frameworkless","javascript","microservice","nodejs","skeleton","typescript"],"created_at":"2024-11-02T02:06:13.001Z","updated_at":"2025-04-06T23:45:57.823Z","avatar_url":"https://github.com/bsdelf.png","language":"TypeScript","readme":"# barebone-js\n\nbarebone-js is a backend boilerplate for Node.js and TypeScript. It's not a framework, but is a way of thinking, which leads to maintainability and scalability. Regardless the runtime, the basic idea behind this project could be applied to backend projects in other programming languages.\n\n## Features\n\n- TypeScript\n- Graceful kill\n- Stacked configurations\n- Extensible application context\n- Well-organized project structure\n- Almost zero learning curve\n\n## Project Structure\n\n### /config\n\nConfig files. When application start, a portion of config files under this folder will be read, stacked, and merged into a single config object based on `NODE_ENV`.\n\nFor development, staging, and production environment, the config stack is:\n\n1. config.default.yaml\n2. config.\\\u003c_environment_\\\u003e.yaml (optional)\n3. config.local.yaml (optional, highest priority)\n\nFor unit test, the configs stack is:\n\n1. config.default.yaml\n2. config.test.yaml (optional)\n3. config.local.test.yaml (optional, highest priority)\n\nTo inspect the merged config object:\n\n```\nnpm run cli:dev config:dump\n```\n\nIn practice, the default and environmental configs are supposed to store generic insensitive settings like URL and port. While the local config is supposed to store variable and sensitive settings like tokens and passwords. Local config should never be committed into repository or built into image. For kubernetes deployments, we suggest use [volumes](https://kubernetes.io/docs/concepts/storage/volumes/) to mount local config into container.\n\n### /src/applications\n\nMain applications for your project. For example:\n\n- REST server: RESTful API server\n- RPC server: HTTP or websocket server\n- Cron: time-based job scheduler\n- Worker: message queue consumer\n- CLI: command line tools for operation or debug\n\nSource code under this folder should keep short and concise.\n\nThey just like Go's [cmd](https://github.com/golang-standards/project-layout/tree/master/cmd).\n\n### /src/core\n\nCore facilities for application lifecycle.\n\n#### 1. Application\n\n`Application` class provides lifecycle hooks.\n\n#### 2. Bootstrap\n\n`bootstrap` function is responsible for context initialization and application startup.\n\n#### 3. Context\n\n`Context` is composed by various long lived objects like:\n\n- Config\n- Logger\n- HTTP Client\n- MySQL Client\n- Redis Client\n\nEach object has a corresponding [provider](#srcproviders), which is responsible for object construction and destruction.\n\n### /src/providers\n\nContext object providers. They follow factory pattern. Each provider has following elements:\n\n- Dependencies: providers required by object constructor.\n- Constructor: construct a new object with given dependencies.\n- Destructor: destroy a given object.\n\nWith above information and methods, a topological sorting ([dag-maker](https://www.npmjs.com/package/dag-maker)) will be applied for context object construction and destruction.\n\n### /src/commands\n\nCommands for specific tasks. They are expected to be invoked by applications like Cron，CLI，Worker.\n\nBusiness logic can be implemented completely in commands. However, let commands be access layer and put actual business logic in [controllers](#srccontrollers) could make your code reusable.\n\n### /src/routes\n\nRoutes for HTTP server.\n\nRoutes are responsible for I/O:\n\n- authenticate\n- validate inputs\n- invoke related components with inputs to serve the request\n- build and validate outputs, rule out sensitive data\n\n### /src/procedures\n\nProcedures for RPC server.\n\nProcedures are quite similar to routes, they handle I/O stuffs.\n\n### /src/controllers\n\nControllers, to be reused by other components. For example:\n\n- Routes\n- Procedures\n- Commands\n\nThis is the place where most of your business logic should be implemented in.\n\nNote, instances of controllers are short lived objects. Long lived objects should be kept in [context](#srccontext).\n\n### /src/models\n\nModels are primitive data abstractions. Controllers and other high level components rely on models to store data.\n\n### /src/migrations\n\nSequelize migrations.\n\nInitialize migration for the first time:\n\n```\nnpm run cli:dev migration:init\n```\n\nCreate a new migration:\n\n```\nnpm run cli:dev migration:create -- --name create-my-table\n```\n\nApply all pending migrations:\n\n```\nnpm run cli:dev migration:up\n```\n\nUndo the most recent migration:\n\n```\nnpm run cli:dev migration:down\n```\n\n### /src/libraries\n\nPortable utility functions and classes, expected to be context irrelevant. Code under this folder can be easliy reused by other projects or published to NPM for sharing.\n\n## Architecture\n\n![architecture](docs/ideal.svg)\n\nThe entire software has roughly four layers, from outer to inner:\n\n- Applications: entrances.\n- Access Layer: I/O, authenticate, request dispatch.\n- Controllers: request processing.\n- Models: primitive data abstractions.\n\nAlso, there are a couple of long lived \"system services\" mananged by context which are global available to above components.\n\nWith this architecture, project can easily achieve horizontal scale and functional scale. See [the scale cube](https://microservices.io/articles/scalecube.html) of microservices.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsdelf%2Fbarebone-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsdelf%2Fbarebone-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsdelf%2Fbarebone-js/lists"}