Documentation

Last updated: March 2026

This reference covers everything you need to use Diagram2Code effectively: the input syntax for Mermaid and PlantUML diagrams, the SQL DDL output format for each supported database dialect, ORM model generation, directive syntax for fine-tuning the output, and the REST API for programmatic use. Use the navigation on the left or the section cards below to find what you need.

🧜 Mermaid ER

Parse erDiagram blocks with tables, columns, types, and relationships.

🌱 PlantUML

Parse @startuml entity diagrams with stereotypes and cardinalities.

🐘 PostgreSQL

SERIAL PKs, UUID, CREATE TYPE for enums, COMMENT ON syntax.

🐬 MySQL

AUTO_INCREMENT, backtick quoting, inline ENUM(), COMMENT inline.

🪶 SQLite

Simplified type affinity (TEXT, INTEGER, REAL, BLOB), IF NOT EXISTS.

🏛️ Oracle 19c+

IDENTITY columns, NUMBER, VARCHAR2, COMMENT ON, no IF NOT EXISTS.

🐹 GORM (Go)

Free tier. Generates Go structs with GORM v2 tags, json tags, and relationship navigation fields.

How It Works

The pipeline has three stages:

  1. Parse — The diagram text (Mermaid or PlantUML) is lexed and parsed into an Intermediate Schema Model (tables, columns, relationships).
  2. Normalize — The schema is cleaned: tables without a primary key get a synthetic id column, duplicate columns are removed, and warnings are emitted.
  3. Generate — The normalized schema is emitted as SQL DDL for the chosen database dialect, with dialect-specific type mapping, quoting, constraints, and comments.

Quick Start Example

Here's a simple diagram and the SQL it generates for each database:

Mermaid Input
erDiagram
    USER {
        int id PK
        string name
        string email
    }
    ORDER {
        int id PK
        int user_id FK
        decimal total
    }
    USER ||--o{ ORDER : places
PostgreSQL Output
CREATE TABLE "user" (
    "id" SERIAL PRIMARY KEY,
    "name" TEXT,
    "email" TEXT
);

CREATE TABLE "order" (
    "id" SERIAL PRIMARY KEY,
    "user_id" INTEGER,
    "total" NUMERIC
);

ALTER TABLE "order"
    ADD CONSTRAINT "fk_order_user_id"
    FOREIGN KEY ("user_id") REFERENCES "user"("id");

Documentation Sections

The full reference is split into focused pages:

🧜 Mermaid ER Syntax

erDiagram blocks, column syntax (type name MARKER), PK/FK/UK markers, and a full-featured table example.

🌱 PlantUML Syntax

@startuml entity diagrams, name : type column order, stereotypes, required-column prefix, and key differences from Mermaid.

🗄️ SQL DDL Generation

All four SQL dialects, type mapping tables, advanced features (comments, enums, constraints, defaults), directives (::NN, ::DEFAULT, ::RELATIONSHIP), normalization, and full schema examples.

🐹 ORM Generation

GORM Go structs with v2 tags, type mapping, relationship navigation fields, enum constants, and a full end-to-end example.

🔌 API Reference

REST API endpoint, request/response format, error codes, and curl example.