dbml.db

Docs

Every surface answers the same way. POST JSON, or send the schema as a raw text body (--data-binary @schema.dbml) with options in the query string. Inputs up to 512 KiB. Version 0.1.0.

HTTP API

EndpointBodyAnswer
POST /api/v1/validate{dbml}{valid, errors[]} (always 200)
POST /api/v1/parse{dbml}{valid, errors, model}
POST /api/v1/summary{dbml}{valid, summary:{counts, tables, refs, enums, text}}
POST /api/v1/review{dbml, rules?}{valid, score, counts, findings[]}
POST /api/v1/format{dbml}{ok, dbml}
POST /api/v1/dbml-to-sql{dbml, dialect} postgres | mysql | mssql | oracle{ok, dialect, sql}
POST /api/v1/sql-to-dbml{sql, dialect} postgres | mysql | mssql | oracle | snowflake | schemarb | json{ok, dialect, dbml}
POST /api/v1/convert{from, to, input}, one side dbml{ok, sql | dbml}
GET /api/v1/rulesreview rules
GET /api/v1/syntaxDBML cheat sheet (text)

An invalid schema answers 422 with errors: [{message, line, column, end_line, end_column, code}]. A bad request (missing field, unknown dialect) answers 400.

curl -s https://dbml.db.pit.world/api/v1/dbml-to-sql?dialect=mysql --data-binary @schema.dbml -H 'content-type: text/plain'

MCP server

Streamable HTTP (stateless, JSON responses) at https://dbml.db.pit.world/mcp. No key. Tools:

claude mcp add --transport http dbml https://dbml.db.pit.world/mcp

Over stdio (for clients without HTTP transport): npx -y @profullstack/dbml mcp. It proxies to this server.

CLI

npm i -g @profullstack/dbml
dbml validate schema.dbml
dbml review schema.dbml            # exits 1 when there are errors
dbml to-sql schema.dbml --dialect mysql > schema.sql
dbml from-sql dump.sql --dialect postgres > schema.dbml
dbml summary schema.dbml
cat schema.dbml | dbml format -
dbml mcp                           # MCP over stdio

Set DBML_API to use another server.

Review rules

RuleSeverityWhat it means
missing_primary_keyerrorA table has no primary key (no [pk] column and no pk index).
ref_target_not_uniqueerrorA ref points at columns that are not a primary key or unique, so the foreign key cannot be created.
fk_type_mismatchwarningA foreign key column type differs from the column it references.
unindexed_foreign_keywarningA foreign key column is not the leading column of any index or the primary key; joins and cascading deletes scan the table.
nullable_foreign_keywarningA foreign key column allows NULL. Fine for an optional relationship; otherwise add [not null].
many_to_many_refwarningA many-to-many ref (<>) needs a junction table in SQL; model it explicitly.
duplicate_indexwarningTwo indexes on the same table cover the same columns in the same order.
reserved_wordwarningA table or column is named with an SQL reserved word and needs quoting everywhere.
float_for_moneywarningA money-like column (price, amount, total, balance, cost) uses a floating-point type; use decimal/numeric or integer cents.
varchar_without_lengthwarningMySQL and SQL Server need a length on varchar.
table_naming_inconsistentinfoTable names mix naming styles (snake_case, camelCase, PascalCase) or singular and plural.
column_naming_inconsistentinfoColumn names mix naming styles across the schema.
redundant_indexinfoAn index is a leading prefix of another index on the same table.
possible_missing_refinfoA column named like <table>_id matches a table but has no ref.
isolated_tableinfoA table has no refs in or out while the schema has other tables.
missing_timestampsinfoA table has no created_at/updated_at style column.
unused_enuminfoAn enum is declared but no column uses it.
wide_tableinfoA table has more than 40 columns.

Score: 100 minus a weighted penalty (error 15, warning 5, info 1), scaled by schema size. The review is deterministic: no AI model is called.

DBML cheat sheet

# DBML cheat sheet (full docs: https://dbml.dbdiagram.io/docs)

Project shop {
  database_type: 'PostgreSQL'
  Note: 'Optional project note'
}

Table users as U {                      // alias U is optional
  id integer [pk, increment]            // column settings go in [ ]
  email varchar(255) [unique, not null]
  role user_role [default: 'member']    // enum type
  created_at timestamp [default: `now()`] // backticks = SQL expression
  Note: 'Table note'
}

Table orders {
  id bigint [pk]
  user_id integer [not null, ref: > users.id]   // inline ref: many orders -> one user
  total numeric(12,2) [not null, note: 'cents are safer']
  status varchar
  created_at timestamp

  Indexes {
    user_id                                 // single column
    (user_id, created_at) [name: 'ix_orders_user_created']
    status [type: hash]
    (id, user_id) [unique]
  }
}

Table order_items {
  order_id bigint [ref: > orders.id]
  product_id integer
  qty integer [not null, default: 1]
  Indexes { (order_id, product_id) [pk] }   // composite primary key
}

Table products {
  id integer [pk]
  name varchar [not null]
}

Table invoices {
  id bigint [pk]
  order_id bigint [not null]
  user_id integer [not null]
  Indexes { (order_id, user_id) [unique] }
}

// Standalone refs. > many-to-one, < one-to-many, - one-to-one, <> many-to-many
Ref: order_items.product_id > products.id [delete: cascade, update: no action]
Ref fk_name: invoices.(order_id, user_id) - orders.(id, user_id)

Enum user_role {
  admin
  member [note: 'default']
}

TableGroup billing {
  orders
  order_items
}

Schemas: write schema.table (e.g. Table auth.users { ... }); the default is public.

Column settings: pk, primary key, null, not null, unique, increment, default: <value>, note: '...', ref: <rel> <table>.<column>
Index settings: pk, unique, name: '...', type: btree|hash, note: '...'
Ref settings: delete|update: cascade | restrict | set null | set default | no action

Limits and pricing

Free: 60 requests a minute per caller. Over that, the answer is a 429, or a 402 offering a $1 day pass (x402 USDC or CoinPay checkout).

Credits

Parsing and SQL conversion use @dbml/core by Holistics (Apache-2.0). DBML is their language; this is an independent service by Profullstack, Inc. Source: github.com/profullstack/dbml.db.