Environment

Type-safe Zod runtime environment variable validation across the monorepo.

Environment Package (`@repo/env`)

Runtime environment mistakes are one of the most common causes of production outages. Morax uses a dedicated packages/env powered by Zod to parse, validate, and autocomplete all environment variables across every app in your workspace.

Zod Validation Schema

Variables are validated on server startup. If a variable is missing or malformed, the process fails fast with a clear error:

packages/env/src/index.ts
// packages/env/src/index.ts
import { z } from 'zod';

const envSchema = z.object({
  NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
  DATABASE_URL: z.string().url(),
  BETTER_AUTH_SECRET: z.string().min(16),
  BETTER_AUTH_URL: z.string().url().default('http://localhost:3000'),
  server: z.object({
    PORT: z.coerce.number().default(4000),
    CORS_ORIGIN: z.string().default('http://localhost:3000'),
  }),
});

export const env = envSchema.parse(process.env);

Server vs. Client Safety

Secret keys (such as database credentials and auth secrets) are restricted to server-side bundles and prevented from accidentally leaking into public client bundles.

Usage Across Workspace Apps

Import env anywhere with instant type safety and editor autocomplete:

Consuming Env
import { env } from '@repo/env';

console.log(env.server.PORT); // Typed as number
console.log(env.DATABASE_URL); // Typed as string