# ThrillWiki Custom Artisan Commands **Created**: June 13, 2025 **Purpose**: Documentation for custom Laravel artisan commands that accelerate ThrillWiki development ## 🚀 Overview Custom artisan commands implement the development acceleration strategy by providing automated code generation with built-in ThrillWiki patterns, optimization, and best practices. ## 📋 Available Commands ### 1. make:thrillwiki-livewire **Purpose**: Generate optimized Livewire components with ThrillWiki patterns and performance optimizations. **Location**: [`app/Console/Commands/MakeThrillWikiLivewire.php`](../app/Console/Commands/MakeThrillWikiLivewire.php) #### Command Signature ```bash php artisan make:thrillwiki-livewire {name} [options] ``` #### Options - `--reusable` : Generate a reusable component with optimization traits - `--with-tests` : Generate test files for the component - `--cached` : Add caching optimization to the component - `--paginated` : Add pagination support to the component - `--force` : Overwrite existing files #### Examples ```bash # Basic component php artisan make:thrillwiki-livewire RideCard # Reusable component with caching and tests php artisan make:thrillwiki-livewire SearchableList --reusable --cached --with-tests # Paginated component with tests php artisan make:thrillwiki-livewire RideResults --paginated --with-tests # Force overwrite existing component php artisan make:thrillwiki-livewire UserProfile --reusable --force ``` #### Generated Files 1. **Component Class**: `app/Livewire/{ComponentName}.php` 2. **View Template**: `resources/views/livewire/{component-name}.blade.php` 3. **Test File** (if `--with-tests`): `tests/Feature/Livewire/{ComponentName}Test.php` ## 🎯 Features & Optimizations ### Built-in ThrillWiki Patterns #### 1. Component Structure - Consistent namespace and class structure - ThrillWiki-specific naming conventions - Optimized import statements - Performance-focused lifecycle hooks #### 2. View Templates - **Basic Template**: Simple, clean structure for standard components - **Reusable Template**: Advanced template with: - Loading states with Alpine.js - Responsive design with Tailwind - Dark mode support - Interactive elements with proper wire: directives #### 3. Test Generation - Complete test suite with ThrillWiki patterns - Component rendering tests - Mount success tests - Pattern compliance verification tests - Ready-to-extend test structure ### Performance Optimizations #### 1. Caching Integration ```php // Auto-generated caching methods protected function getCacheKey(string $suffix = ''): string protected function remember(string $key, $callback, int $ttl = 3600) protected function invalidateCache(string $key = null): void ``` #### 2. Pagination Support - Automatic WithPagination trait inclusion - Tailwind CSS theme configuration - Query string parameter handling #### 3. Reusable Component Features - Optimization traits for performance - Modular design principles - Component state management - Event handling patterns ## 🛠 Implementation Details ### Command Architecture #### 1. File Generation Strategy - **Stub-based Templates**: Flexible template system with placeholder replacement - **Dynamic Content**: Options-based content generation - **Directory Management**: Automatic directory creation and validation - **Conflict Resolution**: Force overwrite option with user confirmation #### 2. Template System ```php // Component stub with dynamic sections {IMPORTS} // Dynamic import statements {CLASS_NAME} // Component class name {TRAITS} // Optional trait inclusions {PROPERTIES} // Component properties {METHODS} // Optional methods (caching, etc.) {VIEW_NAME} // Kebab-case view name ``` #### 3. Option Processing - **Boolean Options**: Enable/disable features (`--cached`, `--reusable`) - **Conditional Logic**: Generate different code based on options - **Validation**: Ensure valid component names and file paths - **User Feedback**: Comprehensive success messages and next steps ### Integration with Development Workflow #### 1. Acceleration Benefits - **50% Faster Component Creation**: Pre-built templates with optimization - **Consistent Patterns**: All components follow ThrillWiki standards - **Built-in Testing**: Automatic test generation reduces QA time - **Performance by Default**: Optimization patterns built-in #### 2. Developer Experience - **Rich CLI Output**: Colored, formatted command output - **Helpful Guidance**: Next steps and usage instructions - **Error Handling**: Clear error messages and suggestions - **File Overview**: Summary of generated files and features ## 📊 Usage Patterns ### Recommended Workflows #### 1. Standard Component Development ```bash # Step 1: Generate component with tests php artisan make:thrillwiki-livewire MyComponent --with-tests # Step 2: Customize component logic # Edit app/Livewire/MyComponent.php # Step 3: Update view template # Edit resources/views/livewire/my-component.blade.php # Step 4: Run tests php artisan test --filter MyComponentTest ``` #### 2. Reusable Component Development ```bash # Generate optimized reusable component php artisan make:thrillwiki-livewire SharedComponent --reusable --cached --with-tests # Result: Component with caching, optimization traits, and comprehensive tests ``` #### 3. List/Table Components ```bash # Generate paginated list component php artisan make:thrillwiki-livewire ItemList --paginated --cached --with-tests # Result: Component with pagination, caching, and optimized queries ``` ### Integration with Existing Codebase - **Namespace Compliance**: Generated components follow app namespace structure - **View Integration**: Templates ready for inclusion in existing layouts - **Test Integration**: Tests integrate with existing test suite - **Pattern Consistency**: Matches existing ThrillWiki component patterns ## 🔄 Future Enhancements ### Implemented Commands 1. ✅ **make:thrillwiki-livewire** - Livewire component generation with optimization patterns 2. ✅ **make:thrillwiki-crud** - Complete CRUD generation with controller, views, and routes 3. ✅ **make:thrillwiki-model** - Model generation with ThrillWiki traits and relationships ### Planned Command Extensions 1. **make:thrillwiki-api** - API resource generation with optimization 2. **make:thrillwiki-service** - Service layer generation with caching patterns 3. **make:thrillwiki-seeder** - Data seeder generation with realistic test data ### Advanced Features 1. **Interactive Mode**: Guided component generation with prompts 2. **Template Customization**: User-defined template overrides 3. **Batch Generation**: Generate multiple related components 4. **Integration Hooks**: Pre/post generation hooks for custom logic ## 📝 Best Practices ### Component Generation Guidelines 1. **Use Descriptive Names**: Clear, purpose-driven component names 2. **Choose Appropriate Options**: Select options that match component purpose 3. **Review Generated Code**: Customize templates to fit specific needs 4. **Test Early**: Run generated tests to ensure proper setup 5. **Document Usage**: Document component purpose and reuse patterns ### Performance Considerations 1. **Use Caching Wisely**: Enable caching for data-heavy components 2. **Pagination for Lists**: Always use pagination for large datasets 3. **Optimize Queries**: Leverage eager loading in generated components 4. **Monitor Performance**: Track component rendering times ### Development Workflow Integration 1. **Version Control**: Commit generated files with descriptive messages 2. **Code Review**: Review generated code for project-specific customization needs 3. **Testing**: Extend generated tests with component-specific scenarios 4. **Documentation**: Update component documentation in memory bank