# erikbrinkman/d3-dag architecture

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

- Interactive diagram: https://gitdiagram.com/erikbrinkman/d3-dag
- Repository: https://github.com/erikbrinkman/d3-dag

## Overview

d3-dag is a TypeScript library for laying out directed acyclic graphs. A caller creates or parses a graph, chooses a layout operator (including the dagre-compatible adapter), and receives node coordinates and link points on the graph. The Sugiyama operator assigns layers, reduces crossings, then assigns coordinates; Grid and Zherebko offer alternative layouts. The graph API also supports construction, traversal, and serialization. Several algorithm-family connections are documented or visible through imports, but their internal calls were not sampled, so those links are marked unverified.

Main entry points: [`src/sugiyama/index.ts`](https://github.com/erikbrinkman/d3-dag/blob/main/src/sugiyama/index.ts) (Sugiyama layout), [`src/dagre.ts`](https://github.com/erikbrinkman/d3-dag/blob/main/src/dagre.ts) (Dagre adapter), [`src/grid/index.ts`](https://github.com/erikbrinkman/d3-dag/blob/main/src/grid/index.ts) (Grid layout), [`src/zherebko/index.ts`](https://github.com/erikbrinkman/d3-dag/blob/main/src/zherebko/index.ts) (Zherebko layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_graph["Graph model"]
  node_graph_model["DAG model<br/>[index.ts]"]
  node_graph_builders["Graph builders"]
  node_graph_json["Graph JSON<br/>[json.ts]"]
end

subgraph group_api["Layout APIs"]
  node_dagre["Dagre adapter<br/>[dagre.ts]"]
  node_sugiyama_layout["Sugiyama layout<br/>[index.ts]"]
end

subgraph group_sugiyama["Sugiyama stages"]
  node_layering["Layer assignment"]
  node_sugify["Layer expansion<br/>[sugify.ts]"]
  node_decross["Crossing reduction"]
  node_coordinates["Coordinate assignment"]
end

subgraph group_alternatives["Alternative layouts"]
  node_grid_layout["Grid layout<br/>[index.ts]"]
  node_zherebko_layout["Zherebko layout<br/>[index.ts]"]
  node_grid_lanes["Grid lane ordering"]
  node_zherebko_order["Topological ordering<br/>[greedy.ts]"]
end

subgraph group_internal["Shared utilities"]
  node_layout_support["Layout sizing<br/>[layout.ts]"]
  node_tweaks["Layout tweaks<br/>[tweaks.ts]"]
  node_iterators["Iterator helpers<br/>[iters.ts]"]
  node_collections["Collection helpers<br/>[collections.ts]"]
end

node_caller(("Library caller"))
node_layout_result["Laid-out graph"]

node_caller -->|"builds or parses"| node_graph_builders
node_graph_builders -->|"creates"| node_graph_model
node_caller -->|"chooses adapter"| node_dagre
node_caller -->|"chooses operator"| node_sugiyama_layout
node_caller -->|"chooses operator"| node_grid_layout
node_caller -->|"chooses operator"| node_zherebko_layout
node_dagre -->|"uses graph"| node_graph_model
node_dagre -->|"delegates layout"| node_sugiyama_layout
node_dagre -->|"delegates layout"| node_grid_layout
node_sugiyama_layout -->|"assigns layers"| node_layering
node_sugiyama_layout -->|"expands layers"| node_sugify
node_sugiyama_layout -->|"reduces crossings"| node_decross
node_sugiyama_layout -->|"assigns coordinates"| node_coordinates
node_grid_layout -->|"orders lanes"| node_grid_lanes
node_zherebko_layout -->|"orders nodes"| node_zherebko_order
node_sugiyama_layout -->|"uses sizing"| node_layout_support
node_grid_layout -->|"applies tweaks"| node_tweaks
node_sugiyama_layout -.->|"applies tweaks"| node_tweaks
node_zherebko_layout -.->|"applies tweaks"| node_tweaks
node_graph_model -->|"serializes through"| node_graph_json
node_sugiyama_layout -->|"returns layout"| node_layout_result
node_grid_layout -->|"returns layout"| node_layout_result
node_zherebko_layout -->|"returns layout"| node_layout_result
node_dagre -->|"returns layout"| node_layout_result
node_layering -.->|"uses helpers"| node_iterators
node_decross -.->|"uses helpers"| node_iterators
node_coordinates -.->|"uses helpers"| node_iterators
node_graph_model -->|"uses collections"| node_collections

click node_graph_model "https://github.com/erikbrinkman/d3-dag/blob/main/src/graph/index.ts"
click node_graph_builders "https://github.com/erikbrinkman/d3-dag/tree/main/src/graph"
click node_graph_json "https://github.com/erikbrinkman/d3-dag/blob/main/src/graph/json.ts"
click node_dagre "https://github.com/erikbrinkman/d3-dag/blob/main/src/dagre.ts"
click node_sugiyama_layout "https://github.com/erikbrinkman/d3-dag/blob/main/src/sugiyama/index.ts"
click node_grid_layout "https://github.com/erikbrinkman/d3-dag/blob/main/src/grid/index.ts"
click node_zherebko_layout "https://github.com/erikbrinkman/d3-dag/blob/main/src/zherebko/index.ts"
click node_layering "https://github.com/erikbrinkman/d3-dag/tree/main/src/sugiyama/layering"
click node_sugify "https://github.com/erikbrinkman/d3-dag/blob/main/src/sugiyama/sugify.ts"
click node_decross "https://github.com/erikbrinkman/d3-dag/tree/main/src/sugiyama/decross"
click node_coordinates "https://github.com/erikbrinkman/d3-dag/tree/main/src/sugiyama/coord"
click node_grid_lanes "https://github.com/erikbrinkman/d3-dag/tree/main/src/grid/lane"
click node_zherebko_order "https://github.com/erikbrinkman/d3-dag/blob/main/src/zherebko/greedy.ts"
click node_layout_support "https://github.com/erikbrinkman/d3-dag/blob/main/src/layout.ts"
click node_tweaks "https://github.com/erikbrinkman/d3-dag/blob/main/src/tweaks.ts"
click node_iterators "https://github.com/erikbrinkman/d3-dag/blob/main/src/iters.ts"
click node_collections "https://github.com/erikbrinkman/d3-dag/blob/main/src/collections.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_graph_model,node_graph_builders,node_graph_json toneBlue
class node_dagre,node_sugiyama_layout toneAmber
class node_layering,node_sugify,node_decross,node_coordinates toneMint
class node_grid_layout,node_zherebko_layout,node_grid_lanes,node_zherebko_order toneRose
class node_layout_support,node_tweaks,node_iterators,node_collections,node_caller,node_layout_result toneIndigo
```

## Components

### Graph model

- [DAG model](https://github.com/erikbrinkman/d3-dag/blob/main/src/graph/index.ts): `src/graph/index.ts`
- [Graph builders](https://github.com/erikbrinkman/d3-dag/tree/main/src/graph): `src/graph`
- [Graph JSON](https://github.com/erikbrinkman/d3-dag/blob/main/src/graph/json.ts): `src/graph/json.ts`

### Layout APIs

- [Dagre adapter](https://github.com/erikbrinkman/d3-dag/blob/main/src/dagre.ts): `src/dagre.ts`
- [Sugiyama layout](https://github.com/erikbrinkman/d3-dag/blob/main/src/sugiyama/index.ts): `src/sugiyama/index.ts`

### Sugiyama stages

- [Layer assignment](https://github.com/erikbrinkman/d3-dag/tree/main/src/sugiyama/layering): `src/sugiyama/layering`
- [Layer expansion](https://github.com/erikbrinkman/d3-dag/blob/main/src/sugiyama/sugify.ts): `src/sugiyama/sugify.ts`
- [Crossing reduction](https://github.com/erikbrinkman/d3-dag/tree/main/src/sugiyama/decross): `src/sugiyama/decross`
- [Coordinate assignment](https://github.com/erikbrinkman/d3-dag/tree/main/src/sugiyama/coord): `src/sugiyama/coord`

### Alternative layouts

- [Grid layout](https://github.com/erikbrinkman/d3-dag/blob/main/src/grid/index.ts): `src/grid/index.ts`
- [Zherebko layout](https://github.com/erikbrinkman/d3-dag/blob/main/src/zherebko/index.ts): `src/zherebko/index.ts`
- [Grid lane ordering](https://github.com/erikbrinkman/d3-dag/tree/main/src/grid/lane): `src/grid/lane`
- [Topological ordering](https://github.com/erikbrinkman/d3-dag/blob/main/src/zherebko/greedy.ts): `src/zherebko/greedy.ts`

### Shared utilities

- [Layout sizing](https://github.com/erikbrinkman/d3-dag/blob/main/src/layout.ts): `src/layout.ts`
- [Layout tweaks](https://github.com/erikbrinkman/d3-dag/blob/main/src/tweaks.ts): `src/tweaks.ts`
- [Iterator helpers](https://github.com/erikbrinkman/d3-dag/blob/main/src/iters.ts): `src/iters.ts`
- [Collection helpers](https://github.com/erikbrinkman/d3-dag/blob/main/src/collections.ts): `src/collections.ts`

### Other components

- **Library caller**
- **Laid-out graph**

## Connections

- Library caller → Graph builders: builds or parses (evidence: `README.md`)
- Graph builders → DAG model: creates (evidence: `src/graph/stratify.ts`)
- Library caller → Dagre adapter: chooses adapter (evidence: `README.md`)
- Library caller → Sugiyama layout: chooses operator (evidence: `README.md`)
- Library caller → Grid layout: chooses operator (evidence: `README.md`)
- Library caller → Zherebko layout: chooses operator (evidence: `README.md`)
- Dagre adapter → DAG model: uses graph (evidence: `src/dagre.ts`)
- Dagre adapter → Sugiyama layout: delegates layout (evidence: `src/dagre.ts`)
- Dagre adapter → Grid layout: delegates layout (evidence: `src/dagre.ts`)
- Sugiyama layout → Layer assignment: assigns layers (evidence: `src/sugiyama/index.ts`)
- Sugiyama layout → Layer expansion: expands layers (evidence: `src/sugiyama/index.ts`)
- Sugiyama layout → Crossing reduction: reduces crossings (evidence: `src/sugiyama/index.ts`)
- Sugiyama layout → Coordinate assignment: assigns coordinates (evidence: `src/sugiyama/index.ts`)
- Grid layout → Grid lane ordering: orders lanes (evidence: `src/grid/index.ts`)
- Zherebko layout → Topological ordering: orders nodes (evidence: `src/zherebko/index.ts`)
- Sugiyama layout → Layout sizing: uses sizing (evidence: `src/sugiyama/index.ts`)
- Grid layout → Layout tweaks: applies tweaks (evidence: `src/grid/index.ts`)
- Sugiyama layout → Layout tweaks: applies tweaks (evidence: `src/sugiyama/index.ts`)
- Zherebko layout → Layout tweaks: applies tweaks (evidence: `src/zherebko/index.ts`)
- DAG model → Graph JSON: serializes through (evidence: `src/graph/index.ts`)
- Sugiyama layout → Laid-out graph: returns layout (evidence: `README.md`)
- Grid layout → Laid-out graph: returns layout (evidence: `README.md`)
- Zherebko layout → Laid-out graph: returns layout (evidence: `README.md`)
- Dagre adapter → Laid-out graph: returns layout (evidence: `README.md`)
- Layer assignment → Iterator helpers: uses helpers (evidence: `src/sugiyama/layering/simplex.ts`)
- Crossing reduction → Iterator helpers: uses helpers (evidence: `src/sugiyama/decross/opt.ts`)
- Coordinate assignment → Iterator helpers: uses helpers (evidence: `src/sugiyama/coord/simplex.ts`)
- DAG model → Collection helpers: uses collections (evidence: `src/graph/index.ts`)
