Skip to main content

Open source · MIT libraries · AGPL editor

relvistarelvista

Open-source DBML diagrams for your docs

Turn DBML schemas into interactive entity-relationship diagrams: edit them in the browser with a live diagram, or render them inside Docusaurus. No account, no server, no screenshots that go stale.

npm i @relvista/docusaurus-plugin
storefront · 02-ecommerce.dbml
storefront · 02-ecommerce.dbmlpublic.countries.code < public.merchants.country_codepublic.users.id - public.user_profiles.user_idpublic.categories.id ?< public.categories.parent_idpublic.merchants.admin_id > public.admins.idfk_orders_user: public.orders.user_id > public.users.id delete: restrict update: cascadepublic.users.country_code > public.countries.code delete: set nullpublic.orders.coupon_id >? public.coupons.id delete: set nullorder_lines: public.order_items.order_id > public.orders.id delete: cascadepublic.order_items.product_id > public.products.id delete: restrict update: no actionorder_payments: public.orders.id < public.payments.order_id delete: cascadepublic.products.(merchant_id, merchant_country) > public.merchants.(id, country_code) delete: cascademerchant_period_owner: public.merchant_periods.(merchant_id, country_code) > public.merchants.(id, country_code)product_tags: public.products.id <> public.tags.idpublic.categories.id ?< public.products.category_idcountriescountriescode char(2) · primary keycodechar(2)name varchar(100) · not nullnameNNvarchar(100)continent_name varchar(50)continent_namevarchar(50)merchantsmerchantsid integer · incrementidintegercountry_code char(2) · foreign keycountry_codechar(2)merchant_name varchar(120) · not nullmerchant_nameNNvarchar(120)admin_id integer · foreign keyadmin_idintegercreated_at timestamp · default: now()created_attimestampmerchant_periodsmerchant_periodsid integer · primary key · incrementidintegermerchant_id integer · foreign key · not nullmerchant_idNNintegercountry_code char(2) · foreign key · not nullcountry_codeNNchar(2)start_date date · not nullstart_dateNNdateend_date dateend_datedateusersusersid integer · primary key · incrementidintegerfull_name varchar(200)full_namevarchar(200)email varchar(255) · unique · not nullemailUNNvarchar(255)country_code char(2) · foreign keycountry_codechar(2)created_at timestamp · default: now()created_attimestampuser_profilesuser_profilesuser_id integer · primary key · foreign keyuser_idintegeravatar_url varchar(500)avatar_urlvarchar(500)bio textbiotextcategoriescategoriesid integer · primary key · incrementidintegerparent_id integer · foreign key Self reference; null for root categoriesparent_idintegername varchar(100) · not nullnameNNvarchar(100)productsproductsid integer · primary key · incrementidintegername varchar(200) · not nullnameNNvarchar(200)merchant_id integer · foreign key · not nullmerchant_idNNintegermerchant_country char(2) · foreign key · not nullmerchant_countryNNchar(2)category_id integer · foreign keycategory_idintegerprice decimal(10,2) · not null · default: 0priceNNdecimal(10,2)status varchar(20) · default: draftstatusvarchar(20)created_at timestamp · default: now()created_attimestamptagstagsid integer · primary key · incrementidintegerlabel varchar(50) · unique · not nulllabelUNNvarchar(50)ordersordersid integer · primary key · incrementidintegeruser_id integer · foreign key · not nulluser_idNNintegerstatus varchar(20) · not null · default: pendingstatusNNvarchar(20)coupon_id integer · foreign keycoupon_idintegercreated_at timestamp · default: now()created_attimestamporder_itemsorder_itemsorder_id integer · foreign keyorder_idintegerproduct_id integer · foreign keyproduct_idintegerquantity integer · not null · default: 1quantityNNintegerunit_price decimal(10,2) · not nullunit_priceNNdecimal(10,2)couponscouponsid integer · primary key · incrementidintegercode varchar(32) · unique · not nullcodeUNNvarchar(32)percent_off integerpercent_offintegerpaymentspaymentsid integer · primary key · incrementidintegerorder_id integer · foreign key · not nullorder_idNNintegeramount decimal(10,2) · not nullamountNNdecimal(10,2)paid_at timestamppaid_attimestampadminsadminsid integer · primary key · incrementidintegerlogin varchar(64) · unique · not nullloginUNNvarchar(64)

Live diagram: drag tables, hover to trace relationships, click a table for details, try fullscreen and export in the toolbar.

Plain DBML

The same language as dbdiagram.io, parsed by @dbml/parse, Holistics' open-source DBML parser. Files open there and here unchanged.

A fence is enough

Write a ```dbml block in Markdown and get a diagram you can zoom, pan, drag, open fullscreen, print and export as SVG or PNG.

Laid out for you

ELK places tables and routes relationships to the exact columns. Keep hand-made positions in a small layout file next to your schema.

Every DBML feature

Table groups, header colours, sticky notes, partials, enums, notes, multi-file projects andDiagramViews all render.

From a code fence to a diagram

You write

docs/schema.md
```dbml title="Blog" height=320
Table users {
id integer [pk]
email varchar [unique]
}

Table posts {
id integer [pk]
author_id integer [ref: > users.id]
title varchar
}
```

Readers get

Blog
Blogpublic.users.id < public.posts.author_idusersusersid integer · primary keyidintegeremail varchar · uniqueemailUvarcharpostspostsid integer · primary keyidintegerauthor_id integer · foreign keyauthor_idintegertitle varchartitlevarchar