glugox / magic
Tools for creating magic!
                                    Fund package maintenance!
                                                                            
                                                                                                                                        glugox
                                                                                    
                                                                
Installs: 31
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/glugox/magic
Requires
- php: ^8.4
- glugox/ai: *
- glugox/model-meta: *
- glugox/table-query: *
- illuminate/contracts: ^10.0||^11.0||^12.0
- prism-php/prism: ^0.86.0
Requires (Dev)
- driftingly/rector-laravel: ^2.0
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.24
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.6
- pestphp/pest: ^4.1
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- rector/rector: ^2.1
- spatie/laravel-ray: ^1.35
Suggests
- inertiajs/inertia-laravel: Needed when using Inertia routes
- dev-main
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-ai/add-base-provider-and-http-abstractions
- dev-ai/create-glugox/module-package-skeleton-and-migrate-code
- dev-ai/fix-undefined-auth-guard-error-q36a7t
- dev-ai/fix-undefined-auth-guard-error-hvmh2d
- dev-ai/fix-undefined-auth-guard-error-5nqux5
- dev-ai/fix-undefined-auth-guard-error
- dev-ai/fix-controller-inheritance-in-package-mode
- dev-ai/fix-routing-issue-for-crm-module
- dev-ai/investigate-build-package-module-issues
- dev-ai/update-magicconfigvalidator-for-array-validation
- dev-ai/fix-validation-for-entities-in-magic-build
- dev-codex/locate-build-issues-in-package-mode
- dev-codex/add-hasname-trait-in-package-mode
- dev-codex/troubleshoot-namespace-application-issue
- dev-codex/add-console-command-for-json-validation
- dev-codex/add-module.json-generation-for-billing
- dev-codex/change-magic-package-generation-location-i8sokd
- dev-codex/change-magic-package-generation-location-feibdl
- dev-codex/change-magic-package-generation-location
- dev-codex/fix-phpstan-errors-to-max-level
- dev-codex/fix-magic-reset-to-fully-clean-up-files
- dev-codex/fix-selection-of-newly-created-related-object
- dev-codex/analyze-code-quality-for-mcp-server-creation
This package is auto-updated.
Last update: 2025-10-31 16:41:15 UTC
README
A Laravel code generator that turns JSON entity definitions into a working application or a reusable Composer package. Magic wires migrations, models, controllers, Vue/Inertia pages, tests, and boilerplate Laravel setup so you can prototype or bootstrap production features in minutes.
Table of contents
- What Magic does
- Requirements
- Installation
- Running the generator
- Understanding configuration
- Package mode
- File generation reference
- Resetting a build
- Customising stubs & namespaces
- Testing and quality tools
- Troubleshooting
- Contributing
- License
What Magic does
Magic reads a JSON schema that describes your domain (entities, relations, presets, UI metadata) and executes a predictable build pipeline:
- Resolve configuration and normalise paths.
- Publish starter assets and language files.
- Install the required Composer and NPM dependencies (host builds only).
- Generate migrations, models, enums, factories, seeders, REST controllers, form requests, API resources, TypeScript definitions, Vue pages, and Pest tests.
- Register routes, Sanctum middleware, queues, and Inertia bootstrapping when targeting a Laravel application.
- Produce a manifest of generated files so resets can be executed safely.
Every build step is implemented as a dedicated action under src/Actions/Build, making the pipeline easy to extend or re-order for your own needs.
Requirements
| Requirement | Version | 
|---|---|
| PHP | ^8.4 | 
| Laravel | 10.x – 12.x | 
| Node.js & npm | Required for front-end scaffolding | 
| Composer | Latest stable | 
Tip: Magic ships as a regular Laravel package. You can install it globally in a host Laravel app or use package mode to generate a standalone Composer package that you pull into multiple projects.
Installation
Install into a Laravel application
- Create or open a Laravel application that already has Breeze/Inertia (Vue) installed.
- Require Magic as a dev dependency:
composer require glugox/magic --dev 
- Publish the configuration file:
php artisan vendor:publish --provider="Glugox\\Magic\\MagicServiceProvider"
- Optional: explore the sample configurations in stubs/samples.
Install for package generation
If you plan to generate re-usable features as a package, install Magic in a throwaway Laravel project and run the generator with the package flags (described below). Magic will emit a new Composer package that you can require in your real application.
Running the generator
Magic exposes one primary Artisan command:
php artisan magic:build [options]
| Option | Description | 
|---|---|
| --config= | Absolute or relative path to a JSON configuration file. | 
| --starter= | Name of a starter config shipped with Magic (e.g. inventory,task). | 
| --set= | Inline overrides using dot notation ( --set=app.name="Acme"). Repeatable. | 
| --package-path= | Destination directory for Composer package builds. Creates the folder if missing. | 
| --package-namespace= | Root PSR-4 namespace to use when generating a package (e.g. Acme\Inventory). | 
| --package-name= | Composer package name for package builds (e.g. acme/inventory-kit). | 
Examples:
# Generate directly into the Laravel application php artisan magic:build --starter=inventory # Generate a package under ./packages/inventory-kit php artisan magic:build \ --config=stubs/samples/inventory.json \ --package-path=packages/inventory-kit \ --package-namespace=Acme\\Inventory \ --package-name=acme/inventory-kit
Magic prevents accidental overwrites by checking for storage/magic/generated_files.json. Run php artisan magic:reset (see below) before triggering a new build in the same environment.
Understanding configuration
- Configuration files follow json-schema.jsonand can be validated automatically by most editors.
- Each config declares global app metadata (name, base namespace overrides, Faker mappings, seeding flags) and an array of entities.
- Entities describe fields, relations, filters, table presets, navigation icons, and test scenarios.
- Sample configs live in stubs/samples; theinventory.jsonexample demonstrates most features.
A minimal entity definition:
{
  "app": {
    "name": "Inventory",
    "seedEnabled": true
  },
  "entities": [
    {
      "name": "Product",
      "icon": "Package",
      "fields": [
        { "name": "name", "type": "string", "rules": ["required"] },
        { "name": "sku", "type": "string", "unique": true },
        { "name": "price", "type": "decimal", "precision": 12, "scale": 2 }
      ],
      "relations": [
        { "type": "belongsTo", "name": "category", "entity": "Category" }
      ]
    }
  ]
}
When a build runs, the configuration is parsed into strongly typed objects (src/Support/Config) so generators can reason about default values and relationships safely.
Package mode
Package mode rewires Magic so that every generated file lands inside a Composer package instead of your Laravel app. Three options must be provided: --package-path, --package-namespace, and --package-name.
Key behaviours:
- MagicPathsswaps Laravel helpers (app_path, database_path, etc.) for equivalents rooted inside the target package directory.
- MagicNamespacesensures PHP namespaces resolve under your chosen base namespace (controllers, models, resources, providers, and tests are all updated).
- InitializePackageActionprepares the destination by creating a Laravel-like directory tree, generating a Composer manifest with PSR-4 autoloading, and scaffolding a- MagicPackageServiceProviderthat registers routes, views, migrations, and translations when installed into a host app.
- Host-only steps—environment tweaks, dependency installation, queue setup, Sanctum middleware mutations, and Vue bootstrapping—are skipped so the package remains framework-agnostic.
- Seeders generated inside a package avoid touching DatabaseSeeder.php; consumers can opt-in by calling the package service provider’s seeders manually.
After running the generator in package mode:
- Commit the generated package to its own repository (or keep it inside a monorepo under packages/).
- Require it from your real Laravel application via VCS or path repositories.
- Register the generated service provider if you disable Laravel’s automatic package discovery.
Example of generating a package called glugox/module-a with the orchestrator starter:
php artisan magic:build --package-path ./modules/glugox/module-a --package-name glugox/module-a --package-namespace Glugox\\ModuleA --starter orchestrator
File generation reference
| Area | What gets generated | 
|---|---|
| Database | Timestamped migrations, model factories, individual seeders. | 
| Domain | Eloquent models, relationships, query scopes, enums, Meta classes, console commands for entity actions. | 
| HTTP layer | API controllers, form requests, API resources, routes ( routes/app.php,routes/app/api.php) and attachable asset support. | 
| Front-end | Vue 3 pages (index, create, edit, detail), shared components, TypeScript DTOs, lucide icon imports, composables. | 
| Testing | Pest feature tests for CRUD operations, HTTP tests, and package-specific coverage. | 
| DevOps | Magic manifest under storage/magic, queue installation helpers,.envupdates (host builds only). | 
Refer to the corresponding action classes in src/Actions/Build for implementation details.
Resetting a build
Use the reset command when you need to revert the generated artefacts inside a Laravel application:
php artisan magic:reset --starter=inventory
magic:reset replays the manifest from storage/magic/generated_files.json, deletes migrations, models, seeders, controllers, Vue pages, TypeScript artefacts, and restores modified Laravel files to their original state before optionally refreshing the database. Package builds can be reset manually by deleting the destination directory and re-running magic:build.
Customising stubs & namespaces
- All PHP and Vue stubs live under stubs/; copy them into your application and updateconfig/magic.phpif you need to override defaults.
- MagicNamespaceslets you change the base namespace for generated classes. Provide the- --package-namespaceoption or edit the configuration’s- app.namespacevalue when targeting a Laravel app.
- MagicPathscentralises every filesystem lookup so package builds, tests, and workbench usage stay isolated. Clearing paths/namespaces after each command prevents leakage into subsequent Artisan calls.
Testing and quality tools
The project uses Pest, PHPStan, Laravel Pint, and Rector. Run everything locally with:
composer install composer test # pest + pint --test composer analyse # phpstan composer format # pint (fixes)
When contributing, make sure your feature and unit tests cover new behaviour—especially when altering generators or stubs.
Troubleshooting
- Manifest file existerror – run- php artisan magic:resetbefore starting a new build in the same Laravel project.
- Missing Vue components in package builds – Magic scaffolds Vue files from built-in stubs when resources/js/components/AppSidebar.vueorAppLogo.vueis absent.
- Routes not registered after installing a package – confirm that the generated MagicPackageServiceProvideris discovered (Composer autoload dump + Laravel package discovery) and thatroutes/app.phpandroutes/app/api.phpexist in your package.
- Need to skip seeding in a package – by design Magic avoids touching DatabaseSeeder.phpduring package builds; call package seeders manually from the consuming app if required.
Contributing
Issues and pull requests are welcome! If you are planning a large change, please open an issue first so we can discuss scope and direction. When submitting a PR:
- Add or update tests.
- Run the QA commands listed above.
- Document user-facing changes in this README or the changelog.
You can also reach out directly at ervinbeciragic@gmail.com.
License
Magic is open-sourced software licensed under the MIT license.