Skip to content
data-minationPublic

About

AI-Ready Data Modeling Language (AIR-DML): An evolution of DBML optimized for LLMs and business context. Bridges the gap between domain experts and developers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AIR-DML

AI-Ready Data Modeling Language

The Open Standard for AI-Ready Data Modeling

AIR-DML is a data modeling language designed for AI-driven development. It provides a structured, human- and machine-readable syntax for database schemas enriched with business context.

npm version License

Used In Production

Mode-ai

Mode-ai - AI-Powered Data Modeling Tool

Generate ER diagrams from natural language using AI. Mode-ai is the reference implementation of AIR-DML, showcasing the full potential of AI-ready data modeling.

  • Natural language to ER diagram generation
  • Interactive visual editor with drag & drop
  • Export to SQL, AIR-DML, and more

Features

✨ AI-Optimized: Designed for AI language models to understand and generate database schemas 🏗️ Domain-Driven Design: Built-in support for bounded contexts via Area 🌍 Multilingual: Logical names (aliases) in any language 🎨 Visual Design: Coordinate and color information for diagram rendering 🔄 Polyglot Persistence: Different database types per area 📦 Zero Dependencies: Independent parser with no external dependencies 💬 Comment Preservation: Leading comments are preserved and associated with elements

Installation

npm install air-dml

ESM only. This package is published as an ES module ("type": "module") and requires Node.js 18 or later. Use import; require() is not supported. If you need it from CommonJS, use a dynamic await import('air-dml').

Quick Start

import { parseAirDML, exportToAirDML } from 'air-dml';

// Parse AIR-DML text
const airDmlText = `
Project "My Project" {
  database_type: "PostgreSQL"
}

// ユーザー管理
Table users [alias: "ユーザー", pos_x: 100, pos_y: 100, color: "#1976D2"] {
  id serial [pk, alias: "ユーザーID"]
  username varchar(100) [not null, unique, alias: "ユーザー名"]
  email varchar(255) [not null, unique, alias: "メールアドレス"]
  created_at timestamp [not null, alias: "作成日時"]
}

// プロフィール情報
Table profiles [alias: "プロフィール", pos_x: 500, pos_y: 100] {
  id serial [pk, alias: "プロフィールID"]
  user_id integer [fk, not null, unique, alias: "ユーザーID"]
  full_name varchar(200) [alias: "氏名"]
  bio text [alias: "自己紹介"]
}

Ref: profiles.user_id - users.id

Area "User Management" [
  pos_x: 50,
  pos_y: 50,
  width: 600,
  height: 300,
  color: "#1976D2"
] {
  users
  profiles

  database_type: "PostgreSQL"

  CommonColumns: [
    created_at timestamp [not null, alias: "作成日時"]
    updated_at timestamp [not null, alias: "更新日時"]
  ]

  Note: "ユーザー管理領域"
}
`;

const diagram = parseAirDML(airDmlText);
console.log(diagram);

// Export back to AIR-DML
const output = exportToAirDML(diagram);
console.log(output);

AIR-DML Syntax

Table Definition

Table table_name [alias: "論理名", pos_x: 100, pos_y: 200, color: "#1976D2"] {
  column_name data_type [constraints, alias: "カラム論理名"]

  Note: "テーブルの説明"
}

Column Constraints

Constraint Description Example
pk Primary Key id serial [pk]
fk Foreign Key (use with Ref) user_id integer [fk]
unique Unique constraint email varchar [unique]
not null NOT NULL constraint name varchar [not null]
increment Auto increment id integer [pk, increment]
hidden Hide column in canvas MANDT varchar [hidden]
alias: "name" Logical name [alias: "ユーザーID"]
note: "desc" Column description [note: "説明"]
values: "k=v/..." Enum / classification values [values: "1=有効/2=無効"]
default: "val" Default value [default: "active"]

values: — Enum / Classification Values

Define allowed values for a column (status codes, flags, etc.):

status varchar(1) [
  not null,
  alias: "ステータス",
  values: "1=有効/2=無効/3=削除済",
  default: "1"
]

Format: "key=label/key2=label2/..." — key and label separated by =, entries separated by /.

Relationships

Ref: table_a.column > table_b.column   // Many-to-One (A → B)
Ref: table_a.column < table_b.column   // One-to-Many (A ← B)
Ref: table_a.column - table_b.column   // One-to-One
Ref: table_a.column >< table_b.column  // Many-to-Many
Ref: table_a.column ~ table_b.column   // AI-inferred (undetermined)

Area (Bounded Context)

Area "Area Name" [
  pos_x: 50,
  pos_y: 50,
  width: 600,
  height: 300,
  color: "#1976D2"
] {
  table1
  table2

  database_type: "PostgreSQL"

  CommonColumns: [
    created_at timestamp [not null, alias: "作成日時"]
    updated_at timestamp [not null, alias: "更新日時"]
  ]

  Note: "Area description"
}

Lineage (how a table is built, v2.3.0+)

A Lineage block records how one table is built: the order of processes, joins, where each column comes from, the kind of transformation, and — above all — the intent (Note: / note:). Expressions (expr:) are optional.

Lineage mart_campaign_daily [alias: "Daily campaign results"] {
  Process 0 {
    1 -> 2 -> mart_campaign_daily   // process order (omit when there is one process)
  }

  Process 1 imp [alias: "Impressions per day and campaign"] {
    served_date <- dwh_impression_fact.served_date [pk]
    campaign_id <- dwh_impression_fact.campaign_id [pk]
    impressions <- dwh_impression_fact [aggregate, note: "count rows"]
    Note: "Bundle each impression into day x campaign"
  }

  Process 2 [alias: "Finish"] {
    Join imp, dwh_campaign [inner, note: "keep campaigns present in both"] {
      imp.campaign_id = dwh_campaign.campaign_id
    }
    served_date   <- imp.served_date
    campaign_id   <- imp.campaign_id
    campaign_name <- dwh_campaign.campaign_name
    impressions   <- imp.impressions
    Note: "Add campaign names"
  }
}
  • Join kinds: inner, left, right, full, cross. Transformations: aggregate, cast, calc, function, case, coalesce, constant.
  • Reading Process 0: it is not a process but an index of how processes connect. In the example above, 1 -> 2 reads "process 2 uses the result of process 1", and 2 -> mart_campaign_daily marks process 2 as the last one, whose result is the built table (exactly one such arrow). Process numbers are labels; the arrows, not the numbers, decide the order. A process name (Process 1 imp) lets other processes use its columns as imp.column.
  • Join order: joins in a process are applied in the order written. The left name of the first Join A, B is the starting table (FROM); each Join A, B joins B to the result so far, where A is a name that has already appeared and B is a name not yet used in the process. Read the kind as <result so far> <kind> JOIN B: left keeps every row of the result so far, right keeps every row of B. lintLineages does not check this order.
  • No new reserved words: Lineage, Process and Join can still be used as table or column names.
  • <-, -> and = are valid only inside Lineage. Parsers older than 2.3.0 cannot read a document that contains Lineage.
  • See SPECIFICATION.md section 2.6 for the full syntax.

AI Generation Guidelines

When using AI to generate AIR-DML, follow these rules:

Required:

  • Use double quotes for alias values: alias: "論理名" ✅
  • Do NOT use single quotes: alias: '論理名' ❌
  • Mark foreign key columns with [fk]
  • Define relationships separately with Ref:
  • Do NOT add inline comments after column definitions

Example Output:

// 定期購入機能
Table subscriptions [alias: "定期購入"] {
  id serial [pk, alias: "定期購入ID"]
  user_id integer [fk, not null, alias: "ユーザーID"]
  product_id integer [fk, not null, alias: "商品ID"]
  status varchar(1) [not null, alias: "ステータス", values: "1=有効/2=停止/3=解約", default: "1"]
  created_at timestamp [not null, alias: "作成日時"]
}

Ref: subscriptions.user_id > users.id
Ref: subscriptions.product_id > products.id

Use values: for any column with a fixed set of allowed values (status, type, flag, etc.). Format: "key=label/key2=label2/..." with / separator.

For complete AI generation guidelines, see SPECIFICATION.md Section 5.

API Reference

parseAirDML(airDmlText: string, diagramId?: string): Diagram

Parse AIR-DML text into a Diagram object.

Parameters:

  • airDmlText - AIR-DML formatted text
  • diagramId - Optional diagram ID

Returns: Diagram object

parseAirDMLSafe(airDmlText: string, diagramId?: string): ParseResult

Parse AIR-DML text and return a ParseResult instead of throwing. This is the recommended API for handling untrusted or user-supplied input, since parse failures are returned as values rather than exceptions.

Parameters:

  • airDmlText - AIR-DML formatted text
  • diagramId - Optional diagram ID

Returns: ParseResult — { success, diagram?, error?, warnings? }

import { parseAirDMLSafe } from 'air-dml';

const result = parseAirDMLSafe(`
  Table users {
    id serial [pk]
  }
`);

if (result.success) {
  console.log(result.diagram.tables);
} else {
  console.error(result.error);
}

Use parseAirDML when a parse failure is a programming error and you want it to throw; use parseAirDMLSafe when you want to inspect and report the failure.

parseAirDMLFiles(files: AirDMLFile[], options?: ParseAirDMLFilesOptions): ParseResult

v2.4.0+. Read several .aml files as one model. Files whose names have the same prefix are combined into one Diagram; no syntax is added, so every file is still a plain AIR-DML document. A large model can be split by business domain, by kind of data, or with its Lineage blocks in separate files.

The prefix is the part of the file name (after the last / or \) before its first .: sales.aml, sales.customers.aml and models/v1.0/sales.raw.aml all have the prefix sales; pipeline.aml has pipeline. Prefixes are compared as written (case-sensitive). Because files are chosen by name, they are chosen before they are read.

Parameters:

  • files - { name: string; text: string }[]. name is the file name (a path is fine); it is also shown in errors and warnings. The order of the array is the order of the files.
  • options.project - the prefix to combine. Only the files with this prefix are read; files with another prefix are not read (a broken file there does not fail the call) and are reported with a warning. When omitted, every file must have the same prefix.
  • options.diagramId - optional diagram ID

Returns: ParseResult — { success, diagram?, error?, warnings? }

import { parseAirDMLFiles, lintLineages } from 'air-dml';

const result = parseAirDMLFiles([
  { name: 'sales.customers.aml', text: customersText }, // Project "sales" + tables
  { name: 'sales.orders.aml', text: ordersText },       // Ref to a table in sales.customers.aml
  { name: 'sales.lineage.aml', text: lineageText },     // Lineage only (no Project needed)
]);

if (result.success && result.diagram) {
  console.log(result.diagram.project); // 'sales'
  console.log(result.diagram.tables.map((t) => t.name));
  console.log(lintLineages(result.diagram)); // works on the combined diagram
} else {
  console.error(result.error); // e.g. "sales.orders.aml: ..."
}

How files are combined:

  • Project may be written in just one file; files without Project are combined too. The diagram's project is the name in the first file that writes Project, or the prefix when no file does. A Project name that differs from the prefix gives a warning (the file is still combined). database_type and Note: the earlier one is used, with a warning when they differ.
  • Tables keep the file order. The same table name in two files is an error.
  • Ref and Lineage are resolved after all tables are combined, so they may point to tables in other files. A file may hold only Lineage blocks.
  • Area blocks with the same name in different files become one Area: tables and CommonColumns are added in file order (the earlier column wins on the same name). When attributes differ, the earlier one is used with a warning.
  • Warnings, and errors for a chosen file that cannot be read, start with the file name (also when there is only one file). Errors for tables of the same name and for prefixes list the file names in the message.

Choosing which files to pass (for example, every .aml in a folder in name order) is up to the application. See SPECIFICATION.md 2.7 for the details.

ParseError / LexerError

Error classes thrown by parseAirDML and reported by parseAirDMLSafe. Both extend Error, so they can be distinguished with instanceof.

  • LexerError - the input could not be tokenized (invalid character, unterminated string, ...)
  • ParseError - the tokens could not be assembled into a valid document
import { parseAirDML, ParseError, LexerError } from 'air-dml';

try {
  parseAirDML(text);
} catch (e) {
  if (e instanceof LexerError) console.error('Tokenization failed:', e.message);
  else if (e instanceof ParseError) console.error('Syntax error:', e.message);
  else throw e;
}

exportToAirDML(diagram: Diagram): string

Export a Diagram object to AIR-DML text.

Parameters:

  • diagram - Diagram object

Returns: AIR-DML formatted text (including Lineage blocks)

lintLineages(diagram: Diagram): LineageIssue[]

Check the Lineage blocks of a parsed diagram. Parsing accepts any well-formed Lineage; this function reports structural errors (cycles in Process 0, no single arrow into the built table, unknown process numbers, …) and warnings (missing intent notes, missing join kind, columns that differ from the built Table, …).

import { parseAirDMLSafe, lintLineages } from 'air-dml';

const result = parseAirDMLSafe(text);
if (result.success && result.diagram) {
  for (const issue of lintLineages(result.diagram)) {
    console.log(issue.severity, issue.code, issue.lineage, issue.process, issue.message);
  }
}

Returns: { code, severity: 'error' | 'warning', lineage, process?, column?, message }[] (empty when there is no problem)

getDataTypesForDatabase(database: string): string[]

Get the list of supported data types for a specific database.

Parameters:

  • database - Database name: "PostgreSQL" | "MySQL" | "SQLite" | "SQL Server" | "Oracle" | "BigQuery" | "Redshift" | "Snowflake"

Returns: Array of data type strings

import { getDataTypesForDatabase } from 'air-dml';

const types = getDataTypesForDatabase('PostgreSQL');
// ["integer", "bigint", "varchar", "text", "boolean", "timestamp", ...]

Type Definitions

interface Diagram {
  id: string;
  name: string;
  project?: string;
  database?: string;
  tables: Table[];
  references: Reference[];
  areas?: Area[];
  createdAt?: string;
  updatedAt?: string;
  note?: string;
}

interface Table {
  id: string;
  name: string;
  logicalName?: string;      // alias
  columns: Column[];
  color?: string;
  pos?: Position;
  areaIds?: string[];
  note?: string;
  leadingComments?: string[];  // v1.2.0+
}

interface Column {
  name: string;
  logicalName?: string;      // alias
  type: DataType;
  typeParams?: string;
  pk?: boolean;
  fk?: boolean;
  unique?: boolean;
  notNull?: boolean;
  increment?: boolean;
  hidden?: boolean;          // v2.1.8+
  note?: string;
  values?: string;           // v2.1.9+ — "key=label/key2=label2/..."
  defaultValue?: string;     // v2.1.9+
  leadingComments?: string[];  // v1.2.0+
}

interface Reference {
  id: string;
  fromTable: string;
  fromColumn: string;
  toTable: string;
  toColumn: string;
  type: RelationshipType;
  swapEdge?: boolean;
  leadingComments?: string[];  // v1.2.0+
}

interface Area {
  id: string;
  name: string;
  tables: string[];
  color?: string;
  pos?: Position;
  width?: number;
  height?: number;
  labelHorizontal?: 'left' | 'center' | 'right';
  labelVertical?: 'top' | 'center' | 'bottom';
  databaseType?: string;
  commonColumns?: Column[];
  note?: string;
  leadingComments?: string[];  // v1.2.0+
}

Key Features At a Glance

Feature Description
Logical names alias attribute for human-readable names in any language
Classification values values attribute for enums and status codes
Area management Bounded context grouping with CommonColumns and per-area database type
Visual layout Coordinates, colors, and sizes for diagram rendering
Multi-DB Area-level database type (polyglot persistence)
Lineage How a table is built: process order, joins, column sources, and the intent of each transformation
Multiple files Split a large model into several files and read them as one model by the file name prefix
AI-optimized LLM-friendly syntax designed for generation and interpretation
Zero dependencies Independent recursive descent parser

Changelog

v2.4.0 (2026-11)

  • Added parseAirDMLFiles to read several files as one model, chosen by the file name prefix (sales.*.aml)
  • Ref, Area and Lineage may point to tables in other files; same-named Area blocks are combined

v2.3.0 (2026-11)

  • Added the Lineage block (how a table is built) to parsing and exportToAirDML
  • Added lintLineages to check Lineage blocks
  • <-, -> and = outside Lineage now drop only that block with a warning (previously the whole parse failed)

v2.1.9 (2026-04)

  • Added values: "key=label/..." column attribute for enum/classification values
  • Added default: "value" column attribute (redesigned with double-quote consistency)
  • SAP R/3 namespace support: /NAMESPACE/FIELDNAME identifiers in lexer

v2.1.8 (2026-04)

  • Added hidden column attribute to hide columns from canvas display

v2.1.7 (2026-04)

  • Fixed: attribute keywords (alias, note, etc.) now usable as column names

v2.1.6 (2026-03)

  • Fixed: top-level keywords (project, table, ref, area) now usable as column names

v2.1.5 (2026-03)

  • Fixed: multi-word type names (e.g. timestamp with time zone) correctly quoted in export

v2.1.4 (2026-03)

  • Added SQL standard type names to PostgreSQL (character varying, time with time zone, etc.)

v2.1.3 (2026-03)

  • Expanded data type lists for all 8 databases (PostgreSQL, MySQL, Oracle, SQL Server, SQLite, BigQuery, Redshift, Snowflake)

v2.1.2 (2026-03)

  • Added Snowflake database type support

v2.1.0 (2025-01)

  • Breaking: Removed default column constraint (re-added in v2.1.9 with double-quote consistency)

v2.0.0 (2025-01)

  • Major: Replaced @dbml/core dependency with custom hand-written recursive descent parser
  • Full AIR-DML syntax support without external dependencies
  • Improved error messages in Japanese

v1.2.0 (2025-01)

  • Added leading comment preservation for Tables, References, and Areas
  • Added leadingComments field to type definitions

v1.0.0 (2025-01)

  • Initial release
  • Core AIR-DML parsing and export
  • Support for alias, pos_x, pos_y, color attributes
  • Area with CommonColumns and database_type

Specification

For the complete AIR-DML specification, see SPECIFICATION.md.

License

Apache-2.0 License - see LICENSE file for details.

Credits

  • Created by: Data-mination Partners
  • Technical collaboration: Claude Sonnet 4.6 (Anthropic)

Links


Trademarks

AIR-DML™ (AI-Ready Data Modeling Language) is a trademark of Datamination Partners Co., Ltd. Trademark Application No. 2026-000274 (Japan)

AIR-DML™ — The Open Standard for AI-Ready Data Modeling.

About

AI-Ready Data Modeling Language (AIR-DML): An evolution of DBML optimized for LLMs and business context. Bridges the gap between domain experts and developers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages