IT4C Backend Boilerplate Documentation
  • boilerplate-backend

boilerplate-backend

nodejsnpmdockerapollo-servergraphqltype-graphqlprismaeslintremark-clijestvuepress

The IT4C Boilerplate for an apollo express backends.

Requirements & Technology

To be able to build this project you need nodejs, npm and optional docker.

The project sets up an apollo server. It uses type-graphql.

Commands

The following commands are available:

CommandDescription
npm installProject setup
npm run buildCompiles and minifies for production
npm run startRuns productions server
Develop
npm run devCompiles and hot-reloads for development
Database
npm run db:migrateCreates and executes migrations needed
npm run db:resetDrops Schema, run all migrations and seeds
npm run db:seedRun the seeds
Test
npm run test:lintRun all linters
npm run test:lint:eslintRun linter eslint
npm run test:lint:remarkRun linter remark
npm run test:unitRun all unit tests and generate coverage report
npm testRun all tests & linters
Documentation
npm run docs:devRun Documentation in development mode
npm run docs:buildBuild static documentation
Maintenance
npm run updateCheck for updates

Docker

Docker can be run in development mode utilizing docker-compose.overwrite.yml:

docker compose up

Docker can be run in production mode:

docker compose -f docker-compose.yml up

Update

You can get a list of packes to update by running npm run update.

Appending -u will also update the packages in the package.json. You have to run npm install again after.

npm run update -- -u
npm install

Endpoints

The following endpoints are provided given the right command is executed or all three if docker compose is used:

EndpointDescription
http://localhost:4000/graphqlGraphQL API
http://localhost:4000/playgroundGraphQL Playground

How to use as part of a project

If you want to use this as part of a larger project, e.g. in conjunction with a frontend also utilizing a boilerplate you cannot use the template mechanic provided by github for this repository.

You can use the following commands to include the whole git history of the boilerplate and be able to update according to changes to this repo using another remote.

git remote add xxx_boilerplate_backend git@github.com:IT4Change/boilerplate-backend.git
git fetch xxx_boilerplate_backend
git merge -s ours --no-commit --allow-unrelated-histories xxx_boilerplate_backend/master
git read-tree --prefix=xxx/ -u xxx_boilerplate_backend/master
git commit -m "Imported boilerplate_backend as a subtree under xxx/."

To update the subtree you can use

git subtree pull -P xxx/ xxx_boilerplate_backend master
git commit -m "Updated boilerplate_backend in subtree under xxx/."

Where xxx refers to the folder and product part you want to use the boilerplate in. This assumes that you might need several copies of the frontend boilerplate for you product.

This mechanic was taken from this source

Database setup

The project is set up for a sqlite database. In order to run the project against a mysql database adjust prisma/schema.prisma, copy the .env.dist file to .env and configure the database connection appropriately. Then run npm run db:migrate to generate the database. It might be required to delete the migration folder beforehand.

License

Apache 2.0