Skip to content

Quick Start

Point --config at your MikroORM config file:

package.json
{
"scripts": {
"erd": "mikro-orm-markdown --config ./mikro-orm.config.ts --out ./ERD.md --title \"My Database\""
}
}
  • .ts config — install tsx as a dev dependency (npm install -D tsx). The CLI loads it automatically and defaults MikroORM discovery to entitiesTs unless you explicitly set preferTs.
  • .js config — no extra packages needed. It can be hand-written, or your own build output (e.g. ./dist/mikro-orm.config.js). If it imports .ts entity files, see the tsx note in Installation.
/** @namespace Blog */
@Entity()
export class Author {
@PrimaryKey({ type: 'integer' })
id!: number;
@Property({ type: 'string' })
name!: string;
@Property({ type: 'string', unique: true })
email!: string;
/** @atLeastOne */
@OneToMany({ entity: () => Post, mappedBy: 'author' })
posts = new Collection<Post>(this);
}
/**
* Blog post authored by a registered user.
* @namespace Blog
*/
@Entity()
export class Post {
@PrimaryKey({ type: 'integer' })
id!: number;
/** Post title */
@Property({ type: 'string' })
title!: string;
@Property({ type: 'text', nullable: true })
body?: string;
@ManyToOne({ entity: () => Author })
author!: Author;
}

Imports are omitted. Explicit type: options keep the example working without @mikro-orm/reflection.

Terminal window
npm run erd

Both entities share the @namespace Blog tag, so they land in one ## Blog section. With MikroORM’s default naming strategy, the generated ERD.md contains an ERD like this:

How the code maps to the output:

  • @namespace Blog → both entities are grouped under the ## Blog section
  • @ManyToOne({ entity: () => Author }) → the Post to Author relation line and the author_id FK column
  • @atLeastOne on Author.posts → the collection side is rendered as one-or-more: Post }|--|| Author
  • unique: true on email → email is marked UK (unique key)
  • @Property({ nullable: true }) on body → the Nullable cell is marked Y
  • /** Post title */ → fills the Description cell for title

Each entity also gets a column table. For example, the generated Post section looks like this:

### Post
*Table: `post`*
> Blog post authored by a registered user.
| Column | Type | Key | Nullable | Description |
| --------- | ------- | ----------- | -------- | ----------- |
| id | integer | PK | | |
| title | string | | | Post title |
| body | text | | Y | |
| author_id | integer | FK (author) | | |

Next: see every CLI option and JSDoc tag.