Configuration

Configuration Package (@repo/config)

This package centralizes application-wide feature flags and configuration settings.

Why You Need This

By keeping feature flags in one place you can toggle functionality without hunting through multiple files. It also ensures every package reads the same values. Visit the Monorepo Foundations guide to learn how configuration is shared.

Purpose

Instead of scattering configuration values or feature flags across the codebase or relying solely on environment variables for structural configuration, this package provides a single, type-safe source of truth.

This allows enabling/disabling major features (like Organizations, specific Auth methods) or setting application constants consistently across different parts of the monorepo (API, web app, mobile app).

Structure

  • src/index.ts: Exports the main config object.
  • src/type.ts: Defines the AppConfig interface, ensuring type safety for the configuration object.

Configuration Object (config)

The exported config object contains various nested properties to control different application domains.

import type { AppConfig } from "./type"; export const config: AppConfig = { organizations: { enabled: true, // Is the multi-tenancy/organization feature enabled? teams: { enabled: true, // Are teams within organizations enabled? maxPerOrg: 99, // Max teams allowed per organization allowRemovingAll: false, // Can users remove all team members? }, invites: { enabled: true, // Are organization invitations enabled? }, freePlan: { enabled: true, // Is there a default free plan for organizations? }, }, auth: { singleUserMode: true, // Is the app running in single-user mode? requireEmailVerification: true, // Must users verify their email? enableEmailVerification: true, // Is the email verification flow active? enableEmailPassword: true, // Is standard email/password auth enabled? allowUserChangeEmail: true, // Can users change their email address? allowUserDeleteAccount: true, // Can users delete their own account? trustedOrigins: ["myapp://"], // Trusted origins for mobile redirects (e.g., deep links) freePlan: { enabled: true, // Is there a default free plan for individual users? }, }, api: { enabled: true, // Is the API generally enabled? openapi: { enabled: true, // Should OpenAPI documentation be generated/served? }, }, app: { scheme: "myapp", // The mobile app's URL scheme (for deep linking) storagePrefix: "myapp", // Prefix for local storage keys }, paymentProvider: "stripe", // Which payment provider integration is active? ("stripe" | "polar.sh") };

Type Definition (AppConfig)

The AppConfig interface ensures that the config object adheres to a specific structure and that consumers of the config benefit from type checking and autocompletion.

export interface AppConfig { organizations: { enabled: boolean; teams: { enabled: boolean; maxPerOrg: number; allowRemovingAll: boolean; }; invites: { enabled: boolean; }; freePlan?: { enabled?: boolean; }; }; auth: { requireEmailVerification: boolean; enableEmailVerification: boolean; enableEmailPassword: boolean; allowUserChangeEmail: boolean; allowUserDeleteAccount: boolean; trustedOrigins: string[]; singleUserMode?: boolean; freePlan?: { enabled?: boolean; }; }; api: { enabled: boolean; openapi?: { enabled?: boolean; }; }; app: { scheme: string; storagePrefix: string; }; paymentProvider?: "stripe" | "polar.sh"; // Add more domains here if needed }

Usage

Import the config object from @repo/config wherever you need to check a feature flag or access a configuration value.

import { config } from "@repo/config"; if (config.organizations.enabled) { // Render organization-related UI or enable API endpoints } const useTeams = config.organizations.teams.enabled; const paymentProvider = config.paymentProvider; // "stripe" or "polar.sh"

Info: This config is primarily for build-time or application startup configuration. Sensitive credentials or runtime-specific values should still use environment variables.