ORM Lens

Sequelize models (preview)

scan, list, describe, hover and er read Sequelize models as well as Django, SQLAlchemy, Prisma, Drizzle, Rails, EF Core and TypeORM ones, and so do the MCP tools list_apps, list_models, describe_model, find_relations and er_diagram. Sequelize has no schema file, so the model code is read: the classes, the init and define calls, and the associations between them. It is read as text, with no Node and no database.

uvx orm-lens scan -f table      # every model and join table
uvx orm-lens er -f dbml         # ER diagram: mermaid, dbml, d2, plantuml or dot
uvx orm-lens describe Document  # one model: columns, keys and what each does on delete

The other commands don’t read Sequelize yet, and neither does the VS Code extension. The Django analyses never see a Sequelize model, and a Python relation never points at one.

What is read

The .ts, .js, .mjs and .cjs files of every package whose package.json depends on sequelize or sequelize-typescript. node_modules, dist, build, test directories, *.spec.*, *.test.* and *.d.ts are skipped, and so are files over 2 MB, anything that isn’t a regular file (a pipe, a socket) and links that lead outside the workspace. A directory whose package.json lists dependencies of its own is another package, read only when it depends on Sequelize too; one that lists none (PeerTube’s server/, which uses the root’s) is read with the root.

In a workspace with no Django or SQLAlchemy project, the MCP server looks for such a package.json at most four directories down. If yours is deeper, point workspace_root at a directory closer to it. The CLI has no such limit.

Models are declared two ways, and both are read:

A model is listed under its class name, or the name define gives it. The table is tableName, or the model name (modelName when given) in the plural, as Sequelize makes it (Category → Categories, Person → People; in snake_case with underscored: AuditLog → audit_logs), or the model name as is with freezeTableName.

Columns are the attributes, named by field (kept as written, even with underscored) or, with underscored, in snake_case. An attribute inherited from a base class is named by the model’s own underscored. The type is the DataTypes one without its prefix (STRING(255), UUID, ENUM); a sequelize-typescript @Column without a type takes it from the property’s TypeScript type, as sequelize-typescript does. A column is nullable unless allowNull: false or it is the primary key. args shows NOT NULL, UNIQUE and DEFAULT ... (Sequelize.fn("now") as now()).

What Sequelize adds is added too: an id (INTEGER) when no attribute is the primary key, createdAt and updatedAt unless timestamps: false (renamed by createdAt: "createdOn", which is in snake_case with underscored, and left out by createdAt: false), and deletedAt for a paranoid model. A timestamp the model declares itself, under that name, is kept as declared. In sequelize-typescript, @CreatedAt, @UpdatedAt and @DeletedAt name these timestamps the same way: as options that a subclass inherits along with underscored and paranoid, and that its own @Table overrides (@Table({ updatedAt: false })).

Foreign keys come from the associations and from an attribute’s own references:

A key points at the primary key, or at the attribute targetKey (belongsTo) or sourceKey (hasMany, hasOne, belongsToMany) names. When the model doesn’t declare the key, it is added with the type of that attribute. A key on the primary key or a unique column, and a hasOne’s, is shown as a OneToOneField; the others as ForeignKey.

Delete policy is the one Sequelize gives the constraint: an attribute’s own onDelete wins, then the association’s. Without one, a nullable key is SET NULL; otherwise belongsTo gives NO ACTION and hasMany / hasOne give CASCADE. As in Sequelize, a key the model declares counts as nullable here only with allowNull: true. belongsToMany keys delete on cascade. constraints: false makes no constraint, so the key has no delete policy, the join table’s keys included; the column and the association are still shown, since queries join on them.

Limits

Apps

All the models of a workspace are one app, sequelize (sequelize_2 if another app already has that name), since they usually refer to each other across files. The grouping is by workspace, not a sign of one database: packages with databases of their own are listed together all the same. orm-lens scan --format json marks them with "orm": "sequelize" and adds tableName. Django models serialize exactly as before.

How it was checked

The models of PeerTube and Outline (sequelize-typescript), and of the Open Collective API and OWASP Juice Shop (init and associations), were read and compared with a separate count over the same source: every @Table class, init and define model, and every key the source names — a belongsTo / hasMany / hasOne with foreignKey, an attribute with references, a @ForeignKey used by an association — with its target and its onDelete when given. All 192 models and 420 named keys were found (426 keys in all, with the ones Sequelize names itself), no column was left without a type, and the DBML diagram has one reference per key. The only differences are three columns where PeerTube and Outline give @ForeignKey one target and @BelongsTo another. On the 29 Django and SQLAlchemy projects used for parser changes the output is the same as before.