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

Ai Doctrine Message Store Laravel Package

symfony/ai-doctrine-message-store

Doctrine DBAL message store integration for Symfony AI Chat. Persist and retrieve chat messages in a relational database using Doctrine DBAL, enabling durable conversation history and easy storage configuration within Symfony applications.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The package provides a Doctrine DBAL-backed message store for Symfony AI Chat, enabling persistent storage of AI-generated conversations in a relational database. For Laravel, this aligns with use cases requiring structured, queryable storage (e.g., compliance logs, customer support chatbots) but introduces Symfony-specific abstractions (PSR-15 Message Store) that may not natively fit Laravel’s ecosystem.
  • Abstraction Layer: Leverages Doctrine DBAL (not ORM), making it database-agnostic and lightweight. However, Laravel’s default Eloquent and Query Builder may complicate integration, as this package assumes Symfony’s PSR-15 message store interface.
  • Key Tradeoffs:
    • Pros: Durable storage, SQL query flexibility, no schema migrations required (if using existing tables).
    • Cons: Symfony dependency, potential performance overhead (DBAL vs. Redis), and Laravel-Symfony friction (e.g., no native PSR-15 support).

Integration Feasibility

  • Doctrine DBAL: Fully compatible with Laravel (doctrine/dbal package). No architectural conflicts.
  • PSR-15 Message Store: Critical hurdle. Laravel lacks native PSR-15 support, requiring:
    • A custom adapter to bridge Symfony’s MessageStoreInterface with Laravel’s event/queue systems.
    • Alternatively, abandon PSR-15 and use Laravel’s DatabaseManager directly (losing some Symfony AI features).
  • Symfony AI Chat: Not directly usable in Laravel. Must replace with:
    • laravel-ai packages (if available).
    • A custom LLM service with manual message storage logic.
  • Schema Management: The package assumes Doctrine DBAL schema control. Laravel’s migrations may conflict if not coordinated (e.g., table/column naming, constraints).

Technical Risk

  • High:
    • Symfony-Laravel Integration Risk: PSR-15 is foreign to Laravel. Custom middleware or wrapper classes will be needed, increasing development time and complexity.
    • Performance: DBAL-based storage may introduce latency for high-throughput AI interactions (e.g., real-time chatbots). Benchmark against Redis or in-memory stores.
    • Schema Conflicts: If sharing a database with existing Laravel tables, risk of constraint violations or naming collisions (e.g., ai_messages vs. user_messages).
  • Mitigation Strategies:
    1. Prototype First: Test with a minimal Laravel app to validate PSR-15 compatibility and performance.
    2. Hybrid Approach: Use this package only for structured queries (e.g., analytics) and offload high-volume messages to Redis or Elasticsearch.
    3. Schema Isolation: Dedicate a separate database schema for AI messages to avoid conflicts.
    4. Fallback Plan: If integration proves too cumbersome, replace with a Laravel-native solution (e.g., spatie/laravel-activitylog for message storage).

Key Questions

  1. Why Relational Storage?

    • Does the use case require SQL querying (e.g., joins with user data, full-text search)?
    • Are there compliance/audit requirements mandating relational storage (e.g., GDPR, HIPAA)?
    • If not, Redis or Elasticsearch may be simpler and higher-performance.
  2. Symfony Dependency Acceptance

    • Is the team open to Symfony’s PSR-15 abstractions, or is a Laravel-native solution preferred?
    • Can we replace Symfony AI Chat with a Laravel-compatible alternative (e.g., laravel-ai)?
  3. Schema Strategy

    • Will this share a database with existing Laravel tables? If so, how will schema migrations be managed?
    • Are there predefined Laravel migrations for the DBAL schema, or will manual setup be required?
  4. Performance Requirements

    • What is the expected message volume (e.g., messages/sec)? DBAL may struggle with >10K writes/sec.
    • Are there latency SLAs for AI responses (e.g., <500ms)? If so, DBAL may not meet them.
  5. Long-Term Maintenance

    • Is the team comfortable with Symfony’s release cadence for this package?
    • Are there Laravel-specific forks or alternatives (e.g., spatie/laravel-ai) that reduce dependency risk?

Integration Approach

Stack Fit

Component Laravel Equivalent/Adapter Needed Notes
Doctrine DBAL doctrine/dbal (v3.x) Native support; no changes required.
PSR-15 Message Store Custom wrapper or Symfony’s Messenger Laravel lacks PSR-15; bridge required.
Symfony AI Chat Replace with laravel-ai or custom LLM service Avoid Symfony dependency bloat.
Schema Migrations Laravel Schema builder or Doctrine Migrations Prefer Laravel’s for consistency.
Recommended Stack Database: PostgreSQL/MySQL (via DBAL)
AI Framework: laravel-ai or custom service
Message Storage: Hybrid (DBAL for queries, Redis for volume)

Migration Path

  1. Phase 1: Feasibility Test (1–2 weeks)

    • Install dependencies:
      composer require doctrine/dbal symfony/ai-doctrine-message-store symfony/messenger
      
    • Implement a minimal PSR-15 consumer in Laravel:
      // app/Providers/AppServiceProvider.php
      use Symfony\Component\Messenger\MessageBusInterface;
      use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
      
      public function register()
      {
          $this->app->singleton(MessageBusInterface::class, function ($app) {
              $store = new \Symfony\AI\DoctrineMessageStore\DoctrineDBALMessageStore(
                  $app['db']->connection()->getDoctrineConnection()
              );
              return new \Symfony\Component\Messenger\MessageBus([$store]);
          });
      }
      
    • Test with 100–1000 messages to validate schema and performance.
  2. Phase 2: Schema Integration (1 week)

    • Generate Laravel migrations for the DBAL schema:
      php artisan make:migration create_ai_messages_table --table=ai_messages
      
    • Ensure no conflicts with existing tables (e.g., unique constraints, naming).
    • Optionally, use Doctrine Migrations if already in the stack.
  3. Phase 3: AI Integration (2–3 weeks)

    • Replace Laravel’s AI message handling with the new store.
    • Add a fallback to Redis for performance-critical paths:
      // config/ai.php
      'message_store' => [
          'primary' => \App\Services\HybridMessageStore::class,
          'drivers' => [
              'dbal' => \Symfony\AI\DoctrineMessageStore\DoctrineDBALMessageStore::class,
              'redis' => \Spatie\RedisMessageStore\RedisMessageStore::class,
          ],
      ];
      
    • Implement HybridMessageStore to route messages based on volume/latency needs.
  4. Phase 4: Monitoring (Ongoing)

    • Track query latency (e.g., DB::listen for slow queries).
    • Set up alerts for schema drift (e.g., schema:update checks).
    • Monitor database load (e.g., pg_stat_activity for PostgreSQL).

Compatibility

  • Doctrine DBAL: Fully compatible. Laravel supports it natively via doctrine/dbal.
  • PSR-15 Message Store: Incompatible without adaptation. Options:
    • Option A: Write a Laravel PSR-15 bridge (e.g., LaravelMessageStore implementing MessageStoreInterface).
    • Option B: Use Symfony’s Messenger (if already in stack) to consume PSR-15 messages.
    • Option C: Abandon PSR-15 and use Laravel’s DatabaseManager directly (simpler but loses Symfony AI features).
  • Symfony AI Chat: Not directly usable. Must replace with:
    • laravel-ai packages (if available).
    • A custom LLM service with manual message storage (e.g., using Eloquent models).

Sequencing

  1. Prerequisite: Ensure doctrine/dbal is installed and configured.
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.
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
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope