Skip to main content

Environment Setup

This guide covers everything needed to run GTM Clarity locally or deploy it to production, including prerequisites, environment configuration, and development commands.

Prerequisites

DependencyVersionPurpose
Node.js18+Runtime
npm9+Package manager
PostgreSQL15+ (or Neon serverless)Primary database
Temporal Server1.15+Workflow orchestration

Optional

DependencyPurpose
DockerRunning Temporal and PostgreSQL locally
Neon CLIManaging Neon serverless PostgreSQL

Environment Variables

Create a .env file in the project root. Use .env.example as a template:

Authentication (Clerk)

VariableRequiredDescription
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYYesClerk publishable key (starts with pk_test_ or pk_live_)
CLERK_SECRET_KEYYesClerk secret key (starts with sk_test_ or sk_live_)
NEXT_PUBLIC_CLERK_SIGN_IN_URLYesSign-in page path (default: /sign-in)
NEXT_PUBLIC_CLERK_SIGN_UP_URLYesSign-up page path (default: /sign-up)
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URLYesRedirect after sign-in (default: /)
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URLYesRedirect after sign-up (default: /)

Database (Neon PostgreSQL)

VariableRequiredDescription
DATABASE_URLYesPostgreSQL connection string (Neon pooled endpoint with ?sslmode=require)

Salesforce OAuth

VariableRequiredDescription
SALESFORCE_CLIENT_IDIf using SalesforceConnected App client ID (from Setup > App Manager)
SALESFORCE_CLIENT_SECRETIf using SalesforceConnected App client secret
SALESFORCE_CALLBACK_URLIf using SalesforceOAuth callback URL (default: http://localhost:3000/api/connectors/salesforce/callback)

Connector Security

VariableRequiredDescription
CONNECTOR_ENCRYPTION_KEYYes32-byte hex string for AES-256-GCM token encryption

Generate the encryption key:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Security

Never commit .env files to source control. The .gitignore file is pre-configured to exclude them. If you suspect a key has been compromised, rotate it immediately and re-authenticate all connectors.

Database Setup

  1. Create an account at neon.tech
  2. Create a new project and database named scoring
  3. Copy the pooled connection string to DATABASE_URL
  4. Run migrations:
npm run drizzle migrate

Option 2: Local PostgreSQL

  1. Install PostgreSQL 15+
  2. Create a database:
createdb scoring
  1. Set DATABASE_URL=postgresql://localhost:5432/scoring in .env
  2. Run migrations:
npm run drizzle migrate

Drizzle ORM Commands

CommandDescription
npm run drizzle migrateRun pending migrations
npm run drizzle studioOpen interactive DB browser at https://local.drizzle.studio

Clerk Setup

  1. Create an account at clerk.com
  2. Create a new application
  3. Enable Organizations in the Clerk dashboard (required for multi-tenancy)
  4. Copy the publishable key and secret key to .env
  5. Configure the redirect URLs to match your deployment
info

Clerk Organizations are the backbone of GTM Clarity's multi-tenant model. Make sure to enable the Organizations feature before first use.

Temporal Server

docker run -d \
--name temporal \
-p 7233:7233 \
-p 8233:8233 \
temporalio/auto-setup:latest

This starts the Temporal server on port 7233 and the Web UI on port 8233.

Option 2: Temporal Cloud (Production)

For production deployments, use Temporal Cloud:

  1. Create a Temporal Cloud namespace
  2. Configure mTLS certificates
  3. Set the connection details in your environment

Starting the Worker

The Temporal worker runs as a separate process:

npx tsx src/connectors/temporal/worker.ts
tip

In production, run the Temporal worker on dedicated instances separate from the web server. Use process managers like PM2 or container orchestration for automatic restarts.

Local Development

Install Dependencies

npm install

Run Development Server

npm run dev

The application starts at http://localhost:3000.

Run Tests

# Unit tests (Vitest)
npm test

# Watch mode
npm test -- --watch

# Specific test file
npm test -- tests/scoring/fit-engine.test.ts

# E2E tests (Playwright)
npm run test:e2e

Code Quality

# Lint
npm run lint

# Type check
npm run type-check

# Production build
npm run build

Production Build

npm run build
npm start

Production Checklist

ItemDetails
Set all env variablesAll Required variables from the table above
Run database migrationsnpm run drizzle migrate
Start Temporal workerSeparate process on connector-sync task queue
Configure Temporal cronSchedule scheduledSyncWorkflow per tenant
Verify Clerk organizationsEnable Organizations feature
Generate encryption keyUse crypto random bytes, store securely
Set up monitoringTemporal Web UI, application logs, error tracking

Tech Stack Reference

LayerTechnologyVersion
FrontendNext.js (App Router)16.1.6
UI FrameworkReact19.2.3
StylingTailwind CSS4
ChartsRecharts3.7
APItRPC11.10
AuthClerk6.39
DatabasePostgreSQL (Neon)15+
ORMDrizzle ORM0.45.1
WorkflowsTemporal.io1.15
CRM SDKJSForce3.10
ValidationZod4.3
TestingVitest4.0
E2E TestingPlaywright1.58