Sketch is a powerful Laravel package that transforms your application development workflow. Instead of starting with migrations or models, Sketch allows you to define your entire application structure using simple YAML blueprints. This schema-first approach ensures consistency and accelerates development across your Laravel applications.
-
📝 Blueprint-Based Generation
- Define your entire application structure in YAML
- Generate models, migrations, and services from a single source
- Maintain consistency across your application components
-
⚡ Rapid Development
- Eliminate repetitive boilerplate code
- Generate complete application components in seconds
- Focus on business logic instead of scaffolding
-
🧩 Built-in Relationships
- Support for all Laravel relationships
- Automatic foreign key generation
- Proper relationship method generation
-
🏗️ Service Repository Pattern
- Generate service and repository layers
- Follow SOLID principles automatically
- Maintain clean architecture effortlessly
- Install the package via Composer:
composer require daycode/sketch- Publish the configuration:
php artisan vendor:publish --provider="Daycode\Sketch\SketchServiceProvider"- Create a YAML blueprint:
php artisan sketch:make-blueprint models/blog/post- Define your schema in the generated YAML file:
model: Post
primaryKey:
name: id
type: integer
fields:
- { name: title, type: string, nullable: false }
- { name: content, type: text, nullable: true }
- { name: status, type: enum, nullable: true, options: ['draft', 'published'] }
timestamps: true
softDeletes: true
relationships:
- { type: belongsTo, model: User, foreignKey: user_id }- Execute Specific Files
php artisan sketch:generate --file=schemas/models/blog/post.yamlAfter publishing the configuration file, you can modify these settings in config/sketch.php:
<?php
declare(strict_types=1);
return [
/*
|--------------------------------------------------------------------------
| Schema Path Configuration
|--------------------------------------------------------------------------
|
| This value determines where your YAML schema files will be stored.
| By default, schemas will be placed in the 'schemas' directory
| in the root of your project.
|
*/
'schemas' => [
'path' => base_path('schemas'),
],
/*
|--------------------------------------------------------------------------
| Output Path Configuration
|--------------------------------------------------------------------------
|
| This value determines where your generated files will be placed.
| By default, models will be placed in app/Models,
| migrations in database/migrations, and actions in app/Actions.
|
*/
'paths' => [
'models' => app_path('Models'),
'migrations' => database_path('migrations'),
'requests' => app_path('Http/Requests'),
],
/*
|--------------------------------------------------------------------------
| Stub Path Configuration
|--------------------------------------------------------------------------
|
| This value determines where your stub files are located.
| You can publish these stubs and modify them according to your needs.
|
*/
'stubs' => [
'model' => __DIR__.'/../stubs/model.stub',
'migration' => __DIR__.'/../stubs/migration.stub',
'request' => __DIR__.'/../stubs/form-request.stub',
],
/*
|--------------------------------------------------------------------------
| Default Model Namespace
|--------------------------------------------------------------------------
|
| This value determines the default namespace for your models.
|
*/
'model_namespace' => 'App\\Models',
];Generate Blueprints:
# Simple blueprint
php artisan sketch:make-blueprint post
# Nested directory blueprint
php artisan sketch:make-blueprint models/blog/post
# With soft delete
php artisan sketch:make-blueprint models/blog/post --soft-delete# Generate from blueprint
php artisan sketch:generate --file=path/to/schema.yaml [options]Generation options:
--force: Override existing files--service-repository: Generate both service and repository layers--service-only: Generate service layer only--repository-only: Generate repository layer only
composer testPlease see CONTRIBUTING.md for details on contributing to Sketch.
If you discover any security-related issues, please email daycodestudioproject@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
