The blueprint kysely nodejs is a boilerplate for creating backend projects with consistent tooling, code style, and structure. It includes npm scripts, GitHub workflows, Jest for testing, and Google's Typescript Style guide (gts). To use this project, follow the getting started section, which include creating a dev branch on GitHub and setting up branch rules to ensure code quality. This project also includes rules for writing unit and e2e tests, as well as creating a clear readme for users.
On top of that it sets up a basic structure for a database based project, complete with migrations and associated commands for running and creating migrations. It also configures jest in a way, that tests are run in sqlite in an in-memory database, so that you can test mutating database operations.
- You have less work setting up all the boilerplate code for a database based project
- All the fundamentals in place: migrations, seeder, CI, testing, linting, code style, etc.
- Consistent tooling, code style and structure among all backend projects
- Test seeder with a deep database structure with which you can test almost anything database related
- Enforced pull request and code review workflow
- Enforced code quality with automated tests
- Configure Github branch rules
- Create a new repo using this repo as a template
- Checkout your repo, create a
devbranch and push it to github. This is important before the next step as the next step requires that thetests.ymlgithub action has run at least once. - Protect your
mainbranch.- Go to Settings -> Branches -> Add rule -> Branch name pattern:
main-> tick - Require branches to be up to date before merging
- Require status checks to pass before merging
- Select
testsaction - Do not allow bypassing the above settings
- Click save
- Go to Settings -> Branches -> Add rule -> Branch name pattern:
- Remove db engines you don't need from
./kyselyandpackage.json- The package
pgandpg-cursorare required for thepostgresengine - The package
mysql2is required for themysqlengine - The package
better-sqlite3is required for thesqliteengine
- The package
- run
yarnto install all dependencies - run
yarn run migration:runto run all migrations - Copy the
.env.sampleto.env
- General scripts
yarn run start- starts thesample/index.tsin watch mode with nodemon, restarts it if the code changesyarn run test- runs tests including code coverage requirementsyarn run test:watch- runs tests in watch mode re-running related tests when code changesyarn run compile- compiles the code to the build folder, runs automatically on releaseyarn run fix- runs gts fix to normalize code style, runs automatically on pushyarn doc:generate- generates markdown documentation into the./docfolder, runs automatically on push
- Database scripts
yarn migration:run- runs all migrations in thedb/migrationsfolderyarn migration:make- creates a new migration file in thedb/migrationsfolderyarn seed:test- runs the test seeder, which seeds the database with a booking system database
- Github workflows
format.yml- runs gts fix on push to normalize code stylerelease.yml- to publish to our private registry if you create a release in Githubtests.yml- runs tests if you push or pull
- Kysely
kysely/index.ts- exports a kysqly instance as per the defined engine in.envyou can import this withimport { kysely } from './kysely'and use it to query the databasekysely/samplescontains lots of samples for how to use kysely to query the database
- Booking system database
- Migrations in
db/migrationsfolder - Test seeder in
db/seedersfolder
- Migrations in
- gts (Google Typescript Style)
- Typescript code style including prettier, eslint, tsconfig etc according to what google thinks makes sense.
getConfigfunction insrc/getConfig.tsto get a normalized config from environment variables
- Uses jest for testing
- Runs tests in the
__tests__folder or with the.spec.tsextension - 80 % coverage requirement
- Before tests are run, the database is migrated to the latest version. Migrations are persisted in the test database is by default located at
storage/kysely.spec.sqlite3, as configured in.env.test - Tests are run in an in-memory sqlite database, so that you can test mutating database operations
- Please note that the db is not reset in between tests so if you mutate data in test A, this data is present in test B
- Write unit tests directly in your code and not in a separate directory. Postfix them with
NAME_OF_YOUR_FILE.spec.ts. - Write e2e tests in the
__tests__directory. - Create a
readme.mdfor your project which includes a "getting started" section with instructions on how to install and use this project. Make sure that getting started is easy. - If you did not follow this rules, your epics are not considered to be done.
- Jest and github actions by Pedro Fonseca
- Jest and github actions by Joel Hooks
- Auto formatting code using prettier and github actions by Mike Skelton
- Github checks documentation
- Google Typescript Style
- Add debug tutorial for vscode & intelij
- Add CI&CD
