/nest-graphql-prisma-boilerplate

Starter template for Nest with GraphQL and Prisma plus infrastructure setup with Terraform + GCP πŸš€

Primary LanguageTypeScriptMIT LicenseMIT

Nest + Prisma + GraphQL Boilerplate

CI

This is a backend starter template based on Nest framework with completed setup of GraphQL and Prisma. The purpose of using the project is to minimize the redundant effort to setup a backend project from scratch. All of the basic setup done for you.

Prerequites

Quickstart

  1. Download zip or click "Use this template"
  2. Run npm install to install packages
  3. Run npm run migrate to generates SQL files and seed dummy data
  4. Run npm run start:dev to run locally with watch mode

Features

Nest with GraphQL and Prisma

Not only nest is a framework for building robust backend applications but also configuring GraphQL and Prisma with the typescript OOP concepts. In the boilerplate, GraphQL is configured with code first approach. You can see the GraphQL configuration here. Prisma is ORM for databases that can use as an alternative to writing plain SQL. The boilerplate configures Prisma to use SQLite for now but you can change to other databases i.e. PostgreSQL, MySQL, MongoDB.

Security and Monitoring

A health check represents a summary of health indicators. A health indicator executes a check of service, whether it is healthy or unhealthy. You'll be able to check the health status at http://localhost:8080/health once you spin up the backend template. The healthcheck module is defined here. A common technique to protect applications from brute-force attacks is rate-limiting. throttle module is a module to configure rate limiting.

Development environment

Environment variables, listing, code formatting, and testing are all configured for you as well as CI with Github action. You can see the config module to see how the environment variables are configured. Also Husky configuration is done for you to avoid unexpected errors happens while developing. In case linting and testing does not triggered on commit, please run npx husky install to enable git hook. Such tests often span a variety of types, including unit tests, end-to-end (e2e) tests, integration tests, and so on. Nest strives to promote the development best practices, including effective testing. Editor configuration is also done for you if you are using VSCode you'll be able to format code when you save.

Infrastructure

You can deploy the template with Cloud Build and Cloud Run with terraform. Cloud Run is a serverless platform from Google Cloud to deploy and run containers. It’s fully managed, autoscallable, and has a generous free tier. Cloud Build is CI/CD platform to build, test and deploy to Cloud Run. Please read README how to spin up the template with terraform.

Scripts

Installation

$ npm install

Database migration and seeding

$ npm run migrate

Running the app

# dev
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Listing, formatting

# eslint
$ npm run lint

# prettier
$ npm run format

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Licence

This project is available under the MIT license. See the LICENSE file for more info.