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

Bolt Laravel Package

stefanak-michal/bolt

Low-level PHP Bolt protocol driver (Bolt <= 6) for TCP socket communication with graph databases like Neo4j, Memgraph, Amazon Neptune, and others. Supports PHP 8.1+ and tracks official protocol message specifications across versions.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Graph Database Integration: The package provides a low-level Bolt protocol driver for PHP, enabling direct TCP socket communication with graph databases (Neo4j, Memgraph, Amazon Neptune, etc.). This aligns well with Laravel applications requiring high-performance graph queries (e.g., recommendation engines, fraud detection, knowledge graphs).
  • Protocol Agnosticism: Supports Bolt ≤6, ensuring compatibility with modern graph databases while allowing future-proofing via version negotiation.
  • Pipeline Support: Enables pipelined queries (chaining run/pull operations), reducing latency for batch operations—a critical feature for Laravel’s async job queues or bulk data processing.

Integration Feasibility

  • Laravel Compatibility: Works with PHP ≥8.1 (Laravel 9+), but requires sockets/openssl extensions (common in production but may need enabling in shared hosting).
  • ORM/Query Builder Synergy: Can integrate with Laravel Eloquent via custom query builders or Laravel Scout for graph-based search. Example:
    // Custom Graph Query Builder
    class GraphQueryBuilder {
        public function run(string $cypher, array $params): array {
            $bolt = (new Bolt(new Socket('127.0.0.1', 7687)))
                ->setProtocolVersions(5.4)
                ->build();
            return $bolt->run($cypher, $params)->pullAll()->getResponses();
        }
    }
    
  • Event-Driven Workflows: Fits Laravel’s event system (e.g., trigger graph updates on model events) or queues (async graph processing).

Technical Risk

  • Low-Level Complexity: Requires manual handling of Bolt messages (e.g., hello/logon/run/pull), increasing boilerplate. Mitigation: Use the Client helper or wrap in a Laravel service.
  • Connection Management: No built-in connection pooling (unlike Laravel’s database connections). Risk: Socket exhaustion under high load. Mitigation: Implement a custom connection pool or use Laravel’s DatabaseManager.
  • Error Handling: Bolt responses are binary, requiring custom parsing. Risk: Silent failures. Mitigation: Validate responses with Response::isSuccess().
  • Cypher Parameter Safety: Raw Cypher queries expose SQL injection risks. Mitigation: Use parameterized queries (as shown in the example).

Key Questions

  1. Use Case Clarity:
    • Is this for real-time graph traversals (e.g., social networks) or batch analytics (e.g., ETL)?
    • Will it replace or supplement Laravel’s existing database (e.g., MySQL/PostgreSQL)?
  2. Performance Requirements:
    • What’s the expected query volume? (Bolt pipelining helps, but high throughput may need connection pooling.)
    • Are transactions critical? (Bolt supports begin/commit/rollback.)
  3. Operational Overhead:
    • Who manages schema migrations (Cypher vs. Laravel Migrations)?
    • How will failover/retry logic be handled? (Laravel’s DatabaseManager could abstract this.)
  4. Team Expertise:
    • Does the team have graph database experience (Cypher, Bolt protocol)?
    • Is there budget for custom wrappers or training?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Database Layer: Integrate via custom connection driver (extend Illuminate\Database\Connectors\ConnectionFactory) or service container binding.
    • Query Builder: Extend Illuminate\Database\Query\Builder to support Cypher queries.
    • Scout: Replace Elasticsearch with Neo4j for full-text + graph search.
    • Events/Jobs: Use Bolt for event sourcing or async graph updates.
  • Microservices:
    • Deploy as a separate service (e.g., Laravel API) communicating with graph DB, then call via HTTP/gRPC.
  • Hybrid Architecture:
    • Use Laravel for CRUD + Neo4j for graph traversals (e.g., user recommendations).

Migration Path

  1. Proof of Concept (PoC):
    • Replace a single complex query (e.g., "find all friends of friends") with Cypher via Bolt.
    • Benchmark against existing SQL/NoSQL solutions.
  2. Incremental Adoption:
    • Phase 1: Add Bolt as a secondary data source (e.g., cache graph results in Redis).
    • Phase 2: Migrate read-heavy graph operations (e.g., analytics).
    • Phase 3: Replace write-heavy operations (e.g., relationship updates).
  3. Tooling:
    • Use Laravel Artisan commands to sync data between SQL and Neo4j.
    • Example:
      // Artisan command to sync users to Neo4j
      $bolt = app(BoltService::class);
      foreach (User::all() as $user) {
          $bolt->run("CREATE (u:User {id: \$id, name: \$name})", [
              'id' => $user->id,
              'name' => $user->name
          ]);
      }
      

Compatibility

  • Protocol Versions: Defaults to 4.3–6.0; explicitly set versions for older databases (e.g., setProtocolVersions(4.4)).
  • Authentication: Supports Basic, Bearer, Kerberos (align with Laravel’s Auth system).
  • Data Types: Maps PHP types to Bolt’s PackStream (e.g., arrayList, objectDictionary).
  • Transactions: Bolt ≥3 supports ACID; use begin/commit for multi-query operations.

Sequencing

  1. Infrastructure Setup:
    • Install Neo4j/Memgraph (Docker/Kubernetes).
    • Configure firewall rules for Bolt port (default: 7687).
  2. Laravel Configuration:
    • Add Bolt to config/database.php:
      'connections' => [
          'neo4j' => [
              'driver' => 'bolt',
              'host' => env('NEO4J_HOST', '127.0.0.1'),
              'port' => env('NEO4J_PORT', 7687),
              'username' => env('NEO4J_USER'),
              'password' => env('NEO4J_PASSWORD'),
              'protocol_versions' => [5.4],
          ],
      ],
      
  3. Driver Development:
    • Create a Laravel database driver (extend Illuminate\Database\Connection).
    • Example:
      class BoltConnection extends Connection {
          public function run($query, $bindings = [], $useReadPdo = true) {
              $bolt = (new Bolt(new Socket($this->config['host'], $this->config['port'])))
                  ->setProtocolVersions($this->config['protocol_versions'])
                  ->build();
              return $bolt->run($query, $bindings)->pullAll()->getResponses();
          }
      }
      
  4. Testing:
    • Unit test Cypher queries with Laravel’s DatabaseMigrations.
    • Load test with Laravel Dusk or Artillery.

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor Bolt protocol changes (e.g., Neo4j’s Bolt 7.0).
    • Update PHP dependencies (e.g., mbstring, sockets) in php.ini.
  • Schema Management:
    • Use Laravel Migrations for SQL + Cypher scripts for graph schema.
    • Tool: Neo4j Browser or Laravel Artisan commands to run Cypher.
  • Logging:
    • Enable Bolt’s debug mode (Bolt::$debug = true) for troubleshooting.
    • Log query performance (e.g., execution time) via Laravel’s Log facade.

Support

  • Troubleshooting:
    • Connection Issues: Verify firewall, Neo4j service status, and Bolt port.
    • Query Errors: Check Cypher syntax with neo4j-admin or Neo4j Bloom.
    • Performance Bottlenecks: Use Neo4j Profiler or Laravel’s DB::enableQueryLog().
  • Documentation:
    • Maintain a runbook for common Bolt errors (e.g., INVALID_SIGNATURE).
    • Document Cypher query patterns (e.g., "how to traverse relationships").

Scaling

  • Horizontal Scaling:
    • Neo4j supports Causal Clustering (multi-master); Bolt handles failover.
    • Laravel: Use queue workers for async graph jobs.
  • Connection Pooling:

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.
craftcms/url-validator
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