VOOZH about

URL: https://deepwiki.com/friendsofhyperf/components/1.4-component-dependencies-and-layer-architecture

⇱ Component Dependencies and Layer Architecture | friendsofhyperf/components | DeepWiki


Loading...
Last indexed: 14 February 2026 (15d5ca)
Menu

Component Dependencies and Layer Architecture

Purpose and Scope

This document describes the dependency hierarchy and layered architecture of the friendsofhyperf/components monorepo. It explains how the 50+ components are organized into layers, how they depend on each other, and their relationship with core Hyperf framework packages. This page focuses on the structural organization and dependency flow; for details on specific components, see Component Catalog, and for installation patterns, see Installation and Setup.

Architectural Layers

The friendsofhyperf/components monorepo follows a clear layered architecture where components are organized into distinct layers based on their role and dependencies. Each layer builds upon the layers beneath it, creating a stable dependency hierarchy.

Layer Overview with Code Entity Mapping


Layer Responsibilities:

LayerPurposeExamplesKey Classes/Functions
ApplicationUser code consuming component APIsControllers, services, commandsN/A (user code)
ConvenienceLaravel-style ergonomic APIsHttp::get(), cache(), dispatch()src/helpers/src/Functions.php, RequestMixin
FeatureDomain-specific functionalityHTTP client, validation, cachingPendingRequest, CacheManager, LockManager
ObservabilityCross-cutting monitoring/debuggingSentry APM, TelescopeTracer, EventHandleListener, aspects
FoundationShared utilities and patternsSupport classes, dispatch systemFriendsOfHyperf\Support\*
Hyperf CoreFramework primitivesDI container, coroutine contextContainer, Context, EventDispatcherInterface

Sources: composer.json1-333 composer.json171-221 src/helpers/composer.json22-42 </old_str>

<new_str>

Architectural Layers

The friendsofhyperf/components monorepo follows a clear layered architecture where components are organized into distinct layers based on their role and dependencies. Each layer builds upon the layers beneath it, creating a stable dependency hierarchy.

Layer Overview with Code Entity Mapping


Layer Responsibilities:

LayerPurposeExamplesKey Classes/Functions
ApplicationUser code consuming component APIsControllers, services, commandsN/A (user code)
ConvenienceLaravel-style ergonomic APIsHttp::get(), cache(), dispatch()src/helpers/src/Functions.php, RequestMixin
FeatureDomain-specific functionalityHTTP client, validation, cachingPendingRequest, CacheManager, LockManager
ObservabilityCross-cutting monitoring/debuggingSentry APM, TelescopeTracer, EventHandleListener, aspects
FoundationShared utilities and patternsSupport classes, dispatch systemFriendsOfHyperf\Support\*
Hyperf CoreFramework primitivesDI container, coroutine contextContainer, Context, EventDispatcherInterface

Sources: composer.json1-333 composer.json171-221 src/helpers/composer.json22-42

Runtime vs Development Dependencies

Components in the monorepo are categorized by their intended use case, affecting how they should be installed and whether they are required in production.

Dependency Classification


Installation Patterns:

Component TypeComposer FlagExamplePurpose
Runtime(none)composer require friendsofhyperf/sentryProduction features
Development--devcomposer require --dev friendsofhyperf/telescopeDebugging, testing
Optional(none) + suggestsSee component's suggest sectionFeature extensions

Example from README:

README.md47-55 demonstrates the pattern:


Sources: README.md34-64 composer.json44-118

Foundation Layer: friendsofhyperf/support

The friendsofhyperf/support component serves as the foundational layer for most components in the monorepo. It provides common utilities, traits, and abstractions that other components build upon.

Support Component Dependencies and Versioning


Version Constraint Pattern:

The support component uses the tilde operator (~) for version constraints:

ComponentSupport VersionMeaning
sentry~3.1.61>= 3.1.61, < 3.2.0
http-client~3.1.61>= 3.1.61, < 3.2.0
helpers~3.1.61>= 3.1.61, < 3.2.0
macros~3.1.61>= 3.1.61, < 3.2.0
facade~3.1.73>= 3.1.73, < 3.2.0

The ~ operator means "allow patch-level changes" - the rightmost digit can increment, but the minor version (3.1) is locked.

Sources: src/sentry/composer.json25 src/macros/composer.json23 src/helpers/composer.json24 src/http-client/composer.json23 src/facade/composer.json23

Support Component Provides

While the exact contents of the support component are not shown in the provided files, based on dependency patterns, it provides:

  • Common Traits: Reusable traits for component functionality
  • Base Classes: Abstract classes for common patterns
  • Utility Functions: Helper utilities used across components
  • Framework Abstractions: Wrappers around Hyperf core concepts

Feature Layer Components

Feature components provide specific functionality and can depend on:

  1. The friendsofhyperf/support foundation layer
  2. Core Hyperf framework packages
  3. Other friendsofhyperf feature components (creating sub-dependencies)

Component Interdependencies


Dependency Examples:

ComponentDirect Dependencies (friendsofhyperf)Core Hyperf Dependencies
sentrysupport ~3.1.61di, context, event, framework
helpersmacros ~3.1.0, support ~3.1.61context, macroable, stringable
http-clientsupport ~3.1.61guzzle, coroutine, macroable
facadesupport ~3.1.73di, context
lock(none)config, context, macroable

Sources: src/sentry/composer.json24-37 src/helpers/composer.json22-42 src/http-client/composer.json22-32 src/facade/composer.json22-26 src/lock/composer.json22-34

Component Registration Pattern via ConfigProvider

All components follow Hyperf's ConfigProvider pattern for automatic registration. The system uses Composer's extra section to declare configuration classes that are automatically discovered and invoked during framework bootstrap.

ConfigProvider Discovery Flow:


Root ConfigProvider Registry:

The root composer.json257-302 declares all 42 ConfigProvider classes:


Individual Component ConfigProvider:

Each component declares its own ConfigProvider for standalone installation. Example from src/sentry/composer.json60-67:


ConfigProvider Methods:

Each ConfigProvider class typically implements:

  • __invoke(): Returns configuration array
  • dependencies: DI container bindings
  • listeners: Event listener registrations
  • aspects: AOP aspect registrations
  • commands: Console command registrations
  • annotations: Annotation scanner configurations

Sources: composer.json256-303 src/sentry/composer.json60-67 src/macros/composer.json48-55 src/cache/composer.json42-47

Convenience Layer: Facades, Helpers, and Macros

The convenience layer provides Laravel-style ergonomic APIs over Hyperf's services. It consists of three interdependent components that enable fluent, expressive code without sacrificing the underlying coroutine-safe architecture.

Convenience Layer Dependency Graph with Code Entities


Dependency Chain:

  1. helpers (line src/helpers/composer.json23) depends on macros ~3.1.0
  2. helpers (line src/helpers/composer.json24) depends on support ~3.1.61
  3. macros (line src/macros/composer.json23) depends on support ~3.1.61
  4. macros (line src/macros/composer.json25) depends on hyperf/macroable ~3.1.0
  5. facade (line src/facade/composer.json23) depends on support ~3.1.73

Global Function Autoloading:

The root composer.json222-237 registers function files via Composer's files autoload mechanism:


These files are automatically loaded before any code executes, making functions like di(), app(), cache(), and dispatch() available globally.

Macro Extension Pattern:

Components like RequestMixin use Hyperf's Macroable trait to inject methods into framework classes at runtime, avoiding inheritance and maintaining coroutine safety.

Sources: composer.json222-237 src/helpers/composer.json22-42 src/macros/composer.json22-39 src/facade/composer.json22-42

Observability Components as Cross-Cutting Concerns

Observability components (Sentry and Telescope) differ from feature components in that they instrument and monitor other components via aspect-oriented programming rather than being directly consumed by application code. They have no compile-time circular dependencies but dynamically intercept method calls.

Sentry Instrumentation Architecture with Aspect Classes


Sentry Required Dependencies:

From src/sentry/composer.json24-38:


Optional Dependencies for Instrumentation:

Sentry uses suggest (lines src/sentry/composer.json39-47) to declare optional targets:

Suggested PackagePurposeAspect Class
elasticsearch/elasticsearchElasticsearch tracingElasticsearchRequestAspect
hyperf/amqpAMQP message tracingAmqpProducerAspect
hyperf/crontabCron job monitoringTracingCrontabListener
hyperf/databaseSQL query tracingDbConnectionAspect
hyperf/engineCoroutine engineCoroutineAspect
hyperf/rpc-multiplexRPC tracingRpcAspect
phpmyadmin/sql-parserSQL parsing utilitySqlParser class

SQL Parser Usage:

The src/sentry/src/Util/SqlParser.php20-65 class demonstrates conditional dependency:


This pattern allows Sentry to function without phpmyadmin/sql-parser but gain enhanced SQL parsing capabilities when it's installed.

Sources: src/sentry/composer.json24-47 src/sentry/src/Util/SqlParser.php20-65

Hyperf Framework Dependencies

All friendsofhyperf components ultimately depend on core Hyperf framework packages. The most common dependencies are:

Core Hyperf Package Usage


Dependency Frequency:

Hyperf PackageUsage Count (in sample)Purpose
hyperf/di8/12Dependency injection and aspect-oriented programming
hyperf/context10/12Coroutine-safe state management
hyperf/support9/12Base utilities and helpers
hyperf/macroable6/12Enable class extension via macros
hyperf/stringable6/12Fluent string manipulation

Sources: src/sentry/composer.json26-35 src/helpers/composer.json25-30 src/lock/composer.json23-28 src/http-client/composer.json25-32 src/facade/composer.json24-25

Version Constraints

The monorepo uses consistent version constraints across components:

Root Dependencies:

composer.json16-42 defines minimum versions:

  • "php": ">=8.1"
  • Core dependencies use flexible constraints (e.g., ^2.0 || ^3.0)

Component Dependencies:

All components require Hyperf ~3.1.0, which means:

  • Minimum version: 3.1.0
  • Maximum version: < 3.2.0
  • Allows: 3.1.0, 3.1.1, 3.1.48, etc.
  • Disallows: 3.0.x, 3.2.x, 4.x

This constraint appears consistently in src/sentry/composer.json26-33 src/lock/composer.json23-28 and other component files.

Sources: composer.json16-42 src/sentry/composer.json26-33 src/lock/composer.json23-28

PSR-4 Autoloading Organization

The monorepo uses PSR-4 autoloading with a clear namespace-to-directory mapping:


Autoloading Configuration:

From composer.json171-221:


Pattern:

  • Namespace: FriendsOfHyperf\{ComponentName}\
  • Directory: src/{component-name}/src/

Sources: composer.json171-221

Dependency Management Patterns

Replace Section for Monorepo

The root composer.json119-168 uses the replace section to define all component packages:


Purpose:

  • Allows installing friendsofhyperf/components as a single package
  • Satisfies dependencies on individual components (e.g., friendsofhyperf/sentry)
  • Enables both monorepo and split-repository installations

Optional Dependencies via Suggest Mechanism

Components use the suggest section in composer.json to declare optional dependencies that unlock additional features without being required for basic functionality. This enables progressive feature adoption and keeps the dependency footprint minimal.

Optional Dependency Pattern:


Sentry Optional Dependencies (src/sentry/composer.json39-47):


Helpers Optional Dependencies (src/helpers/composer.json32-42):


Lock Optional Dependencies (src/lock/composer.json30-34):


Facade Optional Dependencies (src/facade/composer.json27-42):


This pattern allows components to provide integrations with 12+ framework subsystems while maintaining a lean core dependency set.

Sources: src/sentry/composer.json39-47 src/helpers/composer.json32-42 src/lock/composer.json30-34 src/facade/composer.json27-42

Dependency Resolution and Installation

Full Suite Installation


When to use: Development, prototyping, comprehensive feature set

Individual Component Installation


When to use: Production, minimal footprint, specific features only

Sources: README.md34-55 composer.json119-168

Circular Dependency Prevention

The layered architecture prevents circular dependencies through strict dependency direction rules:


Rules:

  1. Application can depend on any layer below it
  2. Convenience can depend on Foundation, not other Convenience components
  3. Feature components can depend on Foundation and other Feature components
  4. Foundation depends only on Hyperf Core
  5. No upward dependencies

Exception: Observability components (Sentry, Telescope) instrument other layers via aspect-oriented programming, but this is not a compile-time dependency.

Sources: System architecture diagrams, src/helpers/composer.json22-24 src/macros/composer.json22-29

Summary

The friendsofhyperf/components monorepo implements a disciplined layered architecture:

  1. Foundation Layer (friendsofhyperf/support): Provides common utilities and abstractions
  2. Feature Layer: Domain-specific components building on foundation
  3. Convenience Layer: Facades, helpers, and macros for ergonomic APIs
  4. Observability Layer: Cross-cutting instrumentation via AOP
  5. Hyperf Core: Framework primitives underlying everything

This architecture enables:

  • Clear dependency flow: No circular dependencies
  • Flexible installation: Monorepo or individual components
  • Version alignment: Consistent ~3.1.0 constraint
  • Auto-registration: ConfigProvider pattern throughout
  • Coroutine safety: hyperf/context used extensively

Sources: composer.json1-330 System architecture diagrams

Refresh this wiki

On this page