Generate an ER diagram from a SQL schema.
Foreign keys already record the relationships. An ER diagram is a rendering of constraints the database is enforcing anyway.
What it reads
A schema dump, or the migration files if that is what exists, which is more common in application repositories than a checked-in schema. CREATE TABLE gives the entities and their columns, foreign key constraints give the relationships and their direction, unique constraints and indexes indicate which columns matter for access, and NOT NULL together with the key definition determines whether a relationship is optional.
How tables become entities
Each table is an entity. Foreign keys become relationships, with cardinality read from the constraints rather than guessed: a unique foreign key is one-to-one, an ordinary one is one-to-many, and a table whose primary key is composed entirely of foreign keys is recognised as a join table and drawn as a many-to-many relationship rather than as an entity in its own right, which is what makes the diagram match the model in your head instead of the tables on disk.
Why the layout can be trusted
The agent reads the files listed above and emits a semantic graph: components, the tier each belongs to, and the edges between them, with no coordinates anywhere. The ELK layout engine then computes positions and orthogonal edge routing. This is why the output cannot come back with boxes overlapping or arrows crossing through cards, which is the usual failure when a language model is asked to place things on a canvas itself.
Missing foreign keys show up as isolation
Plenty of schemas have implicit relationships, a user_id column with no constraint behind it, and they are invisible in SQL. In a diagram they are visible as a table sitting on its own with nothing connecting it, which is a quick way to find where referential integrity is being maintained by hope rather than by the database.
Your schema stays on your machine
It runs on your machine. With a local Ollama model nothing leaves the laptop at all, and with your own API key the file contents go to the provider you chose and never through us. For a source that is your actual codebase, that distinction is usually the deciding one.
SQL to ER diagram
| In the schema | In the diagram |
|---|---|
| CREATE TABLE | An entity |
| Columns and types | Attributes |
| PRIMARY KEY | The identifying attribute |
| FOREIGN KEY | A relationship with direction |
| UNIQUE on a foreign key | One-to-one |
| Ordinary foreign key | One-to-many |
| Composite key of two foreign keys | Recognised as a join table, drawn as many-to-many |
| NOT NULL on the key | A mandatory relationship |
| Indexes | A note on how the entity is accessed |
The prompt
Questions
Related
- Generate a Diagram from a CodebasePoint it at a repository and it surveys the code the way a new engineer would, then draws what it found.
- Generate a Diagram from TerraformTerraform already describes your infrastructure precisely. The diagram is a rendering of something you have written down, not a guess.
- Generate a Diagram from Kubernetes ManifestsKubernetes YAML contains the whole topology and presents it as several hundred lines in which none of it is visible.
- Generate a Diagram from Docker ComposeA Compose file is already a complete description of a small system. It is just written in a format that hides the shape.