Configuration Management (@wrelik/config)
Relevant source files
The following files were used as context for generating this wiki page:
The @wrelik/config package provides a centralized, typed system for managing environment variables and application settings across the Wrelik ecosystem. It is designed to ensure that all Wrelik applications adhere to a strict integration boundary by validating configuration at runtime using Zod and standardizing the loading process via dotenv.
As a core infrastructure package, it eliminates the need for manual process.env access in application code. Instead, it provides shared vendor schemas and extension hooks that allow applications to consume configuration in a type-safe manner. This approach supports the repository's core principle of an "adapter-first architecture" where vendor-specific configurations are handled centrally.
Sources: README.md:14-22, README.md:52-54, DECISIONS.md:14-17
Architecture and Design
The configuration system acts as a validator and loader for environment variables. It ensures that required keys are present and match the expected formats before the application starts.
Core Components
The package relies on two primary external libraries to perform its duties:
- dotenv: Used for loading environment variables from
.envfiles intoprocess.env. - Zod: Used for defining and validating schemas for those variables.
The diagram above illustrates how environment variables flow from raw files through validation into the application as typed objects.
Sources: packages/config/package.json:15-18, README.md:52-54
Implementation Details
The package is built using TypeScript and distributed in both CommonJS and ESM formats to support various Node.js environments.
Build and Distribution
The package uses tsup for its build pipeline, ensuring that type definitions (.d.ts) are generated for consumer use.
| Feature | Tool / Value | Description |
|---|---|---|
| Build Tool | tsup | Compiles src/index.ts to dist/ |
| Formats | cjs, esm | Supports both module systems |
| Entry Point | ./dist/index.js | Main execution entry |
| Types | ./dist/index.d.ts | TypeScript declarations |
Sources: packages/config/package.json:7-13
Integration with Other Packages
@wrelik/config is part of a larger ecosystem where standard integrations are enforced. While specific schema implementations are housed in src/index.ts, the package serves as the foundation for other vendor-specific packages like @wrelik/auth and @wrelik/db.
The diagram shows the relationship where specialized adapter packages depend on the configuration management logic to handle their environment requirements.
Sources: README.md:30-50, DECISIONS.md:4-12
Usage Principles
The @wrelik/config package enforces several architectural constraints defined in the project's core principles:
- Vendor Agnostic: Configuration schemas are designed to allow switching vendors (e.g., from one S3 provider to another) by only updating the central config and adapter, rather than the application logic.
- Explicit Boundaries: Applications are discouraged from accessing
process.envdirectly; they must use the typed outputs of the config package. - Minimal Surface Area: Only the configuration necessary for the infrastructure adapters is exposed.
Sources: README.md:14-22, DECISIONS.md:14-22
Summary
The @wrelik/config package is a foundational utility in the wrelik-kit monorepo. By combining dotenv for environment loading and Zod for runtime validation, it provides a robust, type-safe mechanism for managing application settings. This centralization supports the project's goal of maintaining vendor-agnostic adapters and enforcing strict integration boundaries across all Wrelik applications.