# valeragav/drawio-sql-er architecture

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

- Interactive diagram: https://gitdiagram.com/valeragav/drawio-sql-er
- Repository: https://github.com/valeragav/drawio-sql-er

## Overview

drawio-sql-er is a draw.io plugin that turns SQL DDL—or a read-only PostgreSQL schema—into an editable ER diagram. The main workflow is source selection, schema parsing, diagram generation and placement; users can then update, compare, rearrange, highlight, or export the diagram. The README documents all major capabilities. Some implementation excerpts are partial, so edges between components are included only where the excerpts, SOURCE INDEX references, or README support them.

Main entry points: [`src/plugin.js`](https://github.com/valeragav/drawio-sql-er/blob/main/src/plugin.js) (SQL ER plugin), [`src/drawio.js`](https://github.com/valeragav/drawio-sql-er/blob/main/src/drawio.js) (Graph and draw.io XML), [`bridge/introspect.js`](https://github.com/valeragav/drawio-sql-er/blob/main/bridge/introspect.js) (PostgreSQL introspection), [`src/layout.js`](https://github.com/valeragav/drawio-sql-er/blob/main/src/layout.js) (Diagram layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Schema input"]
  node_parser["SQL parser<br/>[parser.js]"]
  node_pgreader["PostgreSQL introspection<br/>[introspect.js]"]
  node_server["Schema API server<br/>[server.js]"]
end

subgraph group_diagram["Diagram generation"]
  node_graph["Graph and draw.io XML<br/>[drawio.js]"]
  node_groups["Schema grouping<br/>[groups.js]"]
  node_layout["Diagram layout<br/>[layout.js]"]
  node_routing["Relationship routing<br/>[routing.js]"]
  node_placement["Page placement<br/>[placement.js]"]
end

subgraph group_operations["Diagram operations"]
  node_page["Page updates and reflow<br/>[page.js]"]
  node_diff["Schema comparison<br/>[diff.js]"]
  node_highlight["Difference highlighting<br/>[highlight.js]"]
  node_legend["Diagram legend<br/>[legend.js]"]
  node_sqlexport["SQL export<br/>[export.js]"]
  node_mermaid["Mermaid export<br/>[mermaid.js]"]
end

subgraph group_plugin["Plugin interface"]
  node_plugin["SQL ER plugin<br/>[plugin.js]"]
  node_selector["Table selection<br/>[select.js]"]
end

node_user(("draw.io user"))
node_db[("PostgreSQL database")]

node_user -->|"provides SQL or commands"| node_plugin
node_plugin -->|"parses SQL"| node_parser
node_plugin -->|"selects tables"| node_selector
node_plugin -.->|"requests schema"| node_pgreader
node_plugin -.->|"requests schema API"| node_server
node_server -->|"reads schema"| node_pgreader
node_pgreader -->|"queries catalogs"| node_db
node_pgreader -->|"produces DDL for"| node_parser
node_plugin -->|"builds diagram"| node_graph
node_graph -->|"computes groups"| node_groups
node_graph -->|"lays out nodes"| node_layout
node_graph -->|"routes links"| node_routing
node_layout -->|"uses groups"| node_groups
node_layout -->|"uses routing"| node_routing
node_plugin -->|"places diagram"| node_placement
node_plugin -->|"updates page"| node_page
node_page -->|"builds replacement graph"| node_graph
node_plugin -->|"compares schemas"| node_diff
node_plugin -->|"highlights differences"| node_highlight
node_plugin -->|"adds legend"| node_legend
node_plugin -->|"exports SQL"| node_sqlexport
node_plugin -->|"exports Mermaid"| node_mermaid

click node_plugin "https://github.com/valeragav/drawio-sql-er/blob/main/src/plugin.js"
click node_parser "https://github.com/valeragav/drawio-sql-er/blob/main/src/parser.js"
click node_pgreader "https://github.com/valeragav/drawio-sql-er/blob/main/bridge/introspect.js"
click node_server "https://github.com/valeragav/drawio-sql-er/blob/main/scripts/server.js"
click node_selector "https://github.com/valeragav/drawio-sql-er/blob/main/src/select.js"
click node_graph "https://github.com/valeragav/drawio-sql-er/blob/main/src/drawio.js"
click node_groups "https://github.com/valeragav/drawio-sql-er/blob/main/src/groups.js"
click node_layout "https://github.com/valeragav/drawio-sql-er/blob/main/src/layout.js"
click node_routing "https://github.com/valeragav/drawio-sql-er/blob/main/src/routing.js"
click node_placement "https://github.com/valeragav/drawio-sql-er/blob/main/src/placement.js"
click node_page "https://github.com/valeragav/drawio-sql-er/blob/main/src/page.js"
click node_diff "https://github.com/valeragav/drawio-sql-er/blob/main/src/diff.js"
click node_highlight "https://github.com/valeragav/drawio-sql-er/blob/main/src/highlight.js"
click node_legend "https://github.com/valeragav/drawio-sql-er/blob/main/src/legend.js"
click node_sqlexport "https://github.com/valeragav/drawio-sql-er/blob/main/src/export.js"
click node_mermaid "https://github.com/valeragav/drawio-sql-er/blob/main/src/mermaid.js"

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_parser,node_pgreader,node_server,node_user toneBlue
class node_graph,node_groups,node_layout,node_routing,node_placement,node_db toneAmber
class node_page,node_diff,node_highlight,node_legend,node_sqlexport,node_mermaid toneMint
class node_plugin,node_selector toneRose
```

## Components

### Schema input

- [SQL parser](https://github.com/valeragav/drawio-sql-er/blob/main/src/parser.js): `src/parser.js`
- [PostgreSQL introspection](https://github.com/valeragav/drawio-sql-er/blob/main/bridge/introspect.js): `bridge/introspect.js`
- [Schema API server](https://github.com/valeragav/drawio-sql-er/blob/main/scripts/server.js): `scripts/server.js`

### Diagram generation

- [Graph and draw.io XML](https://github.com/valeragav/drawio-sql-er/blob/main/src/drawio.js): `src/drawio.js`
- [Schema grouping](https://github.com/valeragav/drawio-sql-er/blob/main/src/groups.js): `src/groups.js`
- [Diagram layout](https://github.com/valeragav/drawio-sql-er/blob/main/src/layout.js): `src/layout.js`
- [Relationship routing](https://github.com/valeragav/drawio-sql-er/blob/main/src/routing.js): `src/routing.js`
- [Page placement](https://github.com/valeragav/drawio-sql-er/blob/main/src/placement.js): `src/placement.js`

### Diagram operations

- [Page updates and reflow](https://github.com/valeragav/drawio-sql-er/blob/main/src/page.js): `src/page.js`
- [Schema comparison](https://github.com/valeragav/drawio-sql-er/blob/main/src/diff.js): `src/diff.js`
- [Difference highlighting](https://github.com/valeragav/drawio-sql-er/blob/main/src/highlight.js): `src/highlight.js`
- [Diagram legend](https://github.com/valeragav/drawio-sql-er/blob/main/src/legend.js): `src/legend.js`
- [SQL export](https://github.com/valeragav/drawio-sql-er/blob/main/src/export.js): `src/export.js`
- [Mermaid export](https://github.com/valeragav/drawio-sql-er/blob/main/src/mermaid.js): `src/mermaid.js`

### Plugin interface

- [SQL ER plugin](https://github.com/valeragav/drawio-sql-er/blob/main/src/plugin.js): `src/plugin.js`
- [Table selection](https://github.com/valeragav/drawio-sql-er/blob/main/src/select.js): `src/select.js`

### Other components

- **draw.io user**
- **PostgreSQL database**

## Connections

- draw.io user → SQL ER plugin: provides SQL or commands (evidence: `README.md`)
- SQL ER plugin → SQL parser: parses SQL (evidence: `src/plugin.js`)
- SQL ER plugin → Table selection: selects tables (evidence: `src/plugin.js`)
- SQL ER plugin → PostgreSQL introspection: requests schema
- SQL ER plugin → Schema API server: requests schema API
- Schema API server → PostgreSQL introspection: reads schema (evidence: `scripts/server.js`)
- PostgreSQL introspection → PostgreSQL database: queries catalogs (evidence: `bridge/introspect.js`)
- PostgreSQL introspection → SQL parser: produces DDL for (evidence: `bridge/introspect.js`)
- SQL ER plugin → Graph and draw.io XML: builds diagram (evidence: `src/plugin.js`)
- Graph and draw.io XML → Schema grouping: computes groups (evidence: `src/drawio.js`)
- Graph and draw.io XML → Diagram layout: lays out nodes (evidence: `src/drawio.js`)
- Graph and draw.io XML → Relationship routing: routes links (evidence: `src/drawio.js`)
- Diagram layout → Schema grouping: uses groups (evidence: `src/layout.js`)
- Diagram layout → Relationship routing: uses routing (evidence: `src/layout.js`)
- SQL ER plugin → Page placement: places diagram (evidence: `src/plugin.js`)
- SQL ER plugin → Page updates and reflow: updates page (evidence: `src/plugin.js`)
- Page updates and reflow → Graph and draw.io XML: builds replacement graph (evidence: `src/page.js`)
- SQL ER plugin → Schema comparison: compares schemas (evidence: `src/plugin.js`)
- SQL ER plugin → Difference highlighting: highlights differences (evidence: `src/plugin.js`)
- SQL ER plugin → Diagram legend: adds legend (evidence: `src/plugin.js`)
- SQL ER plugin → SQL export: exports SQL (evidence: `src/plugin.js`)
- SQL ER plugin → Mermaid export: exports Mermaid (evidence: `src/plugin.js`)
