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

  • Strong alignment with Laravel’s ecosystem: Contracts are tailored for Laravel 11/12, Symfony 6/7, and PHP 8.3+, ensuring seamless integration with modern Laravel applications.
  • Clean Architecture & Dependency Inversion: Enables strict separation of concerns by defining interfaces for core systems (e.g., Cache\Store, Queue\ShouldQueue), making implementations swappable and testable.
  • Modularity & Reusability: Ideal for modular monoliths or microservices where shared contracts reduce coupling between components.
  • Framework-Agnostic Abstractions: While Laravel-specific, the contracts (e.g., Dtoable, Http\Builder) are generic enough to work across PHP projects using similar patterns.

Integration Feasibility

  • Low-Coupling Design: Contracts are pure interfaces with no runtime dependencies beyond PHP, making them non-intrusive to existing codebases.
  • Composer-First Adoption: Simple installation (composer require dragon-code/contracts) with zero configuration required.
  • Backward Compatibility: MIT-licensed with no breaking changes in major versions (e.g., Laravel 11/12 support added incrementally).
  • Symfony Dependency: Uses symfony/http-kernel (v6/7/8), which is already a Laravel dependency, reducing friction.

Technical Risk

Risk Mitigation Severity
Overhead for Small Projects Contracts add zero runtime cost; only useful if leveraging DDD/clean architecture. Low
Laravel Version Lock-in Actively supports Laravel 11/12; minor updates may require version alignment. Medium
Limited Adoption (0 Dependents) No proven ecosystem, but DragonCode’s other packages (e.g., helpers) rely on these contracts. Medium
Symfony Dependency Bloat symfony/http-kernel is already in Laravel; no additional bloat. Low
Breaking Changes in Minor Updates Follows semver; minor updates (e.g., 2.x.x) may add methods but won’t break existing code. Low

Key Questions for TPM

  1. Architecture Goals:

    • Is the team adopting clean architecture, DDD, or hexagonal design? If not, the value of contracts may be limited.
    • Are we building reusable internal packages or modular services? If yes, contracts accelerate development.
  2. Laravel Version Strategy:

    • What’s the target Laravel version (11/12)? Ensure alignment with the package’s support matrix.
    • Is the team using Symfony 6/7/8 elsewhere? This package’s Symfony dependency may introduce consistency.
  3. Adoption Scope:

    • Should we mandate contracts for all new components or adopt opt-in?
    • How will we enforce contract usage (e.g., static analysis, CI checks)?
  4. Ecosystem Integration:

    • Are we using DragonCode’s other packages (e.g., helpers)? If yes, contracts like Dtoable are required.
    • Will this enable shared contracts across microservices or internal libraries?
  5. Testing & Mocking:

    • How will contracts improve testability? (e.g., mocking Cache\Store instead of concrete implementations.)
    • Should we refactor existing tests to leverage these interfaces?
  6. Performance Impact:

    • Are there performance concerns with interface-based dispatch? (None; contracts are compile-time only.)
  7. Long-Term Maintenance:

    • Who will monitor updates (e.g., Laravel 13 compatibility)?
    • Should we fork the package if DragonCode abandons it?

Integration Approach

Stack Fit

Component Fit Notes
Laravel 11/12 Excellent (explicit support in v2.24.0+) No compatibility issues; follows Laravel’s evolution.
Symfony 6/7/8 Good (dependency via symfony/http-kernel) Already present in Laravel; minimal overhead.
PHP 8.3+ Required (no backward compatibility for older PHP) Ensure CI/CD and local environments meet this requirement.
Clean Architecture Ideal (enforces dependency inversion) Critical for DDD, hexagonal, or onion architecture.
Modular Monoliths Strong (shared contracts between modules) Reduces coupling between independently deployable components.
Microservices Good (if using shared contracts for inter-service communication) Requires standardized contract adoption across services.
Legacy Laravel Poor (<11 not supported) Avoid for projects stuck on Laravel 10 or older.

Migration Path

  1. Assessment Phase:

    • Audit existing custom interfaces (e.g., for caching, queues, DTOs).
    • Identify high-value candidates for replacement (e.g., ShouldQueue, Dtoable).
  2. Pilot Integration:

    • Start with one module/service (e.g., a new feature or internal package).
    • Replace 2-3 custom interfaces with DragonCode’s contracts (e.g., Cache\Store instead of App\Contracts\CacheInterface).
  3. Incremental Adoption:

    • Phase 1: Replace DTO-related interfaces (e.g., Dtoable for serialization).
    • Phase 2: Standardize queue/job contracts (ShouldQueue, ShouldBeUnique).
    • Phase 3: Adopt HTTP/caching contracts (Http\Builder, Cache\Ttl).
  4. Enforcement:

    • Add PHPStan/PSR-12 checks to enforce contract usage in new classes.
    • Update CI/CD pipelines to fail on missing contract implementations.
  5. Deprecation:

    • Gradually deprecate custom interfaces in favor of DragonCode’s.
    • Use abstract base classes to bridge old and new contracts during transition.

Compatibility

Scenario Compatibility Workaround
Laravel 10 or older ❌ No support Stick to custom interfaces or upgrade Laravel.
Symfony 5.x ⚠️ Partial May require dependency overrides (not recommended).
PHP <8.3 ❌ No support Upgrade PHP or avoid this package.
Non-Laravel PHP projects ✅ Possible Use only generic contracts (e.g., Dtoable, Cache\Store).
Existing custom implementations ✅ Replaceable Implement DragonCode’s interfaces alongside old ones, then migrate.

Sequencing

  1. Pre-requisites:

    • Upgrade to Laravel 11/12 and PHP 8.3+.
    • Ensure Symfony 6/7/8 compatibility in the stack.
  2. Critical Path:

    • Step 1: Install dragon-code/contracts in the root project and key packages.
    • Step 2: Replace DTO interfaces first (lowest risk, high reward).
    • Step 3: Standardize queue/job contracts (ShouldQueue, ShouldBeUnique).
    • Step 4: Adopt caching/HTTP contracts (Cache\Store, Http\Builder).
  3. Parallel Work:

    • Refactor tests to use contract interfaces for mocking.
    • Update documentation to reflect new contract usage.
  4. Post-Integration:

    • Monitor performance impact (none expected; contracts are compile-time).
    • Evaluate developer feedback on usability (e.g., IDE autocompletion, clarity).

Operational Impact

Maintenance

Aspect Impact Mitigation
Dependency Updates Minor updates may add methods (e.g., rememberForever in v2.21.0). Use Composer’s update command with --dry-run to test.
Breaking Changes Rare; follows semver. Major versions (e.g., 3.0.0) may require review. Pin to a specific minor version (e.g., ^2.25) in composer.json.
DragonCode Ecosystem Future packages may **
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport