This is a generic nestjs backend that can be used to create a backend for any project. It can be deployed anywhere that you can deploy a docker container, and hooked up to any postgres database provider. It also includes instructions and configuration for easy local debugging. You can 1-click deploy on railway using the link below (you'll need to create a railway account first).
- User authentication (using JWTs, refresh tokens, etc.)
- Creating users and organizations (i.e. multi tenant support)
- Creating and issuing API keys with attached scopes
- Transactional email using resend
- Nest.js as the server framework (using fastify under the hood)
- prisma + postgres as the database
- docker for local development
- passport.js for authentication
- jest for testing
- eslint for linting
- prettier for formatting
- Branch all PRs from the
main
branch using the branch name from Linear (cmd+shift+. on mac). - Do your work.
- Push upstream and open a PR to merge into
main
. - Once the PR is approved, merge it into
main
. This will push the changes to the prod environment.
If you're using vscode, you can use the Start Debug Server
config, which will:
- spin up the database and adminer containers
- Start the API in dev mode (i.e. hot reload)
- Spin down the containers when you kill the debugger
Otherwise, just run docker compose up db adminer
to spin up the database and adminer containers, and then run npm run start:dev
to start the API in dev mode (and docker compose down
to spin down the containers when you're done).
These instructions are cribbed from here.
- Download the latest docker desktop release.
- Run the following command to pull the latest images and then start the container:
docker compose up db
To build everything, omit db
, which will spin up the server and adminer db UI, all in the docker container. To include adminer but not turn on the server in the container, add adminer
(i.e. docker compose up db adminer
).
If you need to rebuild a container, run the following command:
docker compose up --build # omit container name to rebuild all
To remove old containers:
docker compose down # removes all containers
docker compose down --volumes # Remove containers and volumes
See best practices from prisma here.
Overview:
- Make changes to the schema in
prisma/schema.prisma
. - Start the local database container (see above).
- run
npm run prisma:debug
to test the change on the local database (or runnpx prisma db push
). - Keep making changes until you're happy with them, using the
prisma:debug
command to test them. - Once you're happy with them, you can
git stash
to stash the changes you made to the schema and runprisma:debug
once more go go back to what you had. Thengit stash pop
to get the changes back (which you know work, due to your prototyping in steps 1-4). - Finally, run
npm run prisma:dev <name>
(ornpx prisma migrate --name <name>
) create a migration that creates the changes. You can skip step 5, but that will create drift in the database that will force you to reset it completely.
Nest framework TypeScript starter repository.
npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov