Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Contracts Laravel Package

dragon-code/contracts

Dragon Code Contracts provides a lightweight set of PHP interfaces (contracts) you can reuse across any project to standardize key behaviors, improve type-safety, and keep implementations decoupled. Ideal as a shared dependency for packages and applications.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Contracts: Perfectly aligned with Laravel’s core abstractions (caching, queues, HTTP, DTOs), reducing friction for teams already using the framework. Contracts like Cache\Store, Queue\ShouldQueue, and Dtoable mirror Laravel’s built-in patterns, enabling zero-boilerplate adoption for common use cases.
  • Clean Architecture Enabler: Supports hexagonal/port-adapter architecture by providing explicit interfaces for domain interactions (e.g., Cache\Ttl, Http\Builder). This allows teams to decouple business logic from infrastructure, simplifying future migrations (e.g., switching cache drivers or HTTP clients).
  • Symfony Compatibility: Leverages Symfony 6/7 components (e.g., symfony/http-kernel), ensuring interoperability with modern PHP ecosystems while maintaining Laravel-specific extensions (e.g., rememberForever for caching).
  • Domain-Driven Design (DDD) Support: Contracts like ActionInterface and ShouldBeUnique align with DDD principles, enabling bounded context isolation and event-driven workflows without framework lock-in.
  • Modular Monolith Refactoring: Provides a contract-first foundation for decomposing monolithic Laravel apps into independently testable modules, with interfaces like MigrateDatabase facilitating database-agnostic migrations.

Integration Feasibility

  • Minimal Friction: Contracts are pure PHP interfaces with no runtime dependencies beyond Laravel/Symfony, requiring only type hints in existing classes (e.g., class MyDto implements Dtoable).
  • Backward Compatibility: Designed for Laravel 11/12, but most contracts (e.g., Cache\Store) are backward-compatible with older versions, reducing migration risks.
  • IDE-First Adoption: Full PHPStan/PSR-12 support ensures compile-time safety, with IDE autocompletion for contracts (e.g., ShouldQueue::getQueue()).
  • Laravel Service Provider Agnostic: Contracts do not replace Laravel’s built-in interfaces (e.g., Illuminate\Contracts\Cache\Store) but extend them, avoiding conflicts with existing implementations.

Technical Risk

Risk Area Assessment Mitigation Strategy
Breaking Changes Minor updates (e.g., Symfony 7.0 bump in v2.22.0) may require dependency updates, but major versions follow semver. Lock to a stable minor version (e.g., ^2.25) and monitor Laravel/Symfony compatibility.
Overhead for Small Projects Contracts add minimal value for projects with <5K LoC or no modularity goals. Opt-in adoption: Start with high-impact contracts (e.g., Dtoable, ShouldQueue) and expand as needed.
Laravel Version Lock-In Contracts are Laravel-centric (e.g., rememberForever for cache). Use adapter patterns to abstract Laravel-specific logic if portability is critical.
Testing Complexity Interfaces like Cache\Store may increase mocking effort in unit tests. Leverage Laravel’s built-in mocking tools (e.g., Mockery) or DragonCode’s testing utilities (if part of the ecosystem).
Ecosystem Dependency Some contracts (e.g., Dtoable) assume DragonCode/helpers for full functionality. Document optional dependencies and provide fallback implementations for standalone use.
Performance Impact Zero runtime overhead, but compile-time checks may slow development environments. Exclude contracts from production builds (if using PHP 8.2+) or use opcache to mitigate.

Key Questions for TPM

  1. Architecture Goals:

    • Are we prioritizing clean architecture, DDD, or modularity? If yes, this package provides foundational contracts for those patterns.
    • Do we need framework-agnostic interfaces (e.g., for future non-Laravel components), or is Laravel-specific alignment sufficient?
  2. Team Maturity:

    • Is the team comfortable with dependency inversion (interfaces over implementations)? If not, adoption may require training or gradual migration.
    • How do we balance standardization (using this package) vs. custom contracts for domain-specific needs?
  3. Ecosystem Integration:

    • Are we using or planning to use DragonCode/helpers? If yes, contracts like Dtoable are required for full functionality.
    • Do we need additional contracts not covered by this package (e.g., for payment processing, real-time features)?
  4. Migration Strategy:

    • Should we retrofit contracts to existing classes (e.g., implements Dtoable) or start fresh in new modules?
    • How will we handle legacy code that doesn’t adhere to the new contracts?
  5. Long-Term Maintenance:

    • Who will monitor updates (e.g., Laravel 13 compatibility) and adapt contracts if needed?
    • Should we fork the package to customize contracts for our needs, or contribute upstream?
  6. Testing Impact:

    • Will this increase or decrease test coverage? (Interfaces enable mocking but may require refactoring.)
    • How will we test contract implementations (e.g., ensuring ShouldQueue jobs behave as expected)?
  7. Performance & Scaling:

    • Are there bottlenecks in our current caching/queue/HTTP layers that this package could expose or solve?
    • Will adopting contracts simplify scaling (e.g., by enabling easier driver swaps)?

Integration Approach

Stack Fit

  • Laravel 11/12: Native support with zero configuration. Contracts like ShouldQueue and Cache\Store align with Laravel’s latest patterns.
  • Symfony 6/7: Leverages Symfony components (e.g., HttpKernel) for HTTP and kernel-related contracts, ensuring compatibility with Symfony-based Laravel extensions.
  • PHP 8.3+: Requires named arguments, enums, and attributes, which modern Laravel projects already use.
  • DragonCode Ecosystem: Seamless integration with dragon-code/helpers (e.g., Dtoable for serialization) if adopted.
  • Other Frameworks: Limited compatibility—contracts are Laravel-centric (e.g., rememberForever for cache). Use adapter patterns for non-Laravel PHP projects.

Migration Path

Phase Action Items Dependencies Risks
Assessment Audit existing code for caching, queues, DTOs, and HTTP clients to identify high-impact areas for contract adoption. None Underestimating refactoring effort for legacy code.
Pilot Project Select a new module or feature (e.g., a microservice) to fully adopt contracts (e.g., Dtoable for API responses, ShouldQueue for jobs). Composer, PHP 8.3+, Laravel 11/12 Scope creep if pilot becomes too broad.
Core Contracts Implement critical contracts in shared libraries first:
- Dtoable for API/DTO layers dragon-code/helpers (optional) Breaking changes if DTOs are tightly coupled to existing logic.
- Cache\Store and Queue\ShouldQueue for background jobs and caching Laravel Cache/Queue systems Performance regression if contracts introduce overhead.
- Http\Builder for HTTP clients Symfony HttpKernel or Laravel HTTP client Incompatibility with custom HTTP implementations.
Gradual Rollout Retrofit contracts to existing classes in phases:
1. DTOs: Convert data transfer objects to implements Dtoable. Serialization issues if dragon-code/helpers is missing.
2. Jobs: Add ShouldQueue/ShouldBeUnique to queueable classes. Laravel Queue system Job deduplication conflicts if ShouldBeUnique is misapplied.
3. Cache: Replace custom cache interfaces with Cache\Store. Laravel Cache
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium