daycode/sketch

Sketch is a powerful, easy-to-use package for rapidly generating YAML-Based CRUD functionality in Laravel applications.

v2.0.0 2025-01-26 08:23 UTC

This package is auto-updated.

Last update: 2025-01-26 09:19:54 UTC


README

Sketch Logo

Latest Stable Version Total Downloads License

Blueprint-Based Structure Generator

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.

Features

  • 📝 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

Quick Installation

  1. Install the package via Composer:
composer require daycode/sketch
  1. Publish the configuration:
php artisan vendor:publish --provider="Daycode\Sketch\SketchServiceProvider"

Quick Usage

  1. Create a YAML blueprint:
php artisan sketch:make-blueprint models/blog/post
  1. 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 }
  1. Execute Specific Files
php artisan sketch:generate --file=schemas/models/blog/post.yaml

Configuration

After 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',

];

Available Commands

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

Component Generation

# 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

Testing

composer test

Contributing

Please see CONTRIBUTING.md for details on contributing to Sketch.

Security

If you discover any security-related issues, please email daycodestudioproject@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.