Skip to content

General — Settings & Platform Services

Overview

The General sub-module covers all platform-wide services that manage configuration, audit trails, approvals, assets, contacts, and master data. These are the foundational services that every domain module depends on.

What's Covered

ServiceDescription
Settings ManagementKey-value configuration with Redis caching and type casting
Activity LoggingAutomatic audit trail via the HasLog trait
Approval WorkflowPolymorphic approval system for any model
Asset ManagementFile/media storage with local disk and ImageKit cloud
Contact StorageEncrypted contact information with censorship support
Master DataGenders, Ethnicities, Religions, Localizations

Settings Management

Concept

The Setting model provides a centralized, cached key-value store. Every setting is identified by a triple of (module, group, key). Values are automatically type-cast when read and cached in Redis for 60 minutes.

Key methods:

  • Setting::get('module', 'group', 'key', $default) — Read with caching
  • Setting::updateOrCreate(...) — Write with automatic cache invalidation

Flowchart — Setting Read/Write Flow

The following flowchart illustrates how settings are read, cached, and written:

Explanation:

  1. On read, the system first checks Redis cache. If found, the cached value (with proper type casting) is returned immediately.
  2. On cache miss, the settings table is queried. The raw value is cast according to its type column.
  3. The cast value is cached in Redis for 60 minutes, then returned.
  4. On write, all cached setting keys are invalidated to ensure consistency.

Activity Logging

The HasLog trait automatically records all creates, updates, and deletes for any model. It uses Eloquent event listeners and stores entries in the activity_logs table via a polymorphic relationship.

Explanation:

  1. The trait registers Eloquent event listeners for created, updated, and deleted.
  2. On update, timestamp fields (updated_at) are excluded. Only meaningful changes are logged.
  3. The log includes the acting user, action type, description, old/new values, IP address, and user agent.

Approval Workflow

The Approval model provides a polymorphic approval system. Any model can have approvers defined by role name or specific user. The system supports configurable minimum approval counts.

Approver resolution:

  • Role-based: Resolves all users with a given Spatie Role name
  • User-based: Directly assigned to a specific user

Data Flow Diagram — Level 0 System Context

Activity Diagram — Setting Management Lifecycle


Database

Key Tables

TablePurposeUnique Constraint
settingsKey-value config store(module, group, key)
activity_logsAudit trail— (polymorphic)
approvalsWorkflow approvals— (polymorphic)
assetsFile/media storage
contactsEncrypted contacts(type, censored)

Key Files

app/Models/Platform/
├── Setting/Setting.php              # Cached key-value store
├── ActivityLog/ActivityLog.php       # Polymorphic audit trail
├── Approval/Approval.php             # Workflow approval system
├── Asset/Asset.php                   # File/media abstraction
├── Contact/Contact.php               # Encrypted contacts
├── Gender/Gender.php                 # Gender master data
├── Ethnicity/Ethnicity.php           # Ethnicity master data
├── Religion/Religion.php             # Religion master data
└── Localization/Localization.php     # Locale master data

app/Traits/Common/
├── HasLog.php                        # Auto-logging on events
├── HasAsset.php                      # Asset relationship
└── HasContact.php                    # Contact relationship

app/Filament/Clusters/SystemSettings/
└── Pages/
    ├── ManageGeneralSettings.php     # General system settings
    └── ManageMailSettings.php        # Mail configuration

database/migrations/v1_0_0/
└── 001_migrate_platform.php          # All platform tables