PHPackages                             nexus-scholar/graph-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nexus-scholar/graph-core

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nexus-scholar/graph-core
========================

A lightweight, performant, and dependency-free graph data structure library for PHP.

v1.2.0(2w ago)0220↑227.3%MITPHPPHP ^8.2CI passing

Since Sep 23Pushed 1w agoCompare

[ Source](https://github.com/nexus-scholar/graph-core)[ Packagist](https://packagist.org/packages/nexus-scholar/graph-core)[ Docs](https://github.com/nexus-scholar/graph-core)[ RSS](/packages/nexus-scholar-graph-core/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

nexus-scholar/graph-core
========================

[](#nexus-scholargraph-core)

[![PHP Version](https://camo.githubusercontent.com/962aced9b09d89716dbebf186ff899754a096ff1068b6b7988675c2d9fab9331/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Latest Version on Packagist](https://camo.githubusercontent.com/4d785d31a3e0d35bfd5cb24ad822207c956ab6a8506762c97362c616f4884ed0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e657875732d7363686f6c61722f67726170682d636f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nexus-scholar/graph-core)[![GitHub Tests Action Status](https://camo.githubusercontent.com/d4ab724e2098d80d397642f6e0849b5d334ccc855b8c9355a7b448f3126c7243/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e657875732d7363686f6c61722f67726170682d636f72652f63692e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/nexus-scholar/graph-core/actions)[![Total Downloads](https://camo.githubusercontent.com/24870044b16155bd199d6cbcb15594c7f5823714931d6a51b8abf1a9b909b7d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e657875732d7363686f6c61722f67726170682d636f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nexus-scholar/graph-core)

`graph-core` is a lightweight PHP graph data-structure package for directed and undirected graphs. It provides node and edge attributes, efficient adjacency lookups, subgraph views, and exporters for common graph-visualization formats.

Role In Nexus Scholar
---------------------

[](#role-in-nexus-scholar)

This package is the graph foundation for Nexus Scholar citation-network work. It intentionally stays generic: scholarly concepts such as papers, citations, co-citation, bibliographic coupling, screening, and exports live in `nexus-scholar/core`, while graph storage, traversal primitives, attributes, and serialization live here.

Use it directly for PHP graph modeling, or pair it with `nexus-scholar/graph-algorithms` when you need centrality, pathfinding, traversal, components, ordering, or minimum-spanning-tree algorithms.

Features
--------

[](#features)

- Directed and undirected graph support.
- Node and edge attributes.
- Integer indexing internally for fast adjacency lookups.
- Read-only subgraph views without copying the full graph.
- Cytoscape.js JSON, GraphML, and GEXF exporters.
- PHP 8.2+ types and interfaces.
- No runtime dependencies except `ext-dom` for XML export formats.
- Pest-backed test suite.

Requirements
------------

[](#requirements)

- PHP 8.2+
- `ext-dom` for GraphML and GEXF exports

Installation
------------

[](#installation)

```
composer require nexus-scholar/graph-core
```

Quick Start
-----------

[](#quick-start)

```
use Mbsoft\Graph\Domain\Graph;

$graph = new Graph(directed: true);

$graph->addNode('A', ['label' => 'Node A']);
$graph->addNode('B', ['label' => 'Node B']);
$graph->addNode('C', ['label' => 'Node C']);

$graph->addEdge('A', 'B', ['weight' => 1.5]);
$graph->addEdge('B', 'C', ['weight' => 2.0]);
$graph->addEdge('C', 'A', ['weight' => 0.5]);

count($graph->nodes()); // 3
count($graph->edges()); // 3

if ($graph->hasEdge('A', 'B')) {
    $weight = $graph->edgeAttrs('A', 'B')['weight'];
}

$successors = $graph->successors('A');
$predecessors = $graph->predecessors('C');
```

Undirected Graphs
-----------------

[](#undirected-graphs)

```
use Mbsoft\Graph\Domain\Graph;

$graph = new Graph(directed: false);

$graph->addEdge('A', 'B', ['type' => 'friendship']);
$graph->addEdge('B', 'C', ['type' => 'friendship']);

$graph->hasEdge('A', 'B'); // true
$graph->hasEdge('B', 'A'); // true

$graph->successors('B');
$graph->predecessors('B');
```

Edge Lists
----------

[](#edge-lists)

```
use Mbsoft\Graph\Domain\Graph;

$edges = [
    ['A', 'B', ['weight' => 1.0]],
    ['B', 'C', ['weight' => 2.0]],
    ['C', 'D', ['weight' => 1.5]],
];

$graph = Graph::fromEdgeList($edges, directed: true);
```

Subgraph Views
--------------

[](#subgraph-views)

```
use Mbsoft\Graph\Domain\Graph;
use Mbsoft\Graph\Domain\SubgraphView;

$graph = new Graph();
$graph->addEdge('A', 'B');
$graph->addEdge('B', 'C');
$graph->addEdge('C', 'D');

$subgraph = new SubgraphView($graph, ['A', 'B', 'C']);

$subgraph->nodes();
$subgraph->edges();
$subgraph->hasEdge('C', 'D'); // false
```

Export Formats
--------------

[](#export-formats)

Export for browser visualization with Cytoscape.js:

```
use Mbsoft\Graph\IO\CytoscapeJsonExporter;

$exporter = new CytoscapeJsonExporter();
$json = $exporter->export($graph);
```

Export GraphML for tools such as Gephi, yEd, or NetworkX:

```
use Mbsoft\Graph\IO\GraphMLExporter;

$exporter = new GraphMLExporter();
$xml = $exporter->export($graph);
```

Export GEXF for Gephi and compatible network-analysis tools:

```
use Mbsoft\Graph\IO\GexfExporter;

$exporter = new GexfExporter();
$xml = $exporter->export($graph);
```

Architecture
------------

[](#architecture)

Core interfaces and classes include:

- `GraphInterface`: read-only graph operations.
- `MutableGraphInterface`: graph operations with mutation methods.
- `ExporterInterface`: common export contract.
- `Graph`: mutable graph implementation.
- `SubgraphView`: efficient filtered graph view.
- `Node` and `Edge`: value objects for graph elements.
- `IndexMap`: bidirectional mapping between external node IDs and internal integer indexes.

Testing
-------

[](#testing)

```
composer test
composer test:coverage
composer analyse
```

Use Cases
---------

[](#use-cases)

- Citation and bibliographic networks.
- Knowledge graphs and concept maps.
- Dependency graphs.
- Workflow and state-machine modeling.
- Data visualization exports.
- Route, logistics, and infrastructure graphs.

See Also
--------

[](#see-also)

- [nexus-scholar/graph-algorithms](https://github.com/nexus-scholar/graph-algorithms) - algorithms for centrality, pathfinding, traversal, components, ordering, and minimum spanning trees.
- [nexus-scholar/core](https://github.com/nexus-scholar/core) - Nexus Scholar workflow engine that uses graph packages for citation-network features.
- [nexus-scholar/scholar-graph](https://github.com/nexus-scholar/scholar-graph) - legacy scholarly graph prototype that preceded the current graph packages.

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance97

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~121 days

Total

3

Last Release

18d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d86d4859cd0f7e935dc056ca1155f5842ac8c590ebe8481d3051feb339885d7?d=identicon)[nexus-scholar](/maintainers/nexus-scholar)

---

Top Contributors

[![mbsoft31](https://avatars.githubusercontent.com/u/14237661?v=4)](https://github.com/mbsoft31 "mbsoft31 (15 commits)")[![nexus-scholar](https://avatars.githubusercontent.com/u/233639653?v=4)](https://github.com/nexus-scholar "nexus-scholar (6 commits)")

---

Tags

networkAlgorithmgraphdata structureGraphMLcytoscapegexf

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nexus-scholar-graph-core/health.svg)

```
[![Health](https://phpackages.com/badges/nexus-scholar-graph-core/health.svg)](https://phpackages.com/packages/nexus-scholar-graph-core)
```

###  Alternatives

[clue/graph

GraPHP is the mathematical graph/network library written in PHP.

7144.4M43](/packages/clue-graph)[graphp/graph

GraPHP is the mathematical graph/network library written in PHP.

714305.2k4](/packages/graphp-graph)[mlocati/ip-lib

Handle IPv4, IPv6 addresses and ranges

3127.0M58](/packages/mlocati-ip-lib)[fab2s/nodalflow

A PHP Nodal WorkFlow

16369.0k1](/packages/fab2s-nodalflow)[phonetworks/pho-lib-graph

A general purpose graph library in PHP

556.0k1](/packages/phonetworks-pho-lib-graph)[professional-wiki/network

MediaWiki extension for adding interactive network visualizations to your wiki pages

3213.0k](/packages/professional-wiki-network)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
