VOOZH about

URL: https://deepwiki.com/hypervel/support/3.1-architecture-overview

⇱ Architecture Overview | hypervel/support | DeepWiki


Loading...
Menu

Architecture Overview

This document provides a high-level overview of the hypervel/support package architecture, explaining how its foundational components work together to provide a clean, extensible API surface. The architecture follows a layered design pattern with four core infrastructure patterns: Facades, Service Providers, Managers, and Data Objects.

For detailed information about specific patterns, see:

Layered Architecture

The package follows a clear separation of concerns across multiple layers, each with distinct responsibilities.


Layer Responsibilities

LayerPurposeKey Components
Package DefinitionDefines dependencies and autoloading configurationcomposer.json1-50 src/helpers.php
Core InfrastructureProvides foundational patterns for building servicesDataObject, Manager, Facade, ServiceProvider
Facade APIStatic API surface for application code20+ facade classes in src/Facades/
ImplementationConcrete service implementationsManagers, contracts, and service classes
Backend ServicesExternal systems and storageDatabases, cache servers, message queues

Sources: composer.json1-50 src/Facades/Facade.php1-264 src/DataObject.php1-589 src/Manager.php1-157

Core Infrastructure Patterns

The package is built on four foundational patterns that work together to provide extensibility, clean APIs, and type safety.

Pattern Interaction Map


Sources: src/Facades/Facade.php1-264 src/Manager.php1-157 src/DataObject.php1-589 src/Reflector.php1-136

Facade Pattern

The Facade abstract class provides a static proxy to services in the dependency injection container. Each facade implements getFacadeAccessor() to specify which container binding it proxies.

Key Implementation Details:

Example Facade Resolution Flow:


Sources: src/Facades/Facade.php144-153 src/Facades/Facade.php169-192 src/Facades/Facade.php177-192

Manager Pattern

The Manager abstract class implements the driver pattern for multi-backend services. It provides lazy instantiation, driver caching, and extensibility through custom creators.

Architecture:

Driver Resolution Logic:

StepMethodDescription
1Check cachesrc/Manager.php56 - Return cached driver if exists
2Check custom creatorsrc/Manager.php73-75 - Call registered closure if exists
3Check factory methodsrc/Manager.php77-81 - Call create{StudlyDriver}Driver()
4Throw exceptionsrc/Manager.php83 - Driver not supported

Sources: src/Manager.php1-157

DataObject Pattern

The DataObject abstract class provides strongly-typed DTOs with automatic type casting, dependency resolution, and serialization. It uses reflection to map constructor parameters to data keys.

Core Features:


Type Conversion System:

The auto-casting system handles multiple scenarios:

TypeHandlerLocation
Primitive typesconvertValueToType()src/DataObject.php411-432
Nested DataObjectsresolveDependenciesMap()src/DataObject.php254-313
DateTime typesgetCustomizedDependencies()src/DataObject.php109-118
Enum typesDirect from() callsrc/DataObject.php292-299

Property Mapping:

Serialization:

Sources: src/DataObject.php1-589

Dependency Flow

The following diagram shows how application code interacts with the architecture to perform a typical operation.


Sources: src/Facades/Facade.php144-153 src/DataObject.php62-93

Package Definition and Autoloading

The package is defined through Composer configuration and depends on Hyperf 3.1.x ecosystem packages.

Dependencies:

DependencyVersionPurpose
hyperf/context~3.1.0Application context management
hyperf/support~3.1.0Base support utilities
hyperf/collection~3.1.0Collection data structure
nesbot/carbon^2.72.6DateTime manipulation
league/uri^7.5URI manipulation

Autoloading Configuration:

Sources: composer.json1-50

Helper Function Integration

The package provides ~40 global helper functions that complement the facade layer for common operations. These are auto-loaded via Composer's files directive.

Helper Categories:

  • Data Access: data_get(), data_set(), data_fill(), data_forget()
  • Collections: collect(), value()
  • Control Flow: retry(), tap(), once(), transform()
  • Strings: e(), blank(), filled(), class_basename()
  • Environment: env(), environment()

These helpers provide procedural alternatives to facade calls for brevity in application code.

Sources: composer.json36-39

Reflection Utilities

The Reflector class provides utilities for inspecting callables and parameter types, used extensively by the DataObject system.

Key Methods:

The Reflector is particularly important for the DataObject's dependency resolution system src/DataObject.php254-313

Sources: src/Reflector.php1-136

Testing Infrastructure Integration

The architecture includes first-class testing support through the facade system. Facades can be swapped with test doubles without modifying application code.

Testing Methods:

MethodLocationPurpose
spy()src/Facades/Facade.php42-53Create Mockery spy
partialMock()src/Facades/Facade.php58-67Partial mock with real methods
shouldReceive()src/Facades/Facade.php72-81Set Mockery expectations
swap()src/Facades/Facade.php131-136Replace with custom instance
isFake()src/Facades/Facade.php158-164Check if fake installed

This enables isolated unit testing by intercepting facade calls at the container level. For details on specific testing patterns, see Testing Overview.

Sources: src/Facades/Facade.php42-136

Summary

The hypervel/support package architecture provides:

  1. Clean API Surface - Facades offer static access without sacrificing testability
  2. Extensibility - Manager pattern enables custom drivers; ServiceProviders enable custom bindings
  3. Type Safety - DataObject pattern provides strongly-typed DTOs with automatic casting
  4. Testability - Swap mechanism allows isolated testing with fakes and mocks
  5. Convention over Configuration - Naming conventions reduce boilerplate (driver methods, property mapping)

These patterns work together through the PSR-11 container to provide a cohesive foundation for building Hyperf applications with Laravel-like ergonomics.