Configuration Management
Relevant source files
The following files were used as context for generating this wiki page:
The Gauzy platform utilizes a centralized and environment-aware configuration management system encapsulated within the @gauzy/config package. This system is built on top of the NestJS ConfigModule and is responsible for loading, parsing, and providing access to configuration parameters across the entire application. It supports default values, environment-specific overrides via .env files, and provides a typed ConfigService for safe access to configuration properties, particularly for critical settings like database connections, authentication, and third-party service integrations.
Sources: packages/config/package.json:1-5, packages/config/src/lib/config.service.ts
Architecture Overview
The configuration system is designed to be flexible and hierarchical. It loads settings from multiple sources, with environment variables having the highest precedence. This allows developers to easily switch between development, testing, and production environments without changing the codebase.
The core components are:
ConfigService: A service that provides a unifiedget()method to retrieve configuration values. It acts as a wrapper around the underlying NestJSConfigService.default-config.ts: A file containing the baseline configuration for the entire application. These values are used if not overridden by environment variables..envfiles: Standarddotenvfiles (e.g.,.env.local,.env.production) are used to override default settings for specific environments.
Sources: packages/config/src/lib/config.service.ts:10-12, packages/config/src/lib/default-config.ts
Configuration Loading Flow
The following diagram illustrates the process of how configuration values are loaded and resolved.
This diagram shows that the ConfigService resolves values by first checking .env files, then system environment variables, and finally falling back to the values defined in default-config.ts.
Sources: packages/config/src/lib/config.service.ts, .env.example
Core Components
ConfigService
The ConfigService is the primary interface for accessing configuration values. It is an injectable NestJS service that extends the built-in @nestjs/config service, providing a consistent API for the rest of the application.
// packages/config/src/lib/config.service.ts:10-12
import { ConfigService as NestConfigService } from '@nestjs/config';
@Injectable()
export class ConfigService extends NestConfigService {}
The service is exported from the @gauzy/config package, making it available for dependency injection in other modules.
Sources: packages/config/src/lib/config.service.ts:10-12, packages/config/src/index.ts:4
Default Configuration
The default-config.ts file establishes the default values for all configuration parameters. This ensures that the application can run out-of-the-box with a sensible default setup, typically using in-memory or local file-based services like SQLite. These defaults are designed to be overridden by environment variables for staging and production deployments.
Key default settings include:
- Database: Defaults to
sqlite. - API Port: Defaults to
3000. - JWT: Default secret and expiration times are defined.
- File Storage: Defaults to local file system storage.
The diagram below shows the structure of the default configuration object.
This diagram illustrates the nested objects within the defaultConfig export, such as database and JWT settings.
Sources: packages/config/src/lib/default-config.ts:10-188
Environment Variables
Environment variables are the primary mechanism for configuring the application for different deployment environments (development, staging, production). The .env.example file serves as a template for all available environment variables.
Sources: .env.example
Key Configuration Variables
The following table summarizes some of the most important environment variables defined in .env.example.
| Variable | Description | Example Value |
|---|---|---|
NODE_ENV | Sets the application environment. | development |
API_HOST | The hostname for the API server. | http://localhost |
API_PORT | The port on which the API server listens. | 3000 |
DB_TYPE | The type of database to use (postgres, mysql, sqlite). | postgres |
DB_HOST | The database server hostname. | localhost |
DB_PORT | The database server port. | 5432 |
DB_USERNAME | The username for the database connection. | postgres |
DB_PASSWORD | The password for the database connection. | admin |
DB_DATABASE | The name of the database. | gauzy |
JWT_SECRET | Secret key for signing JWT access tokens. | your_jwt_secret |
JWT_EXPIRATION | Expiration time for JWT access tokens. | 1d |
REFRESH_TOKEN_SECRET | Secret key for signing JWT refresh tokens. | your_refresh_token_secret |
REFRESH_TOKEN_EXPIRATION | Expiration time for JWT refresh tokens. | 7d |
FILE_PROVIDER | The service to use for file storage (local, s3, wasabi). | local |
S3_ACCESS_KEY_ID | Access key for AWS S3. | your_s3_key_id |
S3_SECRET_ACCESS_KEY | Secret access key for AWS S3. | your_s3_secret |
S3_BUCKET | The S3 bucket name for file storage. | gauzy |
REDIS_URL | Connection URL for Redis. | redis://localhost:6379 |
Sources: .env.example:1-180
Database Configuration
The configuration package is responsible for providing settings for multiple data access layers, including TypeORM, MikroORM, and Knex.js. The choice of database driver and connection parameters is determined by environment variables.
The ConfigService reads variables like DB_TYPE, DB_HOST, DB_PORT, etc., to dynamically construct the configuration object required by each ORM. This allows the platform to support various SQL databases such as PostgreSQL, MySQL, and SQLite.
The dependencies in packages/config/package.json reflect this multi-ORM support.
// packages/config/package.json:23-33
"dependencies": {
// ...
"@mikro-orm/better-sqlite": "^6.4.13",
"@mikro-orm/core": "^6.4.13",
"@mikro-orm/mysql": "^6.4.13",
"@mikro-orm/nestjs": "^6.1.1",
"@mikro-orm/postgresql": "^6.4.13",
"@nestjs/config": "^4.0.2",
"@nestjs/typeorm": "^11.0.0",
// ...
"nest-knexjs": "^0.0.26",
// ...
"typeorm": "^0.3.27"
}
Sources: packages/config/package.json:23-33, .env.example:12-18
Database Driver Selection Logic
The DB_TYPE environment variable is crucial for determining which database driver to use. The application logic for database connection would typically follow this flow:
This diagram shows how the DB_TYPE variable dictates which database connection library is initialized and used by the application.
Sources: .env.example:12, packages/config/package.json:23-33