NextJS, NestJS, Prisma, PostgreSQL
dev
: start the frontend and backend (hot reloading)format
: run prettier formatterlint
: run eslinttest
: run all teststsc
: run ts checkermigrate
: run prisma migrate and make changes to local db inapps/server
gen-client
: regenerate client used to communicate with backend inapps/web
dev:db:up
: start up the database inapps
dev:db:down
: stop the database inapps
backend:docker:build
: build the docker image for the backend inapps
backend:docker:run
: start the backend and database stack inapps
backend:docker:down
: stop the backend and database stack inapps
prisma db seed
: run database seed script inapps/server
-
Create a .env file in
apps/web
andapps/server
and configure environment variables using the provided example files.apps/server/.env
VARIABLE VALUE DOMAIN http://localhost BACKEND_PORT 8080 SALT_ROUNDS 10 DATABASE_URL postgresql://user:pass@localhost:5432/db?schema=public JWT_SECRET Execute the following to generate a random secret key: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))" JWT_VALID_DURATION 600 JWT_REFRESH_VALID_DURATION 604800 FRONTEND_DOMAIN http://localhost:3002 POSTMARK_SERVER_KEY NODE_ENV development apps/web/.env
VARIABLE VALUE FRONTEND_PORT 3000 AZURE_AD_CLIENT_ID AZURE_AD_CLIENT_SECRET AZURE_AD_TENANT_ID STORAGE_BLOB_URL NEXTAUTH_SECRET NEXTAUTH_URL http://localhost:3002 -
Install yarn dependencies. We currently use Yarn and Yarn workspaces to manage dependencies.
yarn install
-
Generate the Prisma Client in the
apps/server
directory using the following command from within theapps/server
directory:yarn prisma generate
-
Start up your local database in
apps
directory:yarn backend:docker:run yarn dev:db:up
-
Migrate your local database using Prisma Migrate in order to set up database schemas.
yarn migrate
-
Run the frontend and backend locally. The environment variables should be configured to use our local stack:
yarn dev
The client should be hosted at http://localhost:3000.
The server should be hosted at http://localhost:8080.
We utilize a reverse proxy hosted at http://localhost:3002 to allow for CORS/Access Control. To interact with the frontend, visit http://localhost:3002. All backend traffic will also be directed to http://localhost:3002, and the proxy forwards traffic accordingly. Backend traffic is differentiated by a
/api
in the url. -
The database should be located at http://localhost:5432. pgadmin is accessible from http://localhost:5050, and the credentials are
admin@admin.com:pgadmin4
. To connect to the database using pgadmin, create a new server connection with the host set tohost.docker.internal
, port set to5432
, and username and password set touser
andpass
respectively.
When making changes to our backend, we need to regenerate our frontend client to allow us to access the updated endpoints.
-
Start instance of backend server hosted at http://localhost:8080 by running the following command in the server directory:
yarn dev
-
Run the following command:
yarn gen-client
The client should be regenerated based on the running local backend instance.
Run the database seeding script (seed.ts) to initially populate the database.
-
Start docker container and backend database in
apps
yarn backend:docker:run yarn dev:db:up
-
Generate the Prisma Client in the
apps/server
directory using the following command from within theapps/server
directory:yarn prisma generate
-
To reset existing migrations and run the seeding script, run the following command in
apps/server
:yarn prisma migrate reset
-
To run the seeding script and leave existing migrations, run the following command in
apps/server
:yarn prisma db seed