Skip to content

Settings

FORGE provides a database-backed application settings system with support for typed values, grouping, encryption for sensitive data, and a public/private visibility model. Settings are managed through the admin panel and consumed by both backend and frontend.

Overview

Rather than relying solely on environment variables or configuration files, FORGE stores application settings in the database. This enables administrators to modify application behavior at runtime through the admin interface without redeployment.

Database Schema

The settings table stores all configuration values:

ColumnTypeDescription
idUUIDPrimary key
group_nameVARCHAR(100)Setting category (e.g., general, auth, email)
keyVARCHAR(100)Setting identifier (unique within group)
valueTEXTStored value (may be encrypted)
typeVARCHAR(20)Value type: string, boolean, number, json, encrypted
is_publicBOOLEANWhether the setting is exposed to the public API
is_sensitiveBOOLEANWhether the value should be masked in the admin UI
created_atTIMESTAMPRecord creation timestamp
updated_atTIMESTAMPLast update timestamp

Setting Groups

Settings are organized into logical groups:

General

KeyTypeDefaultPublicDescription
app_namestring"FORGE App"YesApplication display name
app_urlstring--YesBase URL of the application
timezonestring"UTC"YesDefault timezone
date_formatstring"YYYY-MM-DD"YesDate display format

Auth

KeyTypeDefaultPublicDescription
allow_registrationbooleantrueYesWhether new users can register
session_lifetimenumber1440NoSession duration in minutes
password_min_lengthnumber8YesMinimum password length
require_email_verifybooleantrueNoRequire email verification

Email

KeyTypeDefaultPublicSensitiveDescription
email_driverstring"smtp"NoNoEmail provider
email_hoststring--NoNoSMTP host address
email_portnumber587NoNoSMTP port
email_usernamestring--NoNoSMTP username
email_passwordencrypted--NoYesSMTP password
email_encryptionstring"tls"NoNoEncryption method
email_from_namestring--NoNoSender display name
email_from_addressstring--NoNoSender email address

Storage

KeyTypeDefaultPublicDescription
storage_driverstring"local"NoStorage backend
max_upload_sizenumber10YesMax file upload size in MB
allowed_typesjson--YesAllowed MIME types for upload

Encryption

Settings with type = "encrypted" are encrypted at rest using AES-256-GCM. The encryption key is provided via the FORGE_ENCRYPTION_KEY environment variable.

┌─────────────────────────────────────────────────────┐
│                 Encryption Flow                      │
├─────────────────────────────────────────────────────┤
│                                                      │
│  Plain Value ──► AES-256-GCM Encrypt ──► Stored     │
│                       │                              │
│              FORGE_ENCRYPTION_KEY                     │
│              (from environment)                       │
│                                                      │
│  Stored Value ──► AES-256-GCM Decrypt ──► Plain     │
│                       │                              │
│              FORGE_ENCRYPTION_KEY                     │
│                                                      │
└─────────────────────────────────────────────────────┘

WARNING

The FORGE_ENCRYPTION_KEY must be set in your environment before the application starts. If the key is lost, all encrypted settings become unrecoverable. Back up this key securely and never commit it to version control.

TIP

Only settings that contain credentials or secrets should use the encrypted type. Common examples include SMTP passwords, API secret keys, and payment provider tokens.

Admin Interface

The admin settings page organizes settings by group with appropriate input controls:

  • String -- Text input field
  • Boolean -- Toggle switch
  • Number -- Numeric input with validation
  • JSON -- Code editor with syntax highlighting
  • Encrypted -- Password input field (value is masked after saving)

Sensitive settings (where is_sensitive = true) display their values as masked dots in the admin UI. The actual value is only revealed when the administrator explicitly clicks to show it.

WARNING

Encrypted settings display as •••••••• in the admin panel. When editing, the field appears empty. Submitting an empty value for an encrypted field preserves the existing value -- it does not clear it.

Public API

The public settings endpoint returns only settings where is_public = true:

bash
GET /api/settings

Example Response

json
{
  "general": {
    "app_name": "My Application",
    "app_url": "https://example.com",
    "timezone": "UTC"
  },
  "auth": {
    "allow_registration": true,
    "password_min_length": 8
  },
  "storage": {
    "max_upload_size": 10,
    "allowed_types": ["image/jpeg", "image/png", "application/pdf"]
  }
}

TIP

Private settings (database credentials, API keys, internal configuration) are never exposed through the public API, regardless of the requesting user's role.

Backend Usage

rust
// Get a typed setting value
let app_name: String = settings_service.get("general", "app_name").await?;
let session_lifetime: i64 = settings_service.get("auth", "session_lifetime").await?;
let allow_reg: bool = settings_service.get("auth", "allow_registration").await?;

// Get an encrypted setting (automatically decrypted)
let smtp_password: String = settings_service.get("email", "email_password").await?;

// Update a setting
settings_service.set("general", "app_name", "New App Name").await?;

Released under the MIT License.