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

Annotated Laravel Package

cycle/annotated

Define Cycle ORM entities and schema using PHP 8 attributes. Annotate columns, primary keys, enums, decimals, and relationships like HasOne, HasMany, and BelongsTo, then let Cycle build the mapping from your code.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Schema-as-Code Alignment: The package enables declarative schema definition via PHP attributes, aligning with modern Laravel practices (e.g., Eloquent models). This reduces YAML/XML migrations and centralizes schema logic in the codebase.
  • Cycle ORM Integration: Designed for Cycle ORM, a high-performance alternative to Eloquent. If the team is already using Cycle ORM or evaluating it for performance-critical workloads, this package is a natural fit.
  • Attribute-Based Design: Leverages PHP 8+ attributes, which are idiomatic in modern PHP (e.g., Symfony, Laravel 9+). Reduces boilerplate compared to annotation-based approaches (e.g., Doctrine ORM).
  • Advanced ORM Features: Supports inheritance patterns (STI/JTI), polymorphic relations, embedded entities, and generated fields—useful for complex domain models but may introduce over-engineering for simpler applications.

Integration Feasibility

  • Laravel Compatibility:
    • Cycle ORM + Laravel: Requires Cycle ORM (not Eloquent) as the underlying persistence layer. Laravel’s default Eloquent is incompatible; migration would involve replacing Eloquent with Cycle ORM or using a facade layer.
    • Service Provider: The package requires Cycle ORM’s service provider to be bootstrapped, which may conflict with Laravel’s existing DatabaseServiceProvider.
    • Query Builder: Cycle ORM’s query builder differs from Laravel’s Query Builder. Teams relying heavily on Laravel’s query syntax (e.g., whereRaw, join) would need to adapt.
  • Migration Path:
    • Step 1: Replace Eloquent models with annotated entities (gradual per-module migration).
    • Step 2: Replace Laravel’s query builder with Cycle ORM’s (or abstract via a repository layer).
    • Step 3: Update migrations to use Cycle ORM’s schema generation (though annotations may reduce the need for raw migrations).
  • Tooling Ecosystem:
    • Laravel Scout/Hashing: Unclear compatibility with Laravel’s ecosystem (e.g., Scout for search, Hashing for passwords). Would need validation.
    • Testing: Works with PHPUnit/Pest but may require adjustments to Laravel’s testing helpers (e.g., create(), factory()).

Technical Risk

  • Performance vs. Convenience Tradeoff:
    • Cycle ORM is faster than Eloquent for complex queries but may introduce development overhead (e.g., learning Cycle’s query syntax).
    • Attribute-based schema definition reduces migration files but increases model complexity (e.g., nested annotations for relations).
  • Breaking Changes:
    • PHP 8.1+ Requirement: May block legacy Laravel projects (pre-8.1).
    • Cycle ORM Dependency: Tight coupling to Cycle ORM limits flexibility if the team later switches back to Eloquent.
  • Debugging Complexity:
    • Deeply Nested Annotations: Relations like ManyToMany or MorphedHasMany require careful setup. Debugging misconfigured relations (e.g., circular dependencies) could be challenging.
    • Schema Generation: Errors in annotations may only surface at runtime (e.g., invalid column types) or during schema compilation.
  • Missing Laravel-Specific Features:
    • No built-in support for Laravel-specific features (e.g., timestamps, softDeletes, observer events). Would need custom annotations or workarounds.

Key Questions

  1. Why Cycle ORM?
    • Is performance a bottleneck with Eloquent? If not, the migration cost may not justify the benefits.
    • Are there specific Cycle ORM features (e.g., repository pattern, CQRS support) that align with the team’s architecture?
  2. Team Adoption:
    • Does the team have experience with attribute-based configurations (e.g., Symfony attributes)?
    • Is there resistance to replacing Eloquent, even for schema definition?
  3. Ecosystem Impact:
    • How will this affect third-party packages (e.g., Laravel Nova, Forge, Envoyer) that rely on Eloquent?
    • Are there Laravel-specific tools (e.g., Telescope, Horizon) that need to integrate with Cycle ORM?
  4. Long-Term Maintenance:
    • Who will maintain Cycle ORM compatibility if the package evolves independently of Laravel?
    • What’s the rollback plan if the migration proves too disruptive?

Integration Approach

Stack Fit

  • Core Stack:
    • PHP 8.1+: Required by the package (aligns with Laravel 9+).
    • Laravel Framework: Compatible but not natively integrated. Requires:
      • Replacing Illuminate\Database\Eloquent\Model with annotated entities.
      • Configuring Cycle ORM as the primary ORM (via service provider).
    • Cycle ORM: Mandatory dependency. Must be installed and configured alongside Laravel’s database components.
  • Alternatives Considered:
    • Doctrine ORM: Similar attribute-based schema definition but with deeper Laravel integration (e.g., doctrine/dbal).
    • Eloquent: Native Laravel ORM with no migration needed, but lacks Cycle ORM’s performance optimizations.
  • Tooling Compatibility:
    • Laravel Migrations: Can coexist but may become redundant if schema is fully defined via annotations.
    • Laravel Factories: Would need adaptation to work with Cycle ORM entities (e.g., custom ModelFactory).
    • Laravel Scout: Unclear compatibility; may require a custom search backend.

Migration Path

  1. Phase 1: Proof of Concept (2–4 weeks)
    • Isolate a non-critical module (e.g., admin dashboard).
    • Replace Eloquent models with annotated entities.
    • Test CRUD operations, relations, and migrations.
    • Validate performance gains (if applicable).
  2. Phase 2: Core Domain Migration (4–8 weeks)
    • Migrate domain models (e.g., User, Order) to annotated entities.
    • Replace Laravel’s query builder with Cycle ORM’s (gradually via a repository layer).
    • Update seeds/factories to work with Cycle ORM.
  3. Phase 3: Full Integration (2–4 weeks)
    • Replace Laravel’s service container bindings for database-related services.
    • Update third-party integrations (e.g., API resources, notifications).
    • Deprecate Eloquent-specific code (e.g., Model::boot() observers).
  4. Phase 4: Rollback Plan
    • Maintain a dual-writing period where both Eloquent and Cycle ORM are supported.
    • Document critical paths that rely on Eloquent-specific features (e.g., hasManyThrough).

Compatibility

Feature Compatibility Workaround
Eloquent Models ❌ Incompatible Replace with annotated entities or use a facade layer.
Laravel Migrations ✅ Compatible (but redundant if using annotations) Use Cycle ORM’s schema generation or keep migrations for non-annotated tables.
Query Builder ❌ Incompatible Use Cycle ORM’s query builder or abstract via repositories.
Eloquent Relations ❌ Incompatible Replace with HasOne, BelongsTo, etc.
Soft Deletes ❌ Not natively supported Implement via Column(type: 'boolean') + custom scope.
Observers/Events ❌ Incompatible Use Cycle ORM’s lifecycle callbacks or event system.
API Resources ✅ Compatible (if using spatie/laravel-api-resources) No changes needed.
Scout (Search) ❓ Unknown May require custom integration or switch to Algolia/Meilisearch directly.
Breeze/Jetstream Auth ❌ Likely incompatible Replace with custom auth logic or adapt packages.

Sequencing

  1. Start with Simple Models:
    • Begin with flat, non-relational models (e.g., User, Product) to validate the annotation syntax.
  2. Tackle Relations Gradually:
    • Migrate HasOne/BelongsTo before complex relations like ManyToMany or polymorphic types.
  3. Handle Inheritance Last:
    • STI/JTI patterns are the most complex; defer until other migrations are stable.
  4. Performance-Critical Paths:
    • Prioritize modules with high query volumes (e.g., checkout flow, analytics) for early wins.
  5. Deprecate Eloquent:
    • Once 80% of models are migrated, remove Eloquent dependencies (e.g., use Illuminate\Database\Eloquent\Model).

Operational Impact

Maintenance

  • Pros:
    • Single Source of Truth: Schema is defined in PHP classes, reducing drift between code and database.
    • Type Safety: PHP 8.1+ attributes enable static analysis
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.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky