# coreify/graph architecture

> Architecture diagram of the GitHub repository coreify/graph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coreify/graph
- Repository: https://github.com/coreify/graph

## Overview

@coreify/graph is a headless graph engine with optional React bindings. A client creates or supplies graph data, manages it through the reactive store, and can parse text, arrange or simulate nodes, analyze the graph, serialize it, and persist or observe state through optional integrations. The README documents these capabilities; source excerpts show store delegation, parsing helpers, persistence, and React subscriptions. Worker internals and some subsystem call paths were not excerpted, so uncertain links are omitted or marked unverified.

Main entry points: [`src/core/store.ts`](https://github.com/coreify/graph/blob/main/src/core/store.ts) (Reactive Store), [`src/persist/index.ts`](https://github.com/coreify/graph/blob/main/src/persist/index.ts) (Persistence), [`src/core/text.ts`](https://github.com/coreify/graph/blob/main/src/core/text.ts) (Text Parsing), [`src/core/layouts.ts`](https://github.com/coreify/graph/blob/main/src/core/layouts.ts) (Layout Helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Graph Core"]
  node_store["Reactive Store<br/>[store.ts]"]
  node_text["Text Parsing<br/>[text.ts]"]
  node_layouts["Layout Helpers<br/>[layouts.ts]"]
  node_simulation["Force Simulation<br/>[simulation.ts]"]
end

subgraph group_analysis["Graph Analysis"]
  node_algorithms["Graph Algorithms<br/>[index.ts]"]
end

subgraph group_data["Data Exchange"]
  node_serialization["Serialization<br/>[index.ts]"]
  node_persistence["Persistence<br/>[index.ts]"]
end

subgraph group_integrations["Optional Integrations"]
  node_react["React Hooks<br/>[index.ts]"]
  node_worker["Worker Wrapper<br/>[index.ts]"]
  node_workerthread["Worker Thread<br/>[thread.ts]"]
end

subgraph group_internal["Core Internals"]
  node_types["Graph Types<br/>[types.ts]"]
  node_validation["Validation Helpers<br/>[validation.ts]"]
end

node_client(("Client"))
node_storage[("Browser Storage")]
node_reactconsumer(("React Consumer"))

node_client -->|"creates and updates"| node_store
node_store -->|"parses and generates"| node_text
node_store -->|"applies layouts"| node_layouts
node_store -->|"clamps positions"| node_validation
node_text -->|"parses tokens"| node_validation
node_text -->|"deduplicates edges"| node_layouts
node_store -->|"uses graph state"| node_types
node_layouts -->|"clamps positions"| node_validation
node_algorithms -->|"uses graph types"| node_types
node_client -->|"analyzes graph"| node_algorithms
node_client -->|"simulates positions"| node_simulation
node_simulation -->|"uses graph types"| node_types
node_client -->|"encodes graph state"| node_serialization
node_persistence -->|"serializes state"| node_serialization
node_persistence -->|"restores and subscribes"| node_store
node_persistence -->|"reads and writes"| node_storage
node_reactconsumer -->|"uses hooks"| node_react
node_react -->|"subscribes to state"| node_store
node_client -->|"runs simulation off-thread"| node_worker
node_worker -.->|"dispatches simulation"| node_workerthread
node_workerthread -.->|"uses simulation engine"| node_simulation

click node_store "https://github.com/coreify/graph/blob/main/src/core/store.ts"
click node_text "https://github.com/coreify/graph/blob/main/src/core/text.ts"
click node_layouts "https://github.com/coreify/graph/blob/main/src/core/layouts.ts"
click node_simulation "https://github.com/coreify/graph/blob/main/src/core/simulation.ts"
click node_types "https://github.com/coreify/graph/blob/main/src/core/types.ts"
click node_validation "https://github.com/coreify/graph/blob/main/src/core/helpers/validation.ts"
click node_algorithms "https://github.com/coreify/graph/blob/main/src/algorithms/index.ts"
click node_serialization "https://github.com/coreify/graph/blob/main/src/serialization/index.ts"
click node_persistence "https://github.com/coreify/graph/blob/main/src/persist/index.ts"
click node_react "https://github.com/coreify/graph/blob/main/src/react/index.ts"
click node_worker "https://github.com/coreify/graph/blob/main/src/worker/index.ts"
click node_workerthread "https://github.com/coreify/graph/blob/main/src/worker/thread.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_store,node_text,node_layouts,node_simulation,node_client toneBlue
class node_algorithms,node_storage toneAmber
class node_serialization,node_persistence toneMint
class node_react,node_worker,node_workerthread toneRose
class node_types,node_validation,node_reactconsumer toneIndigo
```

## Components

### Graph Core

- [Reactive Store](https://github.com/coreify/graph/blob/main/src/core/store.ts): `src/core/store.ts`
- [Text Parsing](https://github.com/coreify/graph/blob/main/src/core/text.ts): `src/core/text.ts`
- [Layout Helpers](https://github.com/coreify/graph/blob/main/src/core/layouts.ts): `src/core/layouts.ts`
- [Force Simulation](https://github.com/coreify/graph/blob/main/src/core/simulation.ts): `src/core/simulation.ts`

### Graph Analysis

- [Graph Algorithms](https://github.com/coreify/graph/blob/main/src/algorithms/index.ts): `src/algorithms/index.ts`

### Data Exchange

- [Serialization](https://github.com/coreify/graph/blob/main/src/serialization/index.ts): `src/serialization/index.ts`
- [Persistence](https://github.com/coreify/graph/blob/main/src/persist/index.ts): `src/persist/index.ts`

### Optional Integrations

- [React Hooks](https://github.com/coreify/graph/blob/main/src/react/index.ts): `src/react/index.ts`
- [Worker Wrapper](https://github.com/coreify/graph/blob/main/src/worker/index.ts): `src/worker/index.ts`
- [Worker Thread](https://github.com/coreify/graph/blob/main/src/worker/thread.ts): `src/worker/thread.ts`

### Core Internals

- [Graph Types](https://github.com/coreify/graph/blob/main/src/core/types.ts): `src/core/types.ts`
- [Validation Helpers](https://github.com/coreify/graph/blob/main/src/core/helpers/validation.ts): `src/core/helpers/validation.ts`

### Other components

- **Client**
- **Browser Storage**
- **React Consumer**

## Connections

- Client → Reactive Store: creates and updates (evidence: `README.md`)
- Reactive Store → Text Parsing: parses and generates (evidence: `src/core/store.ts`)
- Reactive Store → Layout Helpers: applies layouts (evidence: `src/core/store.ts`)
- Reactive Store → Validation Helpers: clamps positions (evidence: `src/core/store.ts`)
- Text Parsing → Validation Helpers: parses tokens (evidence: `src/core/text.ts`)
- Text Parsing → Layout Helpers: deduplicates edges (evidence: `src/core/text.ts`)
- Reactive Store → Graph Types: uses graph state (evidence: `src/core/store.ts`)
- Layout Helpers → Validation Helpers: clamps positions (evidence: `src/core/layouts.ts`)
- Graph Algorithms → Graph Types: uses graph types (evidence: `src/algorithms/index.ts`)
- Client → Graph Algorithms: analyzes graph (evidence: `README.md`)
- Client → Force Simulation: simulates positions (evidence: `README.md`)
- Force Simulation → Graph Types: uses graph types (evidence: `src/core/simulation.ts`)
- Client → Serialization: encodes graph state (evidence: `README.md`)
- Persistence → Serialization: serializes state (evidence: `src/persist/index.ts`)
- Persistence → Reactive Store: restores and subscribes (evidence: `src/persist/index.ts`)
- Persistence → Browser Storage: reads and writes (evidence: `src/persist/index.ts`)
- React Consumer → React Hooks: uses hooks (evidence: `README.md`)
- React Hooks → Reactive Store: subscribes to state (evidence: `src/react/index.ts`)
- Client → Worker Wrapper: runs simulation off-thread (evidence: `README.md`)
- Worker Wrapper → Worker Thread: dispatches simulation
- Worker Thread → Force Simulation: uses simulation engine (evidence: `src/worker/thread.ts`)
