Skip to main content

Constants Reference

The constants module (template/lib/constants.ts and template/lib/constants/) centralizes all application-wide configuration values, enums, environment-driven settings, and magic numbers. Constants are organized into domain-specific files to allow safe imports in contexts outside the Next.js runtime (e.g., migration scripts, seed scripts).

Architecture Overview

Source Files

FileDescription
lib/constants.tsMain constants barrel -- imports from env-config and re-exports sub-modules
lib/constants/payment.tsPayment enums and types (safe for scripts)
lib/constants/analytics.tsAnalytics-related constants

Localization Constants

const DEFAULT_LOCALE = 'en';

const LOCALES = [
'en', 'fr', 'es', 'de', 'zh', 'ar', 'he', 'ru', 'uk', 'pt',
'it', 'ja', 'ko', 'nl', 'pl', 'tr', 'vi', 'th', 'hi', 'id', 'bg'
] as const;

type Locale = (typeof LOCALES)[number];

/** Right-to-left locales */
const RTL_LOCALES: readonly Locale[] = ['ar', 'he'] as const;

Branding and UI

const LOGO_URL = '/logo-ever-work-3.png';

API and Backend

/** Base URL for internal Next.js API routes */
const API_BASE_URL = getNextPublicEnv('NEXT_PUBLIC_API_BASE_URL');

Authentication and Security

const COOKIE_SECRET = getNextPublicEnv('COOKIE_SECRET');
const JWT_ACCESS_TOKEN_EXPIRES_IN = getNextPublicEnv('JWT_ACCESS_TOKEN_EXPIRES_IN');
const JWT_REFRESH_TOKEN_EXPIRES_IN = getNextPublicEnv('JWT_REFRESH_TOKEN_EXPIRES_IN');

Analytics -- PostHog

ConstantSourceDescription
POSTHOG_KEYNEXT_PUBLIC_POSTHOG_KEYPostHog project API key
POSTHOG_HOSTNEXT_PUBLIC_POSTHOG_HOSTPostHog API host
POSTHOG_ENABLEDDerivedTrue when both key and host exist
POSTHOG_DEBUGPOSTHOG_DEBUGEnable debug logging
POSTHOG_SESSION_RECORDING_ENABLEDenv / 'true'Session recording toggle
POSTHOG_AUTO_CAPTUREenv / 'false'Auto-capture page views
POSTHOG_SAMPLE_RATEComputed0.1 in production, 1.0 in development
POSTHOG_SESSION_RECORDING_SAMPLE_RATEComputed0.1 in production, 1.0 in development

Error Tracking -- Sentry

ConstantSourceDescription
SENTRY_DSNNEXT_PUBLIC_SENTRY_DSNSentry Data Source Name
SENTRY_ENABLE_DEVSENTRY_ENABLE_DEVEnable Sentry in development
SENTRY_DEBUGSENTRY_DEBUGSentry debug mode
SENTRY_ENABLEDDerivedTrue when DSN is set and environment allows

Unified Exception Tracking

const EXCEPTION_TRACKING_PROVIDER = getNextPublicEnv('EXCEPTION_TRACKING_PROVIDER', 'both');
const POSTHOG_EXCEPTION_TRACKING = getNextPublicEnv('POSTHOG_EXCEPTION_TRACKING', 'true');
const SENTRY_EXCEPTION_TRACKING = getNextPublicEnv('SENTRY_EXCEPTION_TRACKING', 'true');

type ExceptionTrackingProvider = 'sentry' | 'posthog' | 'both' | 'none';

ReCAPTCHA

const RECAPTCHA_SITE_KEY = getNextPublicEnv('NEXT_PUBLIC_RECAPTCHA_SITE_KEY');
const RECAPTCHA_SECRET_KEY = getNextPublicEnv('RECAPTCHA_SECRET_KEY');

Payment Constants (constants/payment.ts)

This file is intentionally separated from constants.ts to avoid importing @/lib/config, allowing use in migration and seed scripts that run outside Next.js.

Enums

enum PaymentFlow {
PAY_AT_START = 'pay_at_start',
PAY_AT_END = 'pay_at_end',
}

enum PaymentStatus {
PENDING = 'pending',
PAID = 'paid',
FAILED = 'failed',
}

enum PaymentInterval {
DAILY = 'daily',
WEEKLY = 'weekly',
MONTHLY = 'monthly',
YEARLY = 'yearly',
ONE_TIME = 'one-time',
PER_SUBMISSION = 'per-submission',
}

enum PaymentPlan {
FREE = 'free',
STANDARD = 'standard',
PREMIUM = 'premium',
}

enum PaymentMethod {
CREDIT_CARD = 'credit_card',
PAYPAL = 'paypal',
}

enum PaymentCurrency {
USD = 'USD',
EUR = 'EUR',
GBP = 'GBP',
CAD = 'CAD',
AUD = 'AUD',
ETH = 'ETH',
}

enum PaymentProvider {
STRIPE = 'stripe',
SOLIDGATE = 'solidgate',
LEMONSQUEEZY = 'lemonsqueezy',
POLAR = 'polar',
}

enum SubmissionStatus {
DRAFT = 'draft',
PENDING = 'pending',
APPROVED = 'approved',
REJECTED = 'rejected',
PUBLISHED = 'published',
ARCHIVED = 'archived',
}

Plan Display Names

const PAYMENT_PLAN_NAMES: Record<PaymentPlan, string> = {
free: 'Free Plan',
standard: 'Standard Plan',
premium: 'Premium Plan',
};
const SponsorAdPricing = {
WEEKLY: 100, // $100.00
MONTHLY: 300, // $300.00
} as const;

Analytics Constants (constants/analytics.ts)

/** Cookie name for anonymous viewer tracking */
const VIEWER_COOKIE_NAME = 'ever_viewer_id';

/** Cookie max age: 365 days in seconds */
const VIEWER_COOKIE_MAX_AGE = 365 * 24 * 60 * 60; // 31,536,000

Import Patterns

Full Application Code

// Import everything from the main barrel
import {
DEFAULT_LOCALE,
LOCALES,
POSTHOG_ENABLED,
PaymentPlan,
PaymentProvider,
SubmissionStatus,
VIEWER_COOKIE_NAME,
} from '@/lib/constants';

Scripts Outside Next.js Runtime

// Import only from payment.ts to avoid Next.js dependencies
import { PaymentPlan, PaymentStatus, SubmissionStatus } from '@/lib/constants/payment';