VOOZH about

URL: https://deepwiki.com/mathsgod/light/2.1-system-components

⇱ System Components | mathsgod/light | DeepWiki


Loading...
Last indexed: 31 January 2026 (cf9511)
Menu

System Components

Purpose and Scope

This document catalogs the major system components of the Light framework and their structural relationships. It provides a component-level view of the architecture, identifying key classes, their responsibilities, and how they fit together. For detailed information about specific subsystems:


Component Architecture Overview

The Light framework is organized into six primary component layers, each encapsulating distinct system responsibilities. The following diagram maps these layers to their concrete implementations in the codebase.

System Layer Mapping


Sources: src/App.php1-941 src/Type/App.php1-544 src/Auth/Service.php1-141 src/Model/User.php1-390


Core Application Kernel

The Light\App class serves as the central orchestrator with an importance score of 149.50, making it the most critical component in the system. It implements both MiddlewareInterface and RequestHandlerInterface for PSR-15 compatibility.

Responsibilities

ResponsibilityImplementationLines
Container initializationLeague\Container instantiationsrc/App.php68
GraphQL schema factory setupSchemaFactory configurationsrc/App.php121-126
RBAC system loadingRole/permission hierarchy constructionsrc/App.php306-366
Filesystem mountingMountManager configurationsrc/App.php134-146
Request processingMiddleware pipeline executionsrc/App.php500-537
Authentication service injectionAuth\Service instantiationsrc/App.php526-534

Component Registration

The constructor registers all core controllers and services into the dependency injection container:


Sources: src/App.php59-147


GraphQL API Layer

The GraphQL layer uses GraphQLite for annotation-based schema generation. The system exposes two primary entry points: Light\Type\App (importance: 75.46) for queries and various controller classes for mutations.

GraphQL Entry Points


Schema Factory Configuration

The schema factory is configured in the App constructor with namespace scanning and custom type mappers:

ConfigurationPurposeLocation
addNamespace("Light")Scan Light namespace for typessrc/App.php125
addTypeMapperFactory()Bridge Light\Db models to GraphQLsrc/App.php126
setAuthenticationService()Inject auth service for @Loggedsrc/App.php529
setAuthorizationService()Inject auth service for @Rightsrc/App.php530

Sources: src/App.php121-126 src/Type/App.php1-544


Authentication & Authorization Components

The security layer implements a multi-component architecture combining stateless JWT authentication with stateful RBAC authorization.

Security Component Interaction


Component Responsibilities

Auth\Service (src/Auth/Service.php):

  • JWT token extraction from cookies or Authorization header lines 38-43
  • Token validation and expiration checking lines 50-80
  • User context injection into GraphQL resolvers lines 107-113
  • Permission checking via isAllowed() lines 122-139
  • Session revocation detection via cache line 58

Light\Rbac (loaded in src/App.php):

Light\Model\User (src/Model/User.php):

Sources: src/Auth/Service.php1-141 src/App.php306-366 src/Model/User.php1-390


Data Persistence Layer

The data layer provides ORM functionality with automatic audit trails and revision tracking.

Data Layer Component Stack


Core Model Functionality

FeatureImplementationPurpose
Automatic timestampssave() hookSets created_time, updated_time
User trackingsave() hookSets created_by, updated_by from DI container
Audit loggingdelete() hookRecords deletion to EventLog
Revision trackingEventLog integrationStores source/target state snapshots
Query filteringQuery::filters()Declarative filter syntax
Query sortingQuery::sort()String-based sort specification

Database Access Pattern:

The App class provides database access via getDatabase() line 223 which calls Light\Db\Adapter::Create() to instantiate a connection based on environment variables (DATABASE_*).

Sources: src/App.php223-226 src/Model/User.php48


File Storage System

The file storage system uses Flysystem to provide cloud-agnostic file operations across multiple backends.

Storage Architecture


Filesystem Configuration Loading

The App::getFSConfig() method lines 695-714 loads filesystem configurations from the database:

  1. Queries Config model for key "fs" line 697
  2. Parses JSON array of filesystem definitions line 701
  3. Provides default local filesystem if none configured lines 704-712

Each filesystem definition contains:

  • name: Mount identifier (e.g., "local", "s3")
  • type: Backend type ("local", "s3", "aliyun-oss", "hostlink")
  • data: Backend-specific configuration (credentials, endpoints)

MountManager Setup

The constructor initializes the MountManager lines 134-146:


This enables location-based routing: "s3://path/to/file" routes to the S3 adapter, "local://path" routes to local storage.

Sources: src/App.php134-146 src/App.php695-787


Configuration & Infrastructure

Configuration is sourced from multiple locations, each serving different lifecycle stages.

Configuration Sources


Configuration Access Patterns

Environment Variables (.env file):

  • Accessed via $_ENV superglobal
  • Database credentials: DATABASE_HOST, DATABASE_USERNAME, etc.
  • JWT secret: $_ENV["JWT_SECRET"] src/App.php647
  • Cookie settings: $_ENV["COOKIE_DOMAIN"], $_ENV["COOKIE_SECURE"], etc. lines 616-627

Database Configuration (Config model):

  • Static accessor: Config::Value($key, $default) src/App.php107
  • Dynamic updates via GraphQL mutations
  • Examples: mode, access_token_expire, two_factor_authentication

YAML Files:

  • permissions.yml: Parsed at line 338, maps roles to permissions
  • menus.yml: Parsed at line 176, defines navigation structure
  • Version controlled, deployed with code

Sources: src/App.php107-119 src/App.php233-285 src/App.php338 src/App.php176 src/Type/App.php199-261


Component Dependency Graph

This diagram shows the concrete dependency relationships between major components, using actual class names and method calls from the codebase.


Key Dependency Patterns

  1. Central Hub Pattern: App aggregates all major subsystems and provides them to other components
  2. Factory Pattern: getDrive(), getFS(), getMailer() methods create configured instances on demand
  3. Service Locator: Container stores singletons, accessed by type hint in constructors
  4. Decorator Pattern: Auth\Service wraps authentication state, injected into GraphQL context
  5. Strategy Pattern: Multiple filesystem adapters implement common interface, selected by configuration

Sources: src/App.php59-147 src/App.php500-537 src/Auth/Service.php28-80


Summary Table: Component Catalog

ComponentLocationImportancePrimary Responsibility
Light\Appsrc/App.php149.50Application kernel, request orchestration
Light\Type\Appsrc/Type/App.php75.46GraphQL root query type
Light\Model\Usersrc/Model/User.php52.61User identity and permissions
Light\RbacLoaded in src/App.php12849.97Role-based access control
Light\ModelBase class49.55ORM base with audit hooks
Light\Db\Adaptersrc/App.php225N/ADatabase connection factory
Auth\Servicesrc/Auth/Service.php26.88JWT validation and user context
Controller\FileSystemControllerRegistered src/App.php9340.67File operation mutations
Controller\AuthControllerRegistered src/App.php7769.18Authentication mutations
SchemaFactorysrc/App.php124N/AGraphQL schema generation
MountManagersrc/App.php144N/AMulti-backend filesystem routing
Light\Model\ConfigDatabase table30.74Runtime configuration storage

Sources: src/App.php1-941 src/Type/App.php1-544 src/Auth/Service.php1-141 src/Model/User.php1-390