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 structured, relational storage of AI-generated conversations. This aligns well with Laravel applications requiring auditability, compliance, or SQL-based querying of AI interactions (e.g., chatbots, LLM integrations, or regulated industries).
  • Abstraction Layer: Uses Doctrine DBAL (not ORM), ensuring database agnosticism (PostgreSQL, MySQL, SQLite) and lightweight integration. Avoids Eloquent coupling, allowing flexibility in schema design.
  • Symfony Ecosystem: While Symfony-focused, the package adheres to PSR-15 Message Store standards, making it adaptable to Laravel via Symfony’s Bridge components or custom wrappers. Laravel’s existing doctrine/dbal support reduces friction.

Integration Feasibility

  • Laravel Compatibility:
    • Doctrine DBAL: Native support via doctrine/dbal (v3.x+).
    • PSR-15 Message Store: Laravel lacks native PSR-15 support, requiring a custom adapter or Symfony’s Messenger for compatibility.
    • Symfony AI Chat: Not directly usable in Laravel; must replace with Laravel-specific AI packages (e.g., laravel-ai) or build a message store facade.
  • Key Dependencies:
    • Requires Symfony AI Chat (v0.8+) or a PSR-15-compatible consumer.
    • No Eloquent dependency, but schema migrations must align with Laravel’s Schema builder or Doctrine tools.

Technical Risk

  • High:
    • Symfony-Laravel Friction: Laravel’s event/queue systems (e.g., Illuminate\Bus) are not PSR-15-native, necessitating custom middleware or wrapper classes.
    • Schema Management: Conflicts may arise if the package’s DBAL schema clashes with existing Laravel migrations.
    • Performance Overhead: DBAL-based storage may introduce latency for high-throughput AI interactions (e.g., >10K messages/sec), compared to Redis or in-memory stores.
  • Mitigation:
    • Prototype: Test with a minimal Laravel app using symfony/ai and this store to validate PSR-15 integration.
    • Hybrid Approach: Use this package only for structured queries and offload high-volume messages to Redis (via spatie/laravel-redis-message-store).
    • Fallback: Implement a Laravel-native message store using DatabaseManager if PSR-15 is prohibitive.

Key Questions

  1. Database Strategy:
    • Does the use case require SQL querying (e.g., full-text search, joins with user data) or can Redis/Elasticsearch suffice?
    • Are there compliance/audit requirements mandating relational storage (e.g., GDPR, HIPAA)?
  2. Symfony Dependency:
    • Is the Laravel app already using Symfony’s AI components, or is this a one-off integration?
    • Can the message store be decoupled from Symfony AI Chat to avoid vendor lock-in?
  3. Schema Ownership:
    • Will this share a database with existing Laravel tables? If so, how will schema conflicts be resolved?
    • Are there predefined Laravel migrations for the DBAL schema, or must they be written manually?
  4. Performance Baseline:
    • What is the expected message volume? Will DBAL meet latency requirements, or is a hybrid cache (e.g., Redis + DBAL) needed?
  5. Long-Term Maintenance:
    • Is the team comfortable with Symfony’s release cadence for this package?
    • Are there Laravel-specific alternatives (e.g., spatie/laravel-ai) that reduce Symfony dependency?

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 (if available) or a custom PSR-15 adapter.
    • Message Storage: Hybrid approach:
      • Use this package for structured queries (e.g., analytics, compliance).
      • Offload high-volume messages to Redis (via spatie/laravel-redis-message-store).

Migration Path

  1. Phase 1: Proof of Concept (1–2 weeks)

    • Install dependencies:
      composer require doctrine/dbal symfony/ai-doctrine-message-store
      
    • Implement a minimal PSR-15 consumer in Laravel (e.g., a MessageStore facade wrapping the Symfony 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, indexes).
    • 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 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::class,
          ],
      ];
      
    • Implement a priority-based routing system (e.g., Redis for real-time, DBAL for persistence).
  4. Phase 4: Monitoring (Ongoing)

    • Track query latency and database load using Laravel’s DB::listen.
    • Set up alerts for schema drift (e.g., schema:update checks).
    • Monitor message store health with custom metrics (e.g., Laravel Debugbar).

Compatibility

  • Doctrine DBAL: Fully compatible; Laravel supports it natively.
  • PSR-15:
    • Incompatible without adaptation. Solutions:
      • 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 for simplicity.
  • Symfony AI Chat:
    • Not directly usable in Laravel. Must replace with:
      • laravel-ai packages (if available).
      • Custom LLM service with manual message storage (e.g., AIService::storeMessage()).

Sequencing

  1. Prerequisite: Ensure doctrine/dbal is installed and configured in config/database.php.
  2. Step 1: Set up the message store schema.
    // database/migrations/xxxx_create_ai_messages_table.php
    Schema::create('ai_messages', function (Blueprint $table) {
        $table->id();
        $table->string('conversation_id');
        $table->text('message');
        $table->json('metadata')->nullable();
        $table->timestamps();
    });
    
  3. Step 2: Implement PSR-15 compatibility layer.
    // app/Services/LaravelMessageStore.php
    namespace App\Services;
    
    use Symfony\Component\Messenger\Message\SentMessageInterface;
    use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
    use Doctrine\DBAL\Connection;
    
    class LaravelMessageStore implements \Symfony\Component\Messenger\MessageStoreInterface
    {
        public function __construct(private Connection $connection) {}
    
        public function ack(SentMessageInterface $message): void
        {
            // Implement DBAL-based ack logic
        }
    
        public function reject(SentMessageInterface $message, \Throwable $reason): void
        {
            // Implement rejection logic
    
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata