graph README

The project's README from github.com/statelyai/graph. As one markdown file: README.md.

@statelyai/graph

Graphs as plain JSON, with the algorithms, formats, and layout engines to do real work with them.

A graph is just { nodes, edges } data, and every operation is a standalone, tree-shakable function. Built and used by Stately to power its visual tooling for complex systems.

Documentation

Why @statelyai/graph?

Installation

npm install @statelyai/graph

Quick start

Create a publishing workflow and find the shortest route from draft to published:

import { createGraph, getShortestPath } from '@statelyai/graph';

const graph = createGraph({
  nodes: [
    { id: 'draft' },
    { id: 'review' },
    { id: 'published' },
  ],
  edges: [
    { id: 'submit', sourceId: 'draft', targetId: 'review' },
    { id: 'approve', sourceId: 'review', targetId: 'published' },
  ],
});

const path = getShortestPath(graph, { from: 'draft', to: 'published' });

if (path) {
  console.log([path.source.id, ...path.steps.map(({ node }) => node.id)]);
  // ['draft', 'review', 'published']
}

For guides, API details, and adapter dependencies, see the docs. To contribute, see CONTRIBUTING.md.

Inspiration

Inspired by NetworkX, Graphology, and graphlib.

License

MIT

graph (statelyai/graph)

Searching Database…

249 ·GitHub
What is this?A TypeScript library providing universal utilities for working with graphs: a plain {nodes, edges} JSON data model plus algorithms, format converters, and layout engines to actually use that data.
Is this a library I import, or a standalone app?It is a library: every operation is a standalone, tree-shakable function you import, not a framework or GUI tool.
How do I add it to a project?Install the package from npm and import the specific functions or adapters you need via optional subpath imports.
Do I need anything besides Node/npm to use it?Just a JS/TS environment; format converters and layout engines (Graphviz, ELK, dagre, etc.) are optional adapters pulled in only if you use them.
Is every format and layout engine bundled in by default?No, the core package only covers the data model and algorithms; each of the 14 formats and 8 layout engines is a separate optional adapter with its own dependencies.
Who would actually need this?Developers building diagram editors, node editors, statecharts, or architecture-visualization tools who need a fast, serializable graph model with real algorithms.
Why is it fast compared to libraries like graphology?It stores graphs as plain JSON with transparent indexed lookups instead of class instances, which the README says makes it 9-15x faster than graphology at building a 100k-node graph.
Can it turn XState state machines into graphs?Yes, it was built by Stately and includes an adapter to turn XState machines into graphs.
What kinds of algorithms are included?Shortest paths, centrality, communities, flow, matching, and isomorphism, all tested against edge cases like self-loops and parallel edges, implemented iteratively so deep graphs won't overflow the stack.
Is the graph data strongly typed?Yes, it uses generic types end to end for nodes, edges, ports, and the graph itself.
What are similar projects?networkx, cytoscape.js, G6, uPlot, LogicFlow, rete, Chart.js, liteparse
Creator
statelyai
Size
1.8 MB
Stars
249
Age
8mo
Commits · 90 Days