sumitMomentum / platform-b2b-momentum

https://platform-b2b-momentum.vercel.app
MIT License
0 stars 0 forks source link

Setup for Next.js SaaS Dev in Local

Prerequisites

NGROK Setup

  1. Create an NGROK account.
  2. On the NGROK Dashboard (Cloud Edge > Domains), generate a new domain (the first one is free).
  3. Run the following command to set up your domain:
    ngrok http --domain=your-personal-domain.ngrok-free.app 3000
  4. Download and install NGROK on your local machine, and set it as an environment variable.
  5. Verify the installation by running the NGROK command in the terminal.

Clerk Setup

  1. Create a Clerk account.
  2. Create an application (give it any relevant name).
  3. Enable organization creation under Configure > Organization Settings.
  4. Customize the session token under Configure > Sessions, click Edit, and set the value as:
    {"metadata": "{{user.public_metadata}}"}
  5. Create a webhook under Configure > Webhooks.
  6. Set the custom URL to:

    https://<Serverdomain>/en/api/clerk

    (This is the domain generated by NGROK.)

  7. Subscribe to "Organization" and "User" events.
  8. Temporary Super Admin Access needs to be granted as of now.

Enode Setup

  1. Create an Enode account.
  2. Create an organization.
  3. Create a client on the Enode Dashboard. Set the client environment to Sandbox, and ensure the client and link UI names are the same.

SQL Setup

  1. Download and install MySQL server.
  2. Set up and start the server (create a user if it's new).
  3. Create a database.

Code Setup

  1. Install all dependencies:
    npm i

Setting Environment Variables

Set the following environment variables in your .env file:


Starting the App (In Sequence)

1. Start NGROK Local Server

Open the terminal and run:

ngrok http --domain=your-personal-domain.ngrok-free.app 3000

2. Update the Local Database

  1. Open the terminal in the app folder.
  2. Install Prisma globally if necessary:
    npm i prisma -g
  3. Populate the database:
    npx prisma migrate dev --name init

3. Set Environment Variables (Windows Only - If Required)

Open the terminal and set all environment variables from the .env file:

set variable_name=value

4. Start the App

Open the terminal and run:

npm run dev

Prisma Migration Guide

This guide outlines the steps to manage database migrations using Prisma in both development and production environments.

Development Environment

1. Set Up Your Development Environment

2. Make Changes to Your Prisma Schema

3. Create a Migration

4. Apply the Migration

5. Generate Prisma Client

6. Test Your Application

Production Environment

1. Prepare Your Production Environment

2. Create Migrations for Production

 npx prisma migrate dev --name descriptive_migration_name

3. Apply Migrations in Production

 npx prisma generate

4. Generate Prisma Client in Production

npx prisma generate

5. Test in Production

6. Backup Your Database (Optional but Recommended)

Transitioning from Development to Production

  1. Develop and Test Locally : Make and test your changes in the development environment.
  2. Create Migration Files : Use the migrate dev command to create migration files.
  3. Deploy to Production : When ready, transition to production by using the migrate deploy command.
  4. Generate Client : Ensure the Prisma Client is generated after deploying migrations.
  5. Validate : Test your application in production to confirm that all features work as intended.

Notes: