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

Graph Core Laravel Package

nexus-scholar/graph-core

Lightweight PHP 8.2+ graph data-structure for directed/undirected graphs with node/edge attributes, fast adjacency via integer indexing, read-only subgraph views, and exporters for Cytoscape.js JSON, GraphML, and GEXF. Ideal base for graph analytics.

View on GitHub
Deep Wiki
Context7

Reusable PHP graph data structure library for Nexus Scholar citation-network work

Frequently asked questions about Graph Core
How do I integrate this package into a Laravel application for graph-based queries?
Use the package as a service container binding (e.g., `GraphRepository`) and pair it with Eloquent models. Store graph metadata in PostgreSQL/MySQL (e.g., `nodes` and `edges` tables) and hydrate into `graph-core` for in-memory traversals. For example, extend a `Paper` model with `citationNetwork()` to return a `SubgraphView` of co-cited papers.
Will this package work with Laravel 10/11 and PHP 8.2+?
Yes, `nexus-scholar/graph-core` requires PHP 8.2+, which aligns with Laravel 10/11’s supported versions. No runtime conflicts exist, but ensure `ext-dom` is enabled in `php.ini` for GraphML/GEXF exports.
Can I use this for large graphs (e.g., 50K+ nodes) in production?
For large graphs, test memory usage with `SubgraphView` to prune unnecessary nodes. PHP’s `memory_limit` may need adjustment. Offload traversals to SQL for batch processing or use Laravel’s queue system for async operations. Avoid concurrent writes—this package isn’t thread-safe.
How do I export graphs to Cytoscape.js or other visualization tools?
Use built-in exporters: `$graph->toCytoscapeJson()`, `$graph->toGraphML()`, or `$graph->toGEXF()`. These return formatted strings or arrays for direct use in APIs or frontend tools like Cytoscape.js. Validate output schemas if integrating with specific visualization libraries.
Is there a way to cache subgraphs for performance?
Yes, cache `SubgraphView` instances using Laravel’s cache drivers (e.g., Redis). For example, store a subgraph keyed by node IDs: `Redis::remember('subgraph:co_cited_papers', now()->addHours(1), fn() => $graph->subgraph(['paper1', 'paper2']))`.
What’s the difference between this and alternatives like `php-graph` or NetworkX via PHP bindings?
`nexus-scholar/graph-core` focuses on lightweight, typed graph modeling with Laravel-friendly features (e.g., subgraph views, exporters). Alternatives like `php-graph` may lack PHP 8.2+ typing or Laravel integration points. Benchmark adjacency lookups (O(1) here) and memory usage for your use case.
How do I persist graphs to a database and sync with Laravel models?
Store graph metadata in relational tables (e.g., `nodes(external_id, attributes)` and `edges(from_id, to_id, attributes)`). Use Laravel migrations to define schemas, then hydrate into `graph-core` for traversals. Trigger events (e.g., `GraphNodeAdded`) to sync changes bidirectionally.
Does this package support graph algorithms like PageRank or shortest paths?
No, this package provides core graph structures and primitives. For algorithms (e.g., PageRank, traversals), pair it with `nexus-scholar/graph-algorithms`. Alternatively, implement custom logic using `SubgraphView` and adjacency methods.
How do I handle node/edge attributes in Laravel validation or API responses?
Attributes are stored as associative arrays (e.g., `['weight' => 1.5, 'label' => 'Node A']`). Validate them via Laravel’s `Validator` or cast to JSON in API responses. For Eloquent, use `json` columns to store attributes and hydrate into graph nodes/edges.
What’s the best way to test this package in a Laravel CI/CD pipeline?
Use Pest or PHPUnit to test graph operations (e.g., `assertTrue($graph->hasEdge('A', 'B'))`). Mock database interactions if syncing with Eloquent. The package’s test suite is Pest-compatible, so adapt existing tests to your Laravel environment.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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