ajthinking/archetype
Laravel package for defining and instantiating “archetypes” to generate consistent model data and fixtures. Helps standardize defaults, variations, and seeding/test setup by composing reusable templates for your app’s entities.
Start by installing the package via Composer: composer require ajthinking/archetype. After installation, publish the configuration with php artisan vendor:publish --provider="Ajthinking\Archetype\ArchetypeServiceProvider". The config file (config/archetype.php) defines where archetypes are stored (default: app/Archetypes). Your first step should be defining a basic archetype—e.g., app/Archetypes/ResourceApi.php—that scaffolds a model, controller, and resource route. Use the provided archetype:make command to scaffold your first template: php artisan archetype:make ApiResource. This generates a starter class with placeholders for defining inputs, stubs, and post-generation steps.
Archetypes are defined as PHP classes extending Ajthinking\Archetype\Archetype, using a fluent DSL to declare sources (files or directories), stubs (Blade-style templates), and actions (e.g., moving, updating config, running commands). A typical pattern involves:
archetypes/YourArchetype/stubs/ and referencing them via ->stub('path/to/stub.blade.php'){{ $className }}) in stubs for interpolationafterGenerate() to register routes or run migrations via Artisan::call()Api/, Console/, Package/) for reusability across projectsTeams often build an internal BaseArchetype to share common conventions (e.g., naming strategies, path resolution, PSR-4 mappings) and extend it per-project. Archetypes can be registered dynamically via Archetype::add() or statically in the config.
app/Stubs/... instead of archetypes/YourArchetype/stubs/....inputs() method. Use required(), optional(), and enum() for strong typing and validation.php artisan config:clear) after updating config/archetype.php—stale config breaks archetype discovery.-v to see full generation steps: php artisan archetype:generate YourArchetype -v->dryRun(true) during testing to preview file changes without committingstubs:path config, so align your stub naming with the built-in Laravel conventions (e.g., controller.api.stub) for consistencyHow can I help you explore Laravel packages today?