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"
AI Database Copilot
Click the ⚡ Copilot button in the toolbar to open an interactive AI sidebar. The Copilot is aware of your entire schema context and can:
- Write complex SQL queries based on your tables and relationships
- Answer architectural questions
- Suggest DSL modifications to add new features
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.
Live Database Connection
Click 🔗 Connect DB to introspect a live PostgreSQL or MySQL database securely. SchemaStruct connects temporarily, reads your Information Schema, and instantly converts your live database tables, constraints, and relationships into visual DSL.
When integrated with your workflow, you can spot "Schema Drift" easily by comparing the introspected schema against your desired visual states.
SQL Export
Click Export → SQL and choose your target database. SchemaStruct generates proper DDL for 6 databases:
- PostgreSQL — SERIAL, VARCHAR, JSONB, etc.
- MySQL — AUTO_INCREMENT, VARCHAR(255), TINYINT(1), etc.
- SQL Server — IDENTITY(1,1), NVARCHAR(255), BIT, etc.
- SQLite — INTEGER, TEXT, REAL, BLOB
- Oracle — NUMBER(10), VARCHAR2(255), CLOB, sequences
- MariaDB — Same as MySQL with MariaDB compatibility
Each dialect uses proper identifier quoting and type mapping.
GitHub CI/CD Sync
Keep your codebase and visual diagrams perfectly in sync. Click ♲ Syncto push your generated SQL migration directly to a GitHub repository.
- Requires a GitHub Personal Access Token (PAT) with
reposcope - Commits your schema directly to any branch
- Generates a direct link to the commit diff
ORM Code Generation
Export your schema as ORM model code for popular frameworks:
- Prisma — schema.prisma with models, relations, and @@map
- TypeORM — TypeScript entities with decorators
- SQLAlchemy — Python models with Column, ForeignKey, relationship
- Django — Python models with fields and Meta class
Data Dictionary Portal
Beyond exporting, SchemaStruct provides an interactive, read-only Data Dictionary Portal. Click Publish Docs in the Toolbar to get a shareable URL to your project's documentation. You can also export it manually as Markdown or HTML.
The documentation portal includes:
- Summary (total tables, columns, relationships)
- Table of contents with links
- Per-table column details (name, type, constraints, default, notes)
- Relationship maps per table
- Full relationship summary
Schema Templates
Click Templates in the toolbar to load a pre-built schema instantly. Available templates:
- E-commerce — Users, products, categories, orders, reviews, coupons
- Blog / CMS — Posts, categories, tags, comments, media
- Project Management — Teams, projects, tasks, time tracking
- CRM — Contacts, companies, deals, pipelines, activities
- SaaS Multi-tenant — Organizations, roles, subscriptions, billing
- Social Network — Posts, likes, follows, messages, notifications
- Healthcare / EHR — Patients, doctors, appointments, prescriptions
- Education / LMS — Courses, lessons, enrollments, grades
- Inventory Management — Warehouses, stock, purchase orders, shipments
- Authentication System — Roles, permissions, sessions, audit logs
Version History
SchemaStruct auto-saves your schema every 5 seconds. Click History in the toolbar to:
- View a timeline of all saved versions
- Restore any previous version instantly
- Save labeled snapshots (e.g. "Before adding payments")
- Compare two versions with a colored diff view
Schema Validation
Click Validate to lint your schema against 10 built-in rules:
| Rule | Severity | Description |
|---|---|---|
| No Primary Key | Warning | Table has no primary key |
| Naming Convention | Warning | Names should be snake_case |
| Require Timestamps | Info | Tables should have created_at/updated_at |
| NOT NULL Foreign Keys | Warning | FK columns should be NOT NULL |
| No Duplicate Columns | Error | Duplicate column names |
| Lonely Table | Info | Table has no relationships |
| Missing Referenced Table | Error | Ref points to non-existent table |
| Missing Referenced Column | Error | Ref points to non-existent column |
| Reserved Words | Warning | Column name is a SQL reserved word |
| No Type Defined | Warning | Column has no type specified |
Rules can be individually enabled or disabled in the validation panel.
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 }