Skip to content

πŸš€ Production-ready boilerplate with query validation and dynamic typing with Typescript. A highly scalable foundation API, with focus on security, and best practices. Below a live example :

License

Cyril-Deschamps/fastify-typescript-prisma-boilerplate

Repository files navigation

fastify-typescript-prisma-boilerplate

Typescript NodeJS License CI/CD status

Project Highlights
β€’ Request validation with schema Typebox
β€’ Prisma as ORM
β€’ Efficient error handling and logger
β€’ Routes guard with middleware equivalent



πŸ‘©πŸ»β€πŸ’» Developer Ready:

A comprehensive template. Followed strict and REST guidelines

πŸ’Ό Ready for production:

Built-in GitHub Actions script to check linter and deploy. Dockerfile already configurated. See below how to use secrets.

🎁 Opensource:

Available under the APLv2 license.




Features

  • Execution environment : Node 16 with ESM and Yarn
  • Framework : Fastify
  • Language : TypeScript 5.3
  • ORM : Prisma
  • Schema validator : Typebox
  • Security : jsonwebtoken and bcrypt
  • Format : Prettier to enforce consistent code style
  • Linter : ESLint with good practices of clean code
  • GIT Helper : Husky + Commitlint + Commitizen
  • CI/CD : GitHub Actions + Docker

Getting started

The project required Node.js v16 or later.

Clone repository

To clone the repository, use the following commands:

git clone https://github.com/Cyril-Deschamps/fastify-typescript-prisma-boilerplate.git
mv fastify-typescript-prisma-boilerplate your-project-name
cd your-project-name
yarn install

Available Scripts

  • watch - start project in dev mode with hot reload,
  • start - start JS Project,
  • build - transpile TypeScript to ES6,
  • prepare - to install husky hooks,
  • migrate - migrate Prisma schema to remote database,
  • npm-run-all lint-check:\* - Process eslint and prettier checks,
  • npm-run-all lint-fix:\* - Process eslint, prettier checks and try to resolve,

Secrets

Secrets are stored in github secrets. For a local environment, you can use the .env file to store the secret (see .env.example).

General secret

Variable Description Exemple
APP_SECRET The secret used for the cookies (32 chars recommended) UΒ£,rGtD~Fm;1TY9!Zmpz&R7q&0Sdz@2H
APP_CORS_ORIGIN List of the CORS in the shape http://localhost,https://cyrildeschamps.fr

For each environment

Development

Variable Description Example
DEVELOPMENT_APP_BACKEND_PUBLIC_URL HTTP API address https://boilerplate.cyrildeschamps.fr
DEVELOPMENT_APP_FRONTEND_PUBLIC_URL Web application address https://boilerplate.cyrildeschamps.fr
DEVELOPMENT_APP_DATABASE_URL Database URL mysql://user:password@hostname:ip/dbname?schema=public
DEVELOPMENT_HOST Deployment server IP 66.254.114.41
DEVELOPMENT_PORT Deployment server SSH port 22
DEVELOPMENT_SSHKEY SSH key for connecting to the server See server's .ssh/id_... file
DEVELOPMENT_USERNAME Username for connecting to the server debian
DEVELOPMENT_DOCKER_IMAGES_PATH Name of the folder where the project is stored on the server /home/debian/docker-container-images
DEVELOPMENT_DOCKER_LOCAL_IP Local IP (nginx) of the container 172.0.0.18

Production

Variable Description Example
PRODUCTION_APP_BACKEND_PUBLIC_URL HTTP API address https://cyrildeschamps.fr
PRODUCTION_APP_FRONTEND_PUBLIC_URL Web application address https://cyrildeschamps.fr
PRODUCTION_APP_DATABASE_URL Database URL mysql://user:password@hostname:ip/dbname?schema=public
PRODUCTION_HOST Deployment server IP 66.254.114.41
PRODUCTION_PORT Deployment server SSH port 22
PRODUCTION_SSHKEY SSH key for connecting to the server See server's .ssh/id_... file
PRODUCTION_USERNAME Username for connecting to the server debian
PRODUCTION_DOCKER_IMAGES_PATH Name of the folder where the project is stored on the server /home/debian/docker-container-images
PRODUCTION_DOCKER_LOCAL_IP Local IP (nginx) of the container 172.0.0.19

Support

You can support this project by contributing to it, by posting issues and proposing pull request.

License

Licensed under the APLv2. See the LICENSE file for details.

Improvements

  • Use github environment to store secrets and maybe reduce the number of secrets
  • Add testing with Jest or other
  • Auto-tagging with semantic-release
  • Manage migration file between tags or environment)
  • And, all others improvements are welcome...