sandboxnu / mfa-form-automator

Form-signing platform for the Museum of Fine Arts, Boston
https://mfa-form-automator.vercel.app
1 stars 0 forks source link

MFA Form Automator

Tech Stack

NextJS, NestJS, Prisma, PostgreSQL

Overview of Yarn Commands

Getting Started (Local Development)

  1. Create a .env file in apps/web and apps/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
  2. Install yarn dependencies. We currently use Yarn and Yarn workspaces to manage dependencies.

    yarn install
  3. Generate the Prisma Client in the apps/server directory using the following command from within the apps/server directory:

    yarn prisma generate
  4. Start up your local database in apps directory:

    yarn backend:docker:run
    yarn dev:db:up
  5. Migrate your local database using Prisma Migrate in order to set up database schemas.

    yarn migrate
  6. 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.

  7. 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 to host.docker.internal, port set to 5432, and username and password set to user and pass respectively.

Regenerating Client

When making changes to our backend, we need to regenerate our frontend client to allow us to access the updated endpoints.

  1. Start instance of backend server hosted at http://localhost:8080 by running the following command in the server directory:

    yarn dev
  2. Run the following command:

    yarn gen-client

    The client should be regenerated based on the running local backend instance.

Database Seeding

Run the database seeding script (seed.ts) to initially populate the database.

  1. Start docker container and backend database in apps

    yarn backend:docker:run
    yarn dev:db:up
  2. Generate the Prisma Client in the apps/server directory using the following command from within the apps/server directory:

    yarn prisma generate
  3. To reset existing migrations and run the seeding script, run the following command in apps/server:

    yarn prisma migrate reset
  4. To run the seeding script and leave existing migrations, run the following command in apps/server:

    yarn prisma db seed