Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/src/common/shared-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Module} from '@nestjs/common'
import {ConfigModule} from '../kernel/core/configuration/config-module.js'
import {ConfigModule} from '../core/configuration/config-module.js'
import {XcacheModule} from '../kernel/modules/cache/xcache-module.js'
import {RedisModule} from '../kernel/resource/redis/redis.module.js'
import {AccountModule} from '../modules/account/account.module.js'
Expand Down
35 changes: 35 additions & 0 deletions apps/server/src/core/configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Configuration

`Configurator` will look for application configuration files, then will
search environment variables and at the end if environment variables
provided external secret providers will hit them up for secrets.
If the configuration wasn't satisfied, error will be thrown.

- Environment Variables
- Configuration Files
- Command Line Arguments
- Externalized configuration providers

## RC-like Configuration

Application always will take command-line parameters as the highest priority,
then environment variables, then configuration files.
However, if the external configuration provider is available by configuration
software such as Consul, Vault, or any other, it'll be used as the highest
priority once the application will connect to it.

## Configuration File Resolution

// TODO: ...

## Configuration File Format

- json
- yaml
- toml
- xml
- ini
- hcl
- properties
- dotenv
- env
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
*
*/

import {
DynamicModule,
Module,
} from '@nestjs/common'
import {ConfigurationService} from '../../../configs/service/configuration-service.js'
import {DynamicModule, Module} from '@nestjs/common'
import {ConfigurationService} from '../../configs/service/configuration-service.js'



Expand Down
92 changes: 92 additions & 0 deletions apps/server/src/core/configuration/configuration-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
//One secure mechanism for handling secrets in Node.js is using a library or implementing a Secret Manager approach as previously discussed, along with some additional best practices.
//
//1. Leverage a library: Utilize a secure library such as `dotenv` or `env-var` for handling environment variables, or `node-secret-loader` for loading secrets from environment variables or files. These libraries provide better safety and abstraction in handling secrets.
//
//2. Encryption: Use encryption to protect secrets, especially when they're stored in configuration files or in a secure environment variable storage service like HashiCorp Vault. This prevents the secrets from being visible to anyone who gains access to the server's file system.
//
//3. Secure the environment variables storage: Store your secrets in environment variables rather than in your code, but be careful about where these environment variables are stored. Do not hard-code them directly in the source code. Instead, consider using tools like `dotenv`, which let you store environment variables in a `.env` file and load them only in development and testing environments.
//
//4. Use a configuration management tool: Employ a configuration management tool like `Fig` or `Kelsey Hightower's envconfig` that can help you manage and securely store secrets and configuration data. These tools can also ensure that secrets are only available to the specific services that need them.
//
//5. Limit access: Restrict access to secrets by using process isolation (like containers) or user permissions. This way, even if an attacker gains access to one process, they won't necessarily have access to secrets stored in other processes.
//
//6. Audit and monitor: Log any access to secrets, and monitor for unusual or unauthorized activity. This helps you detect if there have been breaches, and enables you to respond quickly.
//
//7. Regularly rotate secrets: Periodically rotate sensitive secrets, especially those used for authentication and cryptographic purposes, to limit the potential damage caused by a possible compromise.
//
// By following these best practices, you can significantly improve the security of handling secrets in Node.js applications.



export interface HttpServerConfiguration {
port: number
host: string
protocol: "http" | "https"
}

export interface Configuration {
environment: "production" | "staging" | "testing" | "development" | "local"
http: HttpServerConfiguration
cacheMechanism: "redis" | "memcached" | "memory"
}
Comment on lines +28 to +32
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export interface Configuration {
	environment: "production" | "staging" | "testing" | "development" | "local"
	http: HttpServerConfiguration
	cacheMechanism: CacheMechanismConfiguration
}

export interface RedisCacheConfiguration {
	host: string
	port: number
	password?: string
}

export interface MemcachedCacheConfiguration {
	servers: string[]
	options?: Memcached.Options
}

export interface InMemoryCacheConfiguration {
	maxSize?: number
	ttl?: number
}

type CacheMechanismConfiguration =
	| { type: "redis"; config: RedisCacheConfiguration }
	| { type: "memcached"; config: MemcachedCacheConfiguration }
	| { type: "memory"; config: InMemoryCacheConfiguration };



type ConfigType<K extends keyof Configuration> = K extends "http" ? HttpConfig : never;

type HttpConfig = {
port: number; host: string; protocol: "http" | "https";
};


export interface ConfigurationLoader {
load(): Promise<Partial<Configuration>>
}


export class DotEnvConfigurationLoader implements ConfigurationLoader {
async load(): Promise<Partial<Configuration>> {
return {}
}
}


export class RcLoader implements ConfigurationLoader {
async load(): Promise<Partial<Configuration>> {
return {}
}
}

export class ConfigCatLoader implements ConfigurationLoader {
async load(): Promise<Partial<Configuration>> {
return {}
}
}


/** Configuration Manager is a core service that's responsible for managing the configuration of the application.
* It's important to notice this class isn't intended to handle secrets themselves as they shouldn't be persisted
* or available in selected methods.
* For the secure operations, there's a secret manager that handles these values in a safe way. */
export class ConfigurationManager {
private readonly loaders: ConfigurationLoader[] = []


/// Loads configuration from specified sources
async load(): Promise<void> {
return Promise.resolve()
}


async get<K extends keyof Configuration>(key: K): Promise<Configuration[K]> {
return Promise.resolve({} as any)
}

async set<K extends keyof Configuration>(key: K, value: Configuration[K]): Promise<void> {
return Promise.resolve()
}

async reset(): Promise<void> {
return Promise.resolve()
}
}
6 changes: 0 additions & 6 deletions apps/server/src/kernel/core/configuration/README.md

This file was deleted.

6 changes: 3 additions & 3 deletions apps/server/src/kernel/modules/mailer/mailer-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*
*/

import { Module } from '@nestjs/common'
import { Mailer } from './contract/mailer.js'
import { NoopMailer } from './provider/mailer/noop-mailer.js'
import {Module} from '@nestjs/common'
import {Mailer} from './mailer.js'
import {NoopMailer} from './provider/mailer/noop-mailer.js'



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
*/


import { CreateEmailMessagePayload } from '../dto/create-email-message-payload.js'
import {CreateEmailMessagePayload} from './dto/create-email-message-payload.js'



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@
*
*/



import {
Injectable,
Logger,
} from '@nestjs/common'
import { Mailer } from '../../contract/mailer.js'
import { CreateEmailMessagePayload } from '../../dto/create-email-message-payload.js'
import {Injectable, Logger} from '@nestjs/common'
import {CreateEmailMessagePayload} from '../../dto/create-email-message-payload.js'
import {Mailer} from '../../mailer.js'



Expand Down
11 changes: 11 additions & 0 deletions apps/server/src/kernel/runtime/autopilot/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# Autopilot

## Introduction

This is a simplified implementation for server autopilot -
an server that's able to manage itself and automate maintained tasks such as running migrations, backups, and more.

## Features

- `Automatic Migration`, once non-destructive migrations are added into stack server is able to manage them itself, and prepare a database once it'll connect to one.
- `Automatic Backup`, once backup is configured, server will be able to manage backups itself.
- `Automatic Restore`, once backup is configured, server will be able to manage restores itself.
Empty file.