modscape 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -270,7 +270,6 @@ modscape export ./models -o docs/ARCHITECTURE.md
270
270
 
271
271
  Modscape は以下の素晴らしいオープンソースプロジェクトによって支えられています:
272
272
 
273
- - [React Flow](https://reactflow.dev/) - インタラクティブなグラフ UI フレームワーク。
274
273
  - [CodeMirror 6](https://codemirror.net/) - 次世代のウェブベース・コードエディタ。
275
274
  - [Dagre](https://github.com/dagrejs/dagre) - 階層型グラフ・レイアウトエンジン。
276
275
  - [Lucide React](https://lucide.dev/) - シンプルで美しいアイコンセット。
package/README.md CHANGED
@@ -261,7 +261,6 @@ modscape export ./models -o docs/ARCHITECTURE.md
261
261
 
262
262
  Modscape is made possible by these incredible open-source projects:
263
263
 
264
- - [React Flow](https://reactflow.dev/) - Interactive node-based UI framework.
265
264
  - [CodeMirror 6](https://codemirror.net/) - Next-generation code editor for the web.
266
265
  - [Dagre](https://github.com/dagrejs/dagre) - Directed graph layout engine.
267
266
  - [Lucide React](https://lucide.dev/) - Beautifully simple pixel-perfect icons.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modscape",
3
- "version": "1.3.0",
3
+ "version": "2.0.0",
4
4
  "description": "Modscape: A YAML-driven data modeling visualizer CLI",
5
5
  "repository": {
6
6
  "type": "git",
package/src/export.js CHANGED
@@ -67,16 +67,13 @@ function generateMermaidLineage(schema) {
67
67
  let mermaid = 'graph TD\n';
68
68
  let hasLineage = false;
69
69
 
70
- schema.tables.forEach(table => {
71
- if (table.lineage?.upstream && table.lineage.upstream.length > 0) {
72
- hasLineage = true;
73
- const targetName = sanitize(table.name);
74
- table.lineage.upstream.forEach(upId => {
75
- const sourceTable = schema.tables.find(t => t.id === upId);
76
- const sourceName = sanitize(sourceTable?.name || upId);
77
- mermaid += ` ${sourceName} --> ${targetName}\n`;
78
- });
79
- }
70
+ (schema.lineage || []).forEach(edge => {
71
+ hasLineage = true;
72
+ const sourceTable = schema.tables.find(t => t.id === edge.from);
73
+ const targetTable = schema.tables.find(t => t.id === edge.to);
74
+ const sourceName = sanitize(sourceTable?.name || edge.from);
75
+ const targetName = sanitize(targetTable?.name || edge.to);
76
+ mermaid += ` ${sourceName} --> ${targetName}\n`;
80
77
  });
81
78
 
82
79
  return hasLineage ? mermaid : null;
@@ -197,10 +194,11 @@ export function generateMarkdown(schema, modelName) {
197
194
  }
198
195
 
199
196
  // Lineage
200
- if (table.lineage?.upstream?.length > 0) {
201
- const upstreamNames = table.lineage.upstream.map(upId => {
202
- const t = schema.tables.find(t => t.id === upId);
203
- return t ? t.name : upId;
197
+ const upstreamEdges = (schema.lineage || []).filter(e => e.to === table.id);
198
+ if (upstreamEdges.length > 0) {
199
+ const upstreamNames = upstreamEdges.map(e => {
200
+ const t = schema.tables.find(t => t.id === e.from);
201
+ return t ? t.name : e.from;
204
202
  });
205
203
  md += `**Upstream**: ${upstreamNames.map(n => `\`${n}\``).join(' → ')}\n\n`;
206
204
  }
package/src/import-dbt.js CHANGED
@@ -34,6 +34,7 @@ export async function importDbt(projectDir, options) {
34
34
  console.log(` 🔍 Parsing dbt manifest: ${manifestPath}`);
35
35
 
36
36
  const tables = [];
37
+ const lineage = [];
37
38
  const domainsMap = new Map();
38
39
  const tableSplitKeyMap = new Map();
39
40
 
@@ -66,7 +67,6 @@ export async function importDbt(projectDir, options) {
66
67
  appearance: { type: 'table' },
67
68
  conceptual: { description: node.description || '' },
68
69
  columns,
69
- lineage: { upstream: [] }
70
70
  };
71
71
 
72
72
  tables.push(tableEntry);
@@ -92,13 +92,12 @@ export async function importDbt(projectDir, options) {
92
92
  }
93
93
 
94
94
  // lineage
95
- for (const [uniqueId, node] of Object.entries(allNodes)) {
95
+ for (const [, node] of Object.entries(allNodes)) {
96
96
  if (!['model', 'seed', 'snapshot', 'source'].includes(node.resource_type)) continue;
97
- const tableEntry = tables.find(t => t.id === node.unique_id);
98
- if (tableEntry && node.depends_on?.nodes) {
97
+ if (node.depends_on?.nodes) {
99
98
  for (const upstreamId of node.depends_on.nodes) {
100
99
  if (allNodes[upstreamId]) {
101
- tableEntry.lineage.upstream.push(upstreamId);
100
+ lineage.push({ from: upstreamId, to: node.unique_id });
102
101
  }
103
102
  }
104
103
  }
@@ -122,11 +121,10 @@ export async function importDbt(projectDir, options) {
122
121
  const tableIds = new Set(splitTables.map(t => t.id));
123
122
  let internal = 0;
124
123
  let external = 0;
125
- for (const table of splitTables) {
126
- for (const upstreamId of table.lineage?.upstream || []) {
127
- if (tableIds.has(upstreamId)) internal++;
128
- else external++;
129
- }
124
+ for (const edge of lineage) {
125
+ if (!tableIds.has(edge.to)) continue;
126
+ if (tableIds.has(edge.from)) internal++;
127
+ else external++;
130
128
  }
131
129
  const total = internal + external;
132
130
  const rate = total > 0 ? Math.round(internal / total * 100) : 100;
@@ -145,9 +143,12 @@ export async function importDbt(projectDir, options) {
145
143
  tables: d.tables.filter(tid => splitTables.some(t => t.id === tid))
146
144
  }));
147
145
 
146
+ const splitTableIds = new Set(splitTables.map(t => t.id));
147
+ const splitLineage = lineage.filter(e => splitTableIds.has(e.from) || splitTableIds.has(e.to));
148
148
  const outputModel = {
149
149
  tables: splitTables,
150
150
  relationships: [],
151
+ lineage: splitLineage,
151
152
  domains: splitDomains
152
153
  };
153
154
 
@@ -167,6 +168,7 @@ export async function importDbt(projectDir, options) {
167
168
  const outputModel = {
168
169
  tables,
169
170
  relationships: [],
171
+ lineage,
170
172
  domains: Array.from(domainsMap.values())
171
173
  };
172
174
 
package/src/sync-dbt.js CHANGED
@@ -59,15 +59,6 @@ export async function syncDbt(projectDir, options) {
59
59
  }
60
60
  }
61
61
 
62
- const lineageUpstream = [];
63
- if (node.depends_on?.nodes) {
64
- for (const upstreamId of node.depends_on.nodes) {
65
- if (allNodes[upstreamId]) {
66
- lineageUpstream.push(upstreamId);
67
- }
68
- }
69
- }
70
-
71
62
  latestTablesMap.set(tableId, {
72
63
  id: tableId,
73
64
  name: node.name,
@@ -76,7 +67,6 @@ export async function syncDbt(projectDir, options) {
76
67
  appearance: { type: 'table' },
77
68
  conceptual: { description: node.description || '' },
78
69
  columns,
79
- lineage: { upstream: lineageUpstream }
80
70
  });
81
71
  }
82
72
 
@@ -112,11 +102,24 @@ export async function syncDbt(projectDir, options) {
112
102
  physical_name: latest.physical_name,
113
103
  conceptual: latest.conceptual,
114
104
  columns: latest.columns,
115
- lineage: latest.lineage
116
105
  };
117
106
  });
118
107
 
119
- const updated = { ...existing, tables: newTables };
108
+ // Rebuild lineage from manifest for tables in this file
109
+ const fileTableIds = new Set(newTables.map(t => t.id));
110
+ const newLineage = [];
111
+ for (const [, node] of Object.entries(allNodes)) {
112
+ if (!fileTableIds.has(node.unique_id)) continue;
113
+ if (node.depends_on?.nodes) {
114
+ for (const upstreamId of node.depends_on.nodes) {
115
+ if (allNodes[upstreamId]) {
116
+ newLineage.push({ from: upstreamId, to: node.unique_id });
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ const updated = { ...existing, tables: newTables, lineage: newLineage };
120
123
  fs.writeFileSync(yamlPath, yaml.dump(updated), 'utf8');
121
124
  console.log(` 📄 Updated: ${yamlPath}`);
122
125
  }
@@ -8,11 +8,14 @@ Read this file alongside `.modscape/rules.md` (which defines the YAML schema) be
8
8
 
9
9
  ## 1. Dependency Order (DAG)
10
10
 
11
- Use `lineage.upstream` to determine build order. Always generate upstream models before downstream ones.
11
+ Use the top-level `lineage` section to determine build order. Always generate upstream (`from`) models before downstream (`to`) ones.
12
12
 
13
13
  ```yaml
14
14
  lineage:
15
- upstream: [stg_orders, stg_order_items] # these must be generated first
15
+ - from: stg_orders # must be generated first
16
+ to: fct_orders
17
+ - from: stg_order_items # must be generated first
18
+ to: fct_orders
16
19
  ```
17
20
 
18
21
  In dbt this becomes `{{ ref('stg_orders') }}`. In SQLMesh, `MODEL (... grain [...])` with `@this_model` references. Apply the equivalent pattern for your target tool.
@@ -123,7 +126,7 @@ Common TODO patterns:
123
126
 
124
127
  ## 8. Physical Table Names
125
128
 
126
- When `physical_name` is set on a table, use it as the actual table name in DDL or config blocks. The `id` field is the logical reference name used in `ref()` calls and `lineage.upstream`.
129
+ When `physical_name` is set on a table, use it as the actual table name in DDL or config blocks. The `id` field is the logical reference name used in `ref()` calls and the `lineage` section.
127
130
 
128
131
  ---
129
132
 
@@ -8,9 +8,9 @@
8
8
  ## QUICK REFERENCE (read this first)
9
9
 
10
10
  ```
11
- ROOT KEYS domains | tables | relationships | annotations | layout
11
+ ROOT KEYS domains | tables | relationships | lineage | annotations | layout
12
12
  COORDINATES ONLY in `layout`. NEVER inside tables or domains.
13
- LINEAGE Use lineage.upstream (not relationships) for mart/aggregated tables.
13
+ LINEAGE Use top-level `lineage` section (not relationships, not table.lineage.upstream).
14
14
  parentId Declare a table's domain membership inside layout, not inside domains.
15
15
  IDs Every object (table, domain, annotation) needs a unique `id`.
16
16
  sampleData First row = column IDs. At least 3 realistic data rows.
@@ -27,6 +27,7 @@ A valid `model.yaml` has exactly these top-level keys.
27
27
  domains: # (array) visual containers — OPTIONAL but recommended
28
28
  tables: # (array) entity definitions — REQUIRED
29
29
  relationships: # (array) ER cardinality edges — OPTIONAL
30
+ lineage: # (array) data lineage edges — OPTIONAL
30
31
  annotations: # (array) sticky notes / callouts — OPTIONAL
31
32
  layout: # (object) ALL coordinates — REQUIRED if any objects exist
32
33
  ```
@@ -140,17 +141,15 @@ relationships:
140
141
 
141
142
  ## 4. Data Lineage
142
143
 
143
- `lineage.upstream` declares which source tables a derived table is built from.
144
- This is rendered as animated arrows in **Lineage Mode**. It is separate from ER relationships.
144
+ Top-level `lineage` section declares data flow between tables (which source tables feed which derived tables).
145
+ This is rendered as dashed arrows in **Lineage Mode**. It is separate from ER relationships.
145
146
 
146
147
  ```yaml
147
- tables:
148
- - id: mart_revenue
149
- appearance: { type: mart }
150
- lineage:
151
- upstream:
152
- - fct_orders # list of source table IDs
153
- - dim_dates
148
+ lineage:
149
+ - from: fct_orders # source table id
150
+ to: mart_revenue # derived table id
151
+ - from: dim_dates
152
+ to: mart_revenue
154
153
  ```
155
154
 
156
155
  ### When to use lineage vs relationships
@@ -158,21 +157,21 @@ tables:
158
157
  | Situation | Use |
159
158
  |-----------|-----|
160
159
  | `dim_customers` → `fct_orders` (FK join) | `relationships` |
161
- | `fct_orders` + `dim_dates` → `mart_revenue` (aggregation) | `lineage.upstream` |
160
+ | `fct_orders` + `dim_dates` → `mart_revenue` (aggregation) | `lineage` |
162
161
 
163
- **MUST** define `lineage.upstream` for every `mart` or aggregated table.
164
- **MUST NOT** define `lineage.upstream` for raw tables (`fact`, `dimension`, `hub`, `link`, `satellite`).
165
- **MUST NOT** add a `relationships` entry for a connection already expressed in `lineage.upstream`.
162
+ **MUST** define `lineage` entries for every `mart` or aggregated table.
163
+ **MUST NOT** define `lineage` entries for raw tables (`fact`, `dimension`, `hub`, `link`, `satellite`) as sources.
164
+ **MUST NOT** add a `relationships` entry for a connection already expressed in `lineage`.
166
165
 
167
166
  #### Example: correct separation
168
167
 
169
168
  ```yaml
170
169
  # CORRECT
171
- tables:
172
- - id: mart_revenue
173
- appearance: { type: mart }
174
- lineage:
175
- upstream: [fct_orders, dim_dates] # lineage only
170
+ lineage:
171
+ - from: fct_orders
172
+ to: mart_revenue
173
+ - from: dim_dates
174
+ to: mart_revenue
176
175
 
177
176
  relationships:
178
177
  - from: { table: dim_customers, column: customer_key }
@@ -409,11 +408,9 @@ relationships:
409
408
 
410
409
  ```yaml
411
410
  # CORRECT
412
- tables:
413
- - id: mart_revenue
414
- appearance: { type: mart }
415
- lineage:
416
- upstream: [fct_orders] # ✅ express lineage here
411
+ lineage:
412
+ - from: fct_orders
413
+ to: mart_revenue # express lineage in the top-level lineage section
417
414
  ```
418
415
 
419
416
  ---
@@ -663,10 +660,6 @@ tables:
663
660
  logical_name: "Executive Revenue Summary"
664
661
  physical_name: "mart_finance_monthly_revenue_agg"
665
662
  appearance: { type: mart, icon: "📈" }
666
- lineage: # mart → use lineage, not relationships
667
- upstream:
668
- - fct_orders
669
- - dim_customers
670
663
  implementation:
671
664
  materialization: table
672
665
  grain: [month_key]
@@ -684,6 +677,12 @@ tables:
684
677
  - ["2024-02", 15200.00]
685
678
  - ["2024-03", 18900.75]
686
679
 
680
+ lineage: # data flow — separate from ER
681
+ - from: fct_orders
682
+ to: mart_monthly_revenue
683
+ - from: dim_customers
684
+ to: mart_monthly_revenue
685
+
687
686
  relationships: # ER only — not for lineage
688
687
  - from: { table: dim_customers, column: customer_key }
689
688
  to: { table: fct_orders, column: customer_key }
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "visualizer",
3
3
  "private": true,
4
- "version": "1.3.0",
4
+ "version": "2.0.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
8
8
  "build": "tsc -b && vite build",
9
9
  "lint": "eslint .",
10
- "preview": "vite preview"
10
+ "preview": "vite preview",
11
+ "test": "vitest run"
11
12
  },
12
13
  "dependencies": {
13
14
  "@codemirror/lang-yaml": "^6.1.2",
@@ -19,13 +20,16 @@
19
20
  "class-variance-authority": "^0.7.1",
20
21
  "clsx": "^2.1.1",
21
22
  "codemirror": "^6.0.2",
23
+ "cytoscape": "^3.33.1",
24
+ "cytoscape-dagre": "^2.5.0",
25
+ "cytoscape-dom-node": "^1.2.0",
26
+ "cytoscape-edgehandles": "^4.0.1",
22
27
  "dagre": "^0.8.5",
23
28
  "html-to-image": "^1.11.13",
24
29
  "js-yaml": "^4.1.1",
25
30
  "lucide-react": "^0.575.0",
26
31
  "react": "^19.2.0",
27
32
  "react-dom": "^19.2.0",
28
- "reactflow": "^11.11.4",
29
33
  "tailwind-merge": "^3.5.0",
30
34
  "zustand": "^5.0.11"
31
35
  },
@@ -46,6 +50,7 @@
46
50
  "tailwindcss": "^3.4.19",
47
51
  "typescript": "~5.9.3",
48
52
  "typescript-eslint": "^8.48.0",
49
- "vite": "^7.3.1"
53
+ "vite": "^7.3.1",
54
+ "vitest": "^4.1.0"
50
55
  }
51
56
  }