Opinionated boilerplate to build a Fastify app and Mongodb with better DX.
This is a fork of fastify-esbuild
, a great work from David Peng Thank's David.
This code is born after reading the articles on Better Backend DX: Fastify + ESBuild = ⚡️
In addition this project have these features :
- Complete MongoDB collections management with node-mongo package to simplify Mongodb usage. It is used the official Node.js driver (Mongoose is not used)
- Full test suite using Vitest
- Configuration using dotenv environments
- CRUD complete for the
boards
sample collection.
Feel to free enhancements, proposal, (errors).
https://davipon.hashnode.dev/better-backend-dx-fastify-esbuild)
- Use
@fastify/autoload
for filesystem-based routes & plugins. - Use
esbuild-kit/tsx
to reduce feedback loop during devlopment. - Use
esbuild
to bundle production code. - Use Conventional Commits & SemVer standards, e.g.
commitlint
,commitizen
,standard-version
. - Use
eslint
,prettier
,lint-staged
. - Use
husky
git hooks helper to run formatter & linter.
# Install dependencies
pnpm i
# Activate git hooks
pnpm prepare
# Start development
pnpm dev
# Build production code
pnpm build
# Run production code
pnpm start
The suggested dimension for avatar is 60x60 pixels
For authorize an API request is necessary to check if Bearer token passed in header has the right to execute the action
Is the preHandler function inside core folder used by each route that has to be protected. If the [enforce] function finish without reply and error or status code mean that the request can be executed. Otherwise it will be reply the error and status code and the request will be aborted
Inside route definition is necessary to define a configuration object with the following shape
config: { resource: 'resourceName', scope: '[read-write-delete]' },
The object properties must be the same with the one defined inside keycloak console administration under **Client -> Authservice -> Authorization -> resources
Is a fastify hook that will be executed before route handler