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

Doctrine Odm Mongodb Bridge Laravel Package

bengor-user/doctrine-odm-mongodb-bridge

Doctrine ODM MongoDB bridge for BenGorUser, providing adapters to persist and query User domain models with Doctrine ODM. Install via Composer; fully tested with PHPSpec. Documentation lives in the main BenGorUser/User repository.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: This package bridges Symfony’s User component (or similar) with Doctrine ODM for MongoDB, enabling seamless integration of user entities into a NoSQL-backed Laravel application. If the project relies on MongoDB for user data (e.g., flexible schemas, horizontal scaling, or legacy migration), this package provides a lightweight adapter layer.
  • Laravel Compatibility: Laravel primarily uses Eloquent (SQL) or MongoDB drivers (e.g., jenssegers/laravel-mongodb). This package is not Laravel-native but could be leveraged in a hybrid stack (e.g., MongoDB for users, SQL for transactions) via Doctrine ODM integration (e.g., doctrine/mongodb-odm).
  • Alternatives: Laravel’s built-in MongoDB support (via jenssegers/laravel-mongodb) or native Eloquent may suffice. This package adds Doctrine ODM-specific features (e.g., @Document, @EmbeddedDocument) if the team is already using Doctrine.

Integration Feasibility

  • Doctrine ODM Dependency: Requires Doctrine MongoDB ODM (doctrine/mongodb-odm) as a prerequisite. Laravel does not natively support ODM, so this introduces additional complexity (e.g., configuring ODM alongside Eloquent).
  • User Component Dependency: Assumes a Symfony User interface (e.g., UserInterface, UserProvider). Laravel’s Authenticatable or MustVerifyEmail would need adaptation (e.g., via traits or custom interfaces).
  • Schema Flexibility: MongoDB’s schema-less nature may conflict with Laravel’s migrations. Manual mapping of Doctrine ODM entities to Laravel’s auth system (e.g., users table) would be required.

Technical Risk

  • High Maintenance Overhead:
    • Abandoned Package: Last release in 2017; no Laravel 10/PHP 8.2+ support. Risk of breaking changes with newer Doctrine/ODM versions.
    • No Laravel-Specific Docs: Documentation assumes Symfony; Laravel-specific quirks (e.g., service providers, config publishing) must be reverse-engineered.
  • Dependency Conflicts:
    • Potential clashes with Laravel’s service container, auth scaffolding, or MongoDB drivers (e.g., jenssegers/laravel-mongodb vs. Doctrine ODM).
  • Testing Gaps:
    • Tests use PHPSpec (BDD), not PHPUnit. No Laravel-specific test suite exists, increasing risk of integration issues.
  • Performance:
    • Doctrine ODM may introduce overhead compared to native Laravel MongoDB drivers. Benchmarking required for high-traffic user operations (e.g., login, role checks).

Key Questions

  1. Why MongoDB for Users?
    • Is schema flexibility, horizontal scaling, or legacy migration the primary driver? Could Laravel’s native MongoDB support suffice?
  2. Doctrine ODM Justification
    • Are other Doctrine features (e.g., @ReferenceOne, @EmbeddedDocument) needed beyond basic CRUD? If not, native MongoDB drivers may be simpler.
  3. Auth System Compatibility
    • How will Laravel’s Auth facade integrate with Doctrine ODM’s UserRepository? Will custom providers be needed?
  4. Migration Path
    • If transitioning from SQL to MongoDB, how will existing user data (e.g., passwords, roles) be migrated?
  5. Long-Term Viability
    • Given the package’s age, is the team willing to maintain a fork or accept potential breakage with newer PHP/Laravel versions?
  6. Alternatives Evaluated

Integration Approach

Stack Fit

  • Target Stack:
    • Laravel (v8/9/10) + Doctrine MongoDB ODM (doctrine/mongodb-odm) + Symfony User Component (or Laravel-compatible wrapper).
    • Alternate: If Doctrine ODM is overkill, consider jenssegers/laravel-mongodb + custom User model.
  • Key Components:
    1. Doctrine ODM Setup:
      • Install doctrine/mongodb-odm-bundle (Symfony) or integrate ODM manually in Laravel.
      • Configure config/packages/doctrine_mongodb_odm.yaml (Symfony) or Laravel service providers.
    2. User Entity:
      • Extend Laravel’s Authenticatable with Doctrine ODM’s @Document annotations.
      • Example:
        use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
        use Illuminate\Foundation\Auth\User as Authenticatable;
        
        #[ODM\Document(collection: "users")]
        class User extends Authenticatable {
            #[ODM\Id(strategy: "UUID")]
            protected ?string $id = null;
        
            // Laravel auth fields (email, password_hash)
            // Doctrine ODM-specific fields (e.g., roles as @EmbeddedDocument)
        }
        
    3. Authentication Bridge:
      • Create a custom UserProvider to bridge Doctrine ODM’s UserRepository with Laravel’s Auth system.
      • Example:
        use Doctrine\ODM\MongoDB\DocumentRepository;
        use Illuminate\Contracts\Auth\Authenticatable as LaravelUser;
        
        class DoctrineUserProvider implements UserProviderInterface {
            public function retrieveById($identifier): ?LaravelUser {
                return $this->odmRepository->find($identifier);
            }
            // Implement other Auth methods...
        }
        

Migration Path

  1. Phase 1: Proof of Concept
    • Set up a parallel environment with Doctrine ODM and test basic CRUD (create, read, update user).
    • Verify compatibility with Laravel’s Hash (password hashing) and Auth facade.
  2. Phase 2: Auth Integration
    • Replace Laravel’s default User model with the ODM-annotated version.
    • Update config/auth.php to use the custom DoctrineUserProvider.
  3. Phase 3: Data Migration
    • Write a migration script to export SQL users to MongoDB (e.g., using doctrine/dbal + ODM bulk inserts).
    • Example:
      $sqlUsers = DB::table('users')->get();
      foreach ($sqlUsers as $user) {
          $odmUser = new User();
          $odmUser->email = $user->email;
          $odmUser->password = bcrypt($user->password);
          $dm->persist($odmUser);
      }
      $dm->flush();
      
  4. Phase 4: Deprecation
    • Gradually deprecate SQL user queries in favor of ODM (e.g., replace User::where() with UserRepository::createQueryBuilder()).

Compatibility

  • Laravel-Specific Challenges:
    • Service Container: Doctrine ODM uses Symfony’s dependency injection. Laravel’s container may require custom bindings (e.g., AppServiceProvider).
    • Migrations: Laravel’s Schema builder won’t work with MongoDB. Use Doctrine ODM’s schema validation or manual scripts.
    • Events: Laravel’s auth.login, auth.register events may need custom listeners to work with ODM.
  • Doctrine ODM Quirks:
    • No Migrations: ODM uses schema validation, not migrations. Schema changes require manual updates.
    • Performance: ODM’s hydration strategies (e.g., HYDRATE_ARRAY) may impact query speed. Benchmark against native MongoDB drivers.

Sequencing

  1. Prerequisites:
    • Install doctrine/mongodb-odm and configure MongoDB connection.
    • Set up a Symfony User Component or create a Laravel-compatible wrapper.
  2. Core Integration:
    • Annotate the User model with ODM metadata.
    • Implement the DoctrineUserProvider and register it in Laravel’s auth config.
  3. Testing:
    • Test authentication flows (login, registration, password reset).
    • Validate role/permission systems (if using ODM’s @EmbeddedDocument).
  4. Rollout:
    • Start with non-critical user data (e.g., profiles) before migrating auth.
    • Monitor performance and error rates post-migration.

Operational Impact

Maintenance

  • Short-Term:
    • High Effort: Initial setup requires custom providers, schema mapping, and data migration.
    • Debugging: Issues may span Laravel auth, Doctrine ODM, and MongoDB layers, increasing time-to-resolve.
  • Long-Term:
    • Fork Risk: Given
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony