Version 2.0.0
A powerful Laravel code generator written in Rust that creates models, controllers, resources, factories, migrations, and pivot tables from Prisma-like schema files.
🌐 Website: https://schemly.dev/
- 🚀 Fast & Reliable - Built with Rust for maximum performance
- 📝 Prisma-like Syntax - Define your models with modern, industry-standard syntax
- 🔧 Complete Laravel Support - Generates all Laravel components
- 🔗 Relationship Support - Full support for all Laravel relationship types
- 🏗️ Pivot Tables - Automatic pivot table generation for many-to-many relationships
- 🤖 AI-Friendly - Comprehensive documentation designed for AI code generation
- 🔌 MCP Server - Built-in Model Context Protocol server for Claude, Cursor, and Windsurf
- 🏛️ DDD Support - Optional Domain-Driven Design folder structure
brew tap DevPlus31/schemly
brew install schemlywinget install DevPlus31.Schemlygit clone https://github.com/DevPlus31/schemly.git
cd schemly
cargo build --releaseThe binary will be available at target/release/schemly.
# Copy to a directory in your PATH
cp target/release/schemly /usr/local/bin/
# or
cp target/release/schemly ~/.local/bin/schemly initThis creates a schema.schemly file with example models.
Edit schema.schemly with Prisma-like syntax:
generator laravel {
provider = "schemly"
output = "./app"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
email String @unique @db.VarChar(255)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
posts Post[]
@@map("users")
@@traits(["HasFactory", "Notifiable"])
@@fillable(["name", "email"])
}
model Post {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
content String @db.LongText
userId Int @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("posts")
@@traits(["HasFactory"])
@@fillable(["title", "content", "user_id"])
}# Generate all components
schemly generate
# Preview what would be generated (dry run)
schemly generate --dry-run
# Generate in specific Laravel project
schemly generate --output /path/to/laravel-project
# Generate only specific components
schemly generate --only models,migrations
# Generate everything EXCEPT specific components
schemly generate --exclude controllers,dtos
# Use Domain-Driven Design structure
schemly generate --ddd
# Set up AI context rules (.cursorrules, etc.)
schemly init-rulesSchemly includes a built-in Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and Windsurf to automatically read your schema and generate code.
init_schema- Creates a new schema filegenerate- Generates Laravel code from a schema stringdoctor- Checks project compatibilityanalyze_schema- Returns the schema's AST for the AI to understand your databasecheck_drifts- Checks if generated files have been manually modified
Add the following to your MCP settings or run it directly:
{
"mcpServers": {
"schemly": {
"command": "schemly_mcp"
}
}
}Creates a default schema.schemly file with example models.
# Create schema.schemly in current directory
schemly init
# Create with custom name
schemly init --output my-schema.schemly
# Force overwrite if file exists
schemly init --forceSets up project rules to optimize Schemly AI context.
# Create .cursorrules and .windsurfrules in current directory
schemly init-rules
# Create in a specific directory
schemly init-rules --output /path/to/laravel-projectCompiles the schema into Laravel code.
# Generate all components (reads schema.schemly by default)
schemly generate
# Use custom schema file
schemly generate --file my-schema.schemly
# Generate in specific Laravel project
schemly generate --output /path/to/laravel-project
# Preview what would be generated (dry run)
schemly generate --dry-run
# Force overwrite existing files
schemly generate --force
# Generate only specific components
schemly generate --only models,migrations
schemly generate --only controllers,resources,factories
# Generate everything EXCEPT specific components
schemly generate --exclude requests,dtos
# Use Domain-Driven Design structure
schemly generate --ddd
# Verbose output
schemly generate --verboseAvailable components for --only / --exclude flags:
models- Eloquent modelsmigrations- Database migrationscontrollers- API controllersresources- API resourcesfactories- Model factoriesrequests- Form Requests (Store/Update)dtos- Data Transfer Objectspivot- Pivot tables
Watches the schema file and auto-generates on save (coming soon).
schemly watch
schemly watch --file my-schema.schemlyChecks your Laravel project for compatibility.
# Check current directory
schemly doctor
# Check specific Laravel project
schemly doctor --path /path/to/laravel-projectSchemly comes with three comprehensive examples to get you started:
A simple social media link aggregator similar to Linktree:
- Models: User, Link, Category
- Features: Basic relationships, validation rules, soft deletes
- Perfect for: Learning Schemly basics
schemly generate --file examples/linktree.schemaA complete online store system:
- Models: User, Category, Product, Order, OrderItem, Review, Address, Image
- Features: Complex relationships, decimal pricing, polymorphic images, enums
- Perfect for: Production e-commerce applications
schemly generate --file examples/ecommerce.schemaAn advanced content management system:
- Models: User, Category, Tag, Post, Comment, Media, Newsletter, Subscriber
- Features: DDD structure, many-to-many relationships, polymorphic comments, SEO fields
- Perfect for: Content-heavy applications
schemly generate --file examples/blog.schemaSchemly uses a Prisma-like schema syntax that's modern, readable, and industry-standard.
// Generator configuration
generator laravel {
provider = "schemly"
output = "./app"
}
// Database configuration
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
// Enum definition
enum UserRole {
admin
editor
author
}
// Model definition
model User {
// Fields
id Int @id @default(autoincrement())
name String @db.VarChar(255)
email String @unique
role UserRole @default(author)
// Relationships
posts Post[]
// Model attributes
@@map("users")
@@traits(["HasFactory", "Notifiable"])
@@fillable(["name", "email", "role"])
@@softDeletes
}String- VARCHARInt- INTEGERBigInt- BIGINTFloat- FLOATDecimal- DECIMALBoolean- BOOLEANDateTime- DATETIME/TIMESTAMPJson- JSONBytes- BLOB
@id- Primary key@default(value)- Default value@unique- Unique constraint@map("column_name")- Custom column name@updatedAt- Auto-update timestamp@db.VarChar(255)- Database-specific type@validate("rules")- Laravel validation rules@relation(...)- Relationship definition
@@map("table_name")- Custom table name@@traits([...])- Laravel traits@@fillable([...])- Mass assignable fields@@guarded([...])- Guarded fields@@softDeletes- Soft delete support@@timestamps- Created/updated timestamps
// One-to-Many
model User {
posts Post[]
}
model Post {
userId Int @map("user_id")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
// Many-to-Many (automatic pivot table)
model Post {
tags Tag[]
}
model Tag {
posts Post[]
}For complete syntax reference, see docs/GRAMMAR_COMPARISON.md.
Schemly follows a three-level configuration system:
- Don't overwrite customized controllers
- Generate all components by default
- Use traditional Laravel folder structure
Project-wide settings defined in your schema file:
generator laravel {
provider = "schemly"
output = "./app"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}Command-line flags override everything:
# Override output directory
schemly generate --output /custom/path
# Override safety checks
schemly generate --force
# Override component selection
schemly generate --only models,migrations
schemly generate --exclude dtos,factoriesSchemly generates the following Laravel files:
- Eloquent model classes with relationships, casts, and fillable fields
- Proper namespace and imports
- Trait usage (HasFactory, SoftDeletes)
- Resource controllers with CRUD operations
- Proper imports and type hints
- Form Request classes for
storeandupdateactions - Automatic validation rules mapped from schema fields
- Includes custom
@validate()rules
- API resource classes for JSON responses
- All model fields included
- Model factories for testing and seeding
- Intelligent fake data generation based on field names and types
- Database migration files with proper timestamps
- All field types, constraints, and indexes
- Foreign key relationships
- Pivot table migrations for many-to-many relationships
- Additional fields and timestamps support
By default, schemly will NOT overwrite existing files:
# Safe - skips existing files with warnings
schemly --config models.yml
# Output:
# Warning: File already exists, skipping: ./app/Models/User.php
# Generated model: Post
#
# Summary:
# ✓ 1 files generated successfully
# ⚠ 1 files skipped (already exist)
# Total: 2 files processedUse --force to overwrite existing files:
# Dangerous - overwrites existing files
schemly --config models.yml --force
# Output:
# ⚠️ Warning: --force flag enabled. Existing files will be overwritten!
# Generated model: User
# Generated model: PostSchemly validates your configuration:
- Model names cannot be empty
- Table names cannot be empty
- At least one component type must be enabled
- Enum fields must have enum values
- Relationship configurations are validated
Schemly provides clear error messages:
# Invalid configuration
Error: ModelValidation("Model name cannot be empty")
# File permission issues
Error writing ./app/Models/User.php: Permission denied
# Invalid flag combinations
Error: At least one component type must be enabled for generationBegin with a simple model and gradually add complexity:
model User {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
email String @unique @db.VarChar(255)
@@map("users")
}Field names help generate better fake data:
model User {
firstName String @db.VarChar(100) @map("first_name") // Generates fake()->firstName()
emailAddress String @db.VarChar(255) @map("email_address") // Generates fake()->email()
phoneNumber String @db.VarChar(20) @map("phone_number") // Generates fake()->phoneNumber()
}Always preview what will be generated:
# Preview before generating
schemly generate --dry-run
# Review the output, then generate for real
schemly generateAlways test generated code:
# Generate in a test directory first
schemly generate --output /tmp/test-laravel --dry-run
# Review what would be generated
# Then generate for real
schemly generate --output /tmp/test-laravel
# Review generated files
ls -la /tmp/test-laravel/app/Models/
# Then generate in your real project
schemly generate --output /path/to/real-projectAdd schemly to your development workflow:
# Generate fresh files
schemly generate --force
# Review changes
git diff
# Commit if satisfied
git add .
git commit -m "Regenerate Laravel models from schema"If using an AI like Cursor or Windsurf, generate context rules:
# Generates .cursorrules and .windsurfrules
# Forces AI to rely on Schemly + Schema changes instead of manual Laravel boilerplate
schemly init-rulesCheck your Laravel project before generating:
# Check if project is ready
schemly doctor
# Then generate
schemly generatePermission Denied
# Fix file permissions
chmod 755 /path/to/laravel-project
chmod -R 644 /path/to/laravel-project/app/Models/Invalid Schema Syntax
# Use verbose mode to see detailed parsing errors
schemly generate --verbose
# Or check the schema file manually
cat schema.schemlyMissing Directories
# Use doctor command to check Laravel project structure
schemly doctor
# Or ensure Laravel directory structure exists
mkdir -p app/Models database/migrations app/Http/ControllersFor detailed error information, use Rust's debug output:
RUST_BACKTRACE=1 schemly generategit clone https://github.com/DevPlus31/schemly.git
cd schemly
cargo build
cargo test# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_model_generationThis project is licensed under the MIT License - see the LICENSE file for details.
In version 2.0.0, we completely migrated from YAML to Prisma-like schema syntax. Here's why:
YAML (Old - 28 lines):
models:
- name: User
table: users
timestamps: true
softDeletes: true
fields:
- name: name
type: string
length: 255
nullable: false
- name: email
type: string
length: 255
nullable: false
unique: true
- name: password
type: string
length: 255
nullable: false
relationships:
- type: hasMany
model: Post
foreignKey: user_id
traits:
- HasFactory
- NotifiablePrisma-like (New - 15 lines - 46% less code!):
model User {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
email String @unique @db.VarChar(255)
password String @db.VarChar(255)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
posts Post[]
@@map("users")
@@traits(["HasFactory", "Notifiable"])
@@softDeletes
}✅ ~60% less verbose - More concise, easier to read ✅ Industry standard - Familiar to developers using Prisma ✅ Better tooling - Syntax highlighting, IDE support ✅ Type safety - Clear field types and relationships ✅ Modern syntax - Attributes instead of nested YAML
See CHANGELOG.md for complete version history.
🎉 Major Release - Prisma-like Schema Syntax
Breaking Changes:
⚠️ Complete migration from YAML to Prisma-like schema format⚠️ New CLI structure with subcommands (init,generate,watch,doctor)⚠️ No backward compatibility with YAML files⚠️ Dropped YAML support due to verbosity (~60% reduction in configuration size)
New Features:
- ✅ Prisma-like Syntax: Modern, industry-standard schema definition language
- ✅ New CLI Commands:
init,generate,watch,doctor,init-rules - ✅ Component Pruning: Added
--excludeflag to generate everything EXCEPT specific targets - ✅ Dry Run Mode: Preview what would be generated with
--dry-run - ✅ Doctor Command: Check Laravel project compatibility
- ✅ Improved Component Selection:
--only models,migrationssyntax - ✅ Enhanced Parser: Pest-based grammar with full Prisma compatibility
- ✅ ~60% Reduction: Less verbose configuration compared to YAML
Examples Updated:
- ✅
examples/linktree.schema- 3 models with basic relationships - ✅
examples/blog.schema- 8 models with enums and polymorphic relationships - ✅
examples/ecommerce.schema- 8 models with complex relationships
Documentation:
- 📚 Grammar Comparison: Complete Prisma vs Schemly feature comparison
- 📚 Migration Guide: How to convert from YAML to Prisma-like syntax
- 📚 Updated README: New CLI commands and schema syntax examples
Made with ❤️ and ☕ by developers, for developers.