Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Archetype Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

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:

  • Defining source files in archetypes/YourArchetype/stubs/ and referencing them via ->stub('path/to/stub.blade.php')
  • Using dynamic variables (e.g., {{ $className }}) in stubs for interpolation
  • Hooking into generation steps like afterGenerate() to register routes or run migrations via Artisan::call()
  • Grouping archetypes by domain (e.g., Api/, Console/, Package/) for reusability across projects

Teams 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.

Gotchas and Tips

  • Stub paths are relative to the archetype directory—not the app root. A common mistake is referencing app/Stubs/... instead of archetypes/YourArchetype/stubs/....
  • Variable names in stubs must match the inputs declared in the archetype’s inputs() method. Use required(), optional(), and enum() for strong typing and validation.
  • Remember to clear config cache (php artisan config:clear) after updating config/archetype.php—stale config breaks archetype discovery.
  • For debugging, run with -v to see full generation steps: php artisan archetype:generate YourArchetype -v
  • Use ->dryRun(true) during testing to preview file changes without committing
  • Archetype outputs respect Laravel’s stubs:path config, so align your stub naming with the built-in Laravel conventions (e.g., controller.api.stub) for consistency
  • Consider using Laminas/zend-code or similar for AST-aware replacements in complex files (not built-in, but archetype allows post-processing hooks for this)
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests