VOOZH about

URL: https://deepwiki.com/hypervel/foundation/1-introduction-to-hypervel-foundation

⇱ hypervel/foundation | DeepWiki


Loading...
Last indexed: 7 February 2026 (101eff)
Menu

Introduction to Hypervel Foundation

Purpose and Scope

This document provides a high-level overview of the Hypervel Foundation package, its role as a Laravel-inspired framework built on top of Hyperf, and its core architectural patterns. This introduction covers the framework's design philosophy, primary components, and how they work together to provide a familiar development experience for Laravel developers while leveraging Hyperf's high-performance async capabilities.

For detailed information about specific subsystems, see:

Sources: composer.json1-77 src/Application.php1-35

What is Hypervel Foundation?

Hypervel Foundation is the core package of the Hypervel framework, providing a Laravel-like development experience on top of Hyperf's high-performance async runtime. The package version is currently 0.3.18 as defined in src/Application.php34

The Foundation package serves as the central orchestration layer that:

  • Extends Hyperf's DI Container - The Hypervel\Foundation\Application class extends Hypervel\Container\Container src/Application.php25 which itself extends Hyperf's container with additional Laravel-compatible features
  • Implements Service Container Pattern - Manages service registration, dependency injection, and application lifecycle through the Hypervel\Foundation\Contracts\Application interface src/Contracts/Application.php13
  • Provides Dual-Kernel Architecture - Separate HTTP and Console kernels handle web requests and CLI commands respectively
  • Establishes Laravel-Compatible APIs - Offers familiar methods like basePath(), configPath(), environment(), and isLocal() for developers migrating from Laravel

Sources: src/Application.php25-90 src/Contracts/Application.php1-207 composer.json2-10

Core Components Architecture

The following diagram maps the framework's natural language concepts to their concrete implementations in code:

Component Architecture Diagram


Key Implementation Details:

ComponentClass/FilePrimary Responsibility
Application ContainerHypervel\Foundation\ApplicationCentral DI container and service orchestrator
Application ContractHypervel\Foundation\Contracts\ApplicationInterface defining application capabilities
Config ProviderHypervel\Foundation\ConfigProviderHyperf integration point for package registration
Foundation Service ProviderFoundationServiceProviderRegisters core framework services
Global Helperssrc/helpers.phpProvides static facade functions like app(), config()
HTTP KernelHypervel\Foundation\Http\KernelProcesses incoming HTTP requests
Console KernelHypervel\Foundation\Console\KernelHandles CLI command execution

Sources: src/Application.php25-90 src/Contracts/Application.php13-207 src/ConfigProvider.php18-47 composer.json52-67

Dual-Kernel Architecture

Hypervel Foundation implements a dual-kernel pattern, separating concerns between HTTP and console environments:

Kernel Responsibility Matrix

AspectHTTP KernelConsole Kernel
Entry PointSwoole HTTP Server requestArtisan CLI command
Primary MethodonRequest()Command handler methods
MiddlewareGlobal, route, group middlewareCommand-specific middleware
Response TypeHTTP responses (JSON/HTML)Console output
ContextPer-request coroutine contextSingle process execution
Event DispatchingRequest lifecycle eventsCommand lifecycle events

Both kernels share:

  • Access to the Application container for dependency injection
  • Common exception handling through Hypervel\Foundation\Exceptions\Handler
  • Event dispatcher for lifecycle hooks
  • Configuration system

Sources: src/ConfigProvider.php24-26 High-level diagrams (Diagram 1 & 3)

Application Lifecycle

The application follows a structured initialization and request handling lifecycle:

Application Bootstrap Flow


Key Lifecycle Methods:

MethodLocationPurpose
__construct()src/Application.php82-90Initialize container and base bindings
setBasePath()src/Application.php160-165Configure application root directory
bootstrapWith()src/Application.php118-129Execute bootstrap classes in sequence
register()src/Application.php311-345Register service provider with container
boot()src/Application.php398-416Boot all registered service providers
booting()src/Application.php435-438Register callback before boot
booted()src/Application.php443-450Register callback after boot

Sources: src/Application.php82-450 src/Contracts/Application.php20-154

Integration with Hyperf

Hypervel Foundation integrates deeply with Hyperf while maintaining Laravel-like conventions:

Hyperf Integration Points


Configuration Provider Structure:

The ConfigProvider class at src/ConfigProvider.php18-47 returns an array with these keys:


Package Metadata in composer.json:

The composer.json60-72 file defines two integration points:

  1. Hyperf Integration (extra.hyperf.config): Tells Hyperf to load ConfigProvider
  2. Hypervel Integration (extra.hypervel.providers): Declares FoundationServiceProvider for automatic registration

Sources: src/ConfigProvider.php18-47 composer.json60-72

Key Design Patterns

Service Provider Pattern

Service providers are the primary mechanism for registering services. The Application tracks providers in:

The register() method src/Application.php311-345 handles provider registration with automatic binding of the bindings property.

Facade Pattern via Global Helpers

The src/helpers.php file (loaded via composer.json57-58) provides global functions that delegate to the Application container, implementing the facade pattern. These functions provide static-like access to framework services.

Container Alias System

The Application registers 40+ container aliases in registerCoreContainerAliases() src/Application.php546-664 allowing services to be resolved by multiple identifiers:


This enables flexible service resolution where app('config'), app(ConfigInterface::class), and $container->get('config') all resolve to the same instance.

Path Resolution System

The Application provides dedicated path helper methods for framework directories:

MethodDefault LocationConfiguration Override
basePath()Root directorySet via constructor
path()app/Not configurable
configPath()config/Not configurable
databasePath()database/Not configurable
langPath()lang/Not configurable
publicPath()public/Not configurable
resourcePath()resources/Not configurable
viewPath()resources/views/Via view.config.view_path config
storagePath()storage/Not configurable

All path methods support optional sub-path arguments: app()->configPath('app.php') returns config/app.php.

Sources: src/Application.php170-252 src/Contracts/Application.php40-87

Framework Dependencies

Hyperf Components

The Foundation package depends on multiple Hyperf 3.1.x components:

ComponentPurpose
hyperf/diDependency injection container
hyperf/configConfiguration management
hyperf/commandConsole command infrastructure
hyperf/http-serverHTTP server and routing
hyperf/databaseDatabase query builder and ORM
hyperf/frameworkCore framework utilities
symfony/error-handlerEnhanced error handling

Hypervel Packages

Foundation depends on other Hypervel packages for specific functionality:

PackagePurpose
hypervel/coreCore utilities and interfaces
hypervel/filesystemFile and storage operations
hypervel/supportHelper classes and service providers
hypervel/httpHTTP request/response abstractions
hypervel/validationInput validation system

Sources: composer.json22-48

Environment Detection

The Application delegates environment detection to the Hypervel\Support\Environment service:

MethodLocationPurpose
environment()src/Application.php259-266Get or check environment name
detectEnvironment()src/Application.php287-290Detect current environment
isLocal()src/Application.php271-274Check if local environment
isProduction()src/Application.php279-282Check if production environment
runningUnitTests()src/Application.php295-298Check if testing environment
hasDebugModeEnabled()src/Application.php303-306Check if debug mode enabled

These methods provide Laravel-compatible APIs for environment-based logic.

Sources: src/Application.php259-306 src/Contracts/Application.php90-119

Locale Management

The Application provides internationalization support through translator integration:

MethodPurpose
getLocale() / currentLocale()Retrieve current locale from translator
getFallbackLocale()Get fallback locale
setLocale()Set locale and dispatch LocaleUpdated event
isLocale()Check if current locale matches

When setLocale() is called src/Application.php536-541 it:

  1. Updates the translator service
  2. Dispatches Hypervel\Foundation\Events\LocaleUpdated event src/Events/LocaleUpdated.php7-15

Sources: src/Application.php504-541 src/Events/LocaleUpdated.php7-15 src/Contracts/Application.php177-199

Built-in Commands

Foundation provides essential CLI commands registered through ConfigProvider:

CommandClassPurpose
server:reloadServerReloadCommandGracefully reload Swoole workers
aboutAboutCommandDisplay framework information
config:showConfigShowCommandShow configuration values
vendor:publishVendorPublishCommandPublish package assets

The server:reload command src/Console/Commands/ServerReloadCommand.php14-71 sends SIGUSR1 and SIGUSR2 signals to reload workers and task workers respectively.

Sources: src/ConfigProvider.php31-36 src/Console/Commands/ServerReloadCommand.php14-71

Application Version

The framework version is defined as a class constant:


Accessible via Application::VERSION or the version() method src/Application.php100-103

Sources: src/Application.php34-103

Next Steps

For deeper understanding of specific subsystems: