ErdDocs

Sequelize models to ER diagram

Paste your models and get the ER diagram of the tables Sequelize creates — real table names from tableName, real column names from field, and the foreign keys your associations imply but your attributes never mention. Nothing to install, nothing uploaded.

Your schema

Three of the columns in that diagram appear nowhere in the model definitions above — see below. Paste your own models over it.

The columns you never wrote

A Sequelize schema is spread across three places, and only one of them is the attribute object. The table name is in the options; the column names may be too, behind field; and the foreign keys are frequently in neither — they come from association calls that may sit at the bottom of the file, or in a different file entirely.

In the example above, venue_id, event_id and customer_id are declared by belongsTo and by nothing else. Sequelize will create those columns; a diagram that only reads the attribute objects will not show them, and the picture is then wrong in the one way that matters — it has no relations in it.

What the parser reads

  • Both declaration forms — sequelize.define(...) and Model.init(...), in one file or several pasted together.
  • The names the database gets — tableName over the model name, field over the attribute key.
  • Column properties — the DataTypes with their size, primaryKey, autoIncrement, unique, defaults, and allowNull, which defaults to true just as nullability does in SQL.
  • Associations — belongsTo and hasMany become relations, with the foreign key column added where the association implies one.

Without booting the project

ErdDocs reads the file itself: paste the models, get the diagram, with nothing to install and nothing to boot. The npm packages that answer this question inspect a live Sequelize instance — install, wire them into your app, run it, get a picture — which is a perfectly good approach when the project is yours and already runs. It is no help when you have been handed a repository, when the app needs a database it cannot reach, or when you only want to read the model layer before deciding whether to take the work at all. ErdDocs covers all three: text in, diagram out.

FAQ

Does it understand both sequelize.define and Model.init?

Yes, and a file that uses both. Either way the options object is where the real table name lives: tableName: "ticket_types" wins over the model name, exactly as it does when Sequelize creates the table.

My foreign keys are not in the attributes — they come from belongsTo.

That is the normal case and it is handled. Sequelize creates the column from the association rather than the attribute list, so Order.belongsTo(Customer, { foreignKey: "customer_id" }) means the orders table has a customer_id column that appears nowhere in your model definition. The diagram adds it, because the database will have it.

What about camelCase attributes and snake_case columns?

field: "starts_at" is what the database sees, so that is what the diagram draws. The JavaScript name stays in your code where it belongs; the diagram is about the table, so it uses the column name.

Do I need to run my project?

No — ErdDocs never runs it. It reads the models as text in your browser, so a file with a missing import, a half-finished refactor, or a snippet pasted out of a pull request still draws. Tools that inspect a live Sequelize instance need the project to boot first, which is a much bigger ask than pasting a file.

Is it free?

Yes for schemas up to 25 tables, with no account and no install. $9 once lifts the limit, removes the mark from exports, and unlocks the data dictionary.

Related