Skip to main content
doc0blade47/compdocumentation home
Sign in

Configuration

Last updated Oct 11, 2026
Relevant source files

The following files were used as context for generating this wiki page:

This page details the configuration management within the project, focusing on how environment variables are loaded and how application-specific settings for services like AWS and "Better Auth" are defined and validated. The system leverages dotenv for loading environment variables and zod for robust schema validation, ensuring that all necessary configurations are present and correctly formatted at application startup.

The configuration architecture aims to provide a clear, centralized, and validated approach to managing application settings, reducing runtime errors caused by missing or malformed environment variables.

Environment Variable Loading

The project utilizes a dedicated module, load-env.ts, to manage the loading of environment variables from .env files. This module ensures that environment variables are loaded early in the application lifecycle, supporting various deployment and development environments. It searches for .env files in predefined locations to maximize flexibility.

The loadEnv function attempts to load the .env file from several common paths:

  1. Relative to the compiled output (dist/src/.env).
  2. Relative to the source directory (src/.env).
  3. In the current working directory (process.cwd()/.env).

Once an .env file is found, its variables are loaded and can optionally override existing environment variables. The ensureEnvLoaded function provides a mechanism to guarantee that environment variables have been processed, preventing redundant loading.

// apps/api/src/config/load-env.ts
const searchPaths = [
  // When compiled to dist/src (Nest build output)
  path.join(__dirname, '..', '..', '.env'),
  // When running with ts-node directly from src
  path.join(__dirname, '..', '.env'),
  // Fallback to current working directory
  path.join(process.cwd(), '.env'),
];
 
function loadEnv(): void {
  for (const envPath of searchPaths) {
    if (existsSync(envPath)) {
      config({ path: envPath, override: true });
      envLoaded = true;
      return;
    }
  }
  envLoaded = true;
}

Environment Loading Flow

Sources: apps/api/src/config/load-env.ts:1-25

Application-Specific Configurations

The project uses @nestjs/config's registerAs function in conjunction with zod schemas to define and validate specific configuration objects. This approach provides type safety and ensures that critical application settings are correctly structured and present.

AWS Configuration

The AWS configuration (aws.config.ts) defines the necessary parameters for interacting with Amazon Web Services. It includes settings for region, access keys, and S3 bucket details.

Validation

The AWS configuration is validated at application startup using a zod schema. If any required environment variables are missing or invalid, the application will throw an error and fail to start, preventing potential runtime issues.

AWS Configuration Options

OptionEnvironment VariableDescriptionDefault ValueRequired
regionAPP_AWS_REGIONAWS region to connect to.us-east-1No
accessKeyIdAPP_AWS_ACCESS_KEY_IDAWS access key ID.Yes
secretAccessKeyAPP_AWS_SECRET_ACCESS_KEYAWS secret access key.Yes
bucketNameAPP_AWS_BUCKET_NAMEName of the S3 bucket to use.Yes
endpointAPP_AWS_ENDPOINTCustom endpoint for AWS services (e.g., for localstack).No

Sources: apps/api/src/config/aws.config.ts:1-33

AWS Configuration Schema

Better Auth Configuration

The "Better Auth" configuration (better-auth.config.ts) specifies the URL for an external authentication service.

Validation

The BETTER_AUTH_URL environment variable is required. If it is not provided or is not a valid URL, the application will fail to start.

Better Auth Configuration Options

OptionEnvironment VariableDescriptionRequired
urlBETTER_AUTH_URLThe URL of the "Better Auth" service.Yes

Sources: apps/api/src/config/better-auth.config.ts:1-27

Better Auth Configuration Schema

Configuration Validation Flow

General Environment Variable Setup

For local development, environment variables are typically managed through .env files. The project provides example .env.example files that should be copied and filled with actual credentials.

  1. Create .env files

    Copy the example environment files for each application and package.

    cp apps/app/.env.example apps/app/.env
    cp apps/portal/.env.example apps/portal/.env
    cp packages/db/.env.example packages/db/.env
  2. Fill out required variables

    Populate the newly created .env files with your specific credentials and settings.

    Important

    Ensure all required variables are present. The README.md specifically highlights the need for NEXT_PUBLIC_PORTAL_URL and REVALIDATION_SECRET in comp/apps/app/.env which might be missing from .env.example.

    Common Environment Variables

    | Variable | Description

Was this page helpful?