SchemaStruct Documentation
SchemaStruct is a visual data modeling tool that lets you design database schemas using a simple DSL (Domain-Specific Language) with instant diagram preview. Whether you are planning a new database, documenting an existing one, or collaborating with your team — SchemaStruct makes it easy.
Quick Start
Open the Editor
Go to schemastruct.com/editor — the editor loads with a sample schema so you can see how it works right away.
Write or edit the DSL
Modify the DSL code in the left panel. The diagram on the right updates instantly as you type.
Export your work
Click Export → SQL to download PostgreSQL DDL, or Save to persist your project.
Tables
Tables are the core building block. Define them using the table keyword followed by the table name and curly braces:
table users {
id integer [pk]
email varchar [unique, not null]
name varchar
created_at timestamp
}Table names should be lowercase with underscores. Each line inside the braces defines a column.
Columns & Types
Each column is defined as: column_name type [constraints]
Supported Types
Numeric
integer int bigint smallint serial float double decimal numericText
varchar text charDate/Time
timestamp datetime date timeOther
boolean bool json jsonb uuid byteaConstraints
Add constraints inside square brackets after the column type:
table products {
id integer [pk] // Primary Key
sku varchar [unique] // Unique constraint
name varchar [not null] // NOT NULL
price decimal [not null, default: 0.00] // Default value
}| Constraint | Syntax | Description |
|---|---|---|
| Primary Key | [pk] | Marks column as the primary key |
| Not Null | [not null] | Column cannot be NULL |
| Unique | [unique] | Column values must be unique |
| Default | [default: value] | Sets a default value |
| Multiple | [pk, not null] | Combine constraints with commas |
Notes & Comments
SchemaStruct supports two ways to annotate columns:
Comments (editor only)
Use // or # for inline comments. These are visible only in the code editor and are not shown in the diagram.
table users {
id integer [pk]
email varchar [not null] // Primary contact email
role varchar # admin, editor, viewer
}Notes (shown in diagram on hover)
Use [note: "..."] to add structured notes. These appear as a popup tooltip when you hover over the column in the diagram.
table users {
id integer [pk]
username varchar [not null] [note: "User's unique login name"]
email varchar [unique] [note: "Must be verified before login"]
status varchar [default: 'active'] [note: "active, suspended, deleted"]
}| Syntax | Visible In | Purpose |
|---|---|---|
// text or # text | Editor only | Code comments, dev notes |
[note: "text"] | Editor + Diagram (hover) | Column descriptions, business logic |
Relationships
Define foreign key relationships using the ref: keyword:
// One-to-Many: one user has many orders ref: orders.user_id > users.id // Many-to-One ref: orders.user_id < users.id // One-to-One ref: profiles.user_id - users.id // Many-to-Many ref: students.id <> courses.id
| Operator | Cardinality | Meaning |
|---|---|---|
> | Many-to-One | Left table has FK referencing right table |
< | One-to-Many | Right table has FK referencing left table |
- | One-to-One | Unique foreign key relationship |
<> | Many-to-Many | Junction table relationship |
AI Schema Generation
Click the ✨ AI Generate button in the toolbar to describe your project in plain English. SchemaStruct uses Claude AI to generate a complete database schema for you.
Quick-start Templates
- E-commerce — Products, orders, customers, payments
- Blog / CMS — Posts, authors, categories, comments
- SaaS — Users, organizations, subscriptions, billing
- Social Media — Profiles, posts, followers, messages
- Healthcare — Patients, doctors, appointments, records
- Education — Students, courses, enrollments, grades
Or type any custom prompt like: "A project management app with tasks, projects, teams, and time tracking"
SQL Import
Click Import SQL in the toolbar and paste any SQL DDL to reverse-engineer it into a visual diagram. Supported databases:
- PostgreSQL
- MySQL
- SQLite
- SQL Server
The importer understands CREATE TABLE, PRIMARY KEY, FOREIGN KEY, REFERENCES, NOT NULL, UNIQUE, and DEFAULT clauses.
SQL Export
Click Export → SQL to download a PostgreSQL DDL file containing:
CREATE TABLEstatements with columns and constraintsALTER TABLE ... ADD FOREIGN KEYstatements for all relationships
Auto Layout
Use the Layout dropdown in the toolbar to automatically arrange your tables:
- Left → Right — Horizontal flow
- Top → Bottom — Vertical flow
- Right → Left — Reverse horizontal
- Bottom → Top — Reverse vertical
- Fit to View — Zoom to fit all tables on screen
Real-time Collaboration
When connected with Supabase authentication, SchemaStruct supports real-time collaboration:
- See who is currently editing (colored avatars in the toolbar)
- Schema changes sync instantly across all connected users
- Share projects via unique URLs
Data Modeling Types
Conceptual Model
A high-level overview of your data. Focus on entities and their relationships without worrying about data types or constraints. Great for early-stage planning and stakeholder communication.
// Conceptual: just entities and relationships
table Customer {}
table Order {}
table Product {}
ref: Order.customer > Customer.id
ref: Order.product > Product.idLogical Model
Adds data types and key constraints to the conceptual model. Defines primary keys, foreign keys, and column types — but stays database-agnostic.
table customers {
id integer [pk]
name varchar [not null]
email varchar [unique]
}
table orders {
id integer [pk]
customer_id integer [not null]
total decimal
status varchar
}
ref: orders.customer_id > customers.idPhysical Model
The most detailed model. Includes specific database types, defaults, indexes, and all constraints. Ready to export to SQL and deploy.
table customers {
id serial [pk]
name varchar [not null]
email varchar [unique, not null]
phone varchar
created_at timestamp [not null, default: 'now()']
updated_at timestamp
}
table orders {
id serial [pk]
customer_id integer [not null]
total decimal [not null, default: 0.00]
status varchar [not null, default: 'pending']
notes text
created_at timestamp [not null, default: 'now()']
}
ref: orders.customer_id > customers.idFull Example: E-commerce Schema
// E-commerce Database Schema
table users {
id serial [pk]
email varchar [unique, not null]
password_hash varchar [not null]
full_name varchar [not null]
role varchar [default: 'customer']
created_at timestamp [default: 'now()']
}
table products {
id serial [pk]
name varchar [not null]
description text
price decimal [not null]
stock integer [default: 0]
category_id integer
is_active boolean [default: true]
}
table categories {
id serial [pk]
name varchar [unique, not null]
parent_id integer
}
table orders {
id serial [pk]
user_id integer [not null]
status varchar [default: 'pending']
total decimal [not null]
shipping_address text
created_at timestamp [default: 'now()']
}
table order_items {
id serial [pk]
order_id integer [not null]
product_id integer [not null]
quantity integer [not null, default: 1]
unit_price decimal [not null]
}
// Relationships
ref: orders.user_id > users.id
ref: order_items.order_id > orders.id
ref: order_items.product_id > products.id
ref: products.category_id > categories.id
ref: categories.parent_id > categories.id
Comments
Add comments using double-slash or hash syntax:
// This is a comment # This is also a comment table users { id integer [pk] // Primary key email varchar # User email }