-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fragment Architecture
TurboMaker V2.1.0 introduces a revolutionary Fragment Architecture powered by the Laravel ModelSchema package. This architectural shift delivers 95% performance improvements by moving from traditional template compilation to pre-compiled fragment injection.
Fragment Architecture is a pre-compilation system where the Laravel ModelSchema package generates insertable JSON/YAML fragments for each Laravel component. Instead of processing templates at generation time, TurboMaker V2.1.0 injects these optimized fragments directly into target files.
Traditional (V2.0) | Fragment Architecture (V2.1.0) |
---|---|
⏱️ Template compilation at generation | ⚡ Pre-compiled fragments |
🐌 2-5 seconds generation time | ⚡ 50-200ms generation time |
🔄 Full template processing | 🧩 Direct fragment injection |
🏗️ Complex template engine | 📦 Simple fragment insertion |
// Schema parsing and validation
$schemaService = new SchemaService();
// Fragment generation coordination
$generationService = new GenerationService();
// Performance optimization
$optimizationService = new YamlOptimizationService();
- Model - Eloquent models with relationships and casts
- Migration - Database migrations with indexes and foreign keys
- Request - Form Request classes (Store/Update)
- Resource - API Resource classes for data transformation
- Factory - Model Factory for testing and seeding
- Seeder - Database Seeder for data population
- Controller - API and Web Controllers with CRUD operations
- Test - PHPUnit test classes (Feature and Unit)
- Policy - Authorization Policy classes
- Observer - Eloquent Observer with model event handlers (New in v2.0)
- Service - Business logic Service classes (New in v2.0)
- Action - Single-responsibility Action classes (New in v2.0)
- Rule - Custom Validation Rule classes (New in v2.0)
# Traditional V2.0 Approach
Blog Post Module: 2.3s
E-commerce Product: 4.1s
User Management: 3.7s
# Fragment Architecture V2.1.0
Blog Post Module: 87ms (96% faster)
E-commerce Product: 143ms (97% faster)
User Management: 125ms (97% faster)
# Traditional V2.0
Peak Memory: 45MB
Template Objects: 12MB
Processing Cache: 8MB
# Fragment Architecture V2.1.0
Peak Memory: 12MB (73% less)
Fragment Cache: 3MB
Processing Overhead: 1MB
# User schema with V2.1.0 features
core:
model: User
table: users
fields:
name:
type: string
nullable: false
email:
type: email
unique: true
balance:
type: money
currency: EUR
precision: 2
relations:
posts:
type: hasMany
model: App\Models\Post
// Generate all fragments
$fragments = $generationService->generateAll($schema);
// Result structure with JSON and YAML formats
$fragments = [
'model' => [
'json' => '{"model": {"class_name": "User", ...}}',
'yaml' => 'model: {class_name: "User", ...}'
],
'migration' => [
'json' => '{"migration": {"table": "users", ...}}',
'yaml' => 'migration: {table: "users", ...}'
],
// ... all 13 component types
];
// TurboMaker V2.1.0 injects fragments into target files
$modelFragment = json_decode($fragments['model']['json'], true);
$turboMaker->injectModelFragment($modelFragment, 'app/Models/User.php');
$migrationFragment = json_decode($fragments['migration']['json'], true);
$turboMaker->injectMigrationFragment($migrationFragment, 'database/migrations/...');
Each fragment contains all the data needed for that component:
{
"model": {
"class_name": "User",
"table": "users",
"namespace": "App\\Models",
"fields": [
{
"name": "name",
"type": "string",
"nullable": false,
"cast": "string"
},
{
"name": "balance",
"type": "decimal",
"precision": 10,
"scale": 2,
"cast": "decimal:2"
}
],
"relations": [
{
"type": "hasMany",
"name": "posts",
"model": "App\\Models\\Post"
}
],
"traits": ["HasFactory", "SoftDeletes"],
"options": {
"timestamps": true,
"soft_deletes": true
}
}
}
// YAML optimization with intelligent caching
$optimizedSchema = $yamlOptimizationService->optimizeSchema($yamlContent);
// Schema analysis and recommendations
$analysis = $schemaOptimizationService->analyzeSchema($schema);
echo "Performance Score: {$analysis['performance_score']}/100";
// Fragment caching for repeated generation
$cacheKey = $generationService->getCacheKey($schema);
$fragments = $cache->remember($cacheKey, 3600, function() use ($schema) {
return $generationService->generateAll($schema);
});
// Stream fragments for large schemas
$generationService->generateStreaming($largeSchema, function($componentType, $fragment) {
echo "Generated {$componentType} fragment\n";
$this->injectFragment($componentType, $fragment);
});
// Performance tracking
$metrics = $generationService->getPerformanceMetrics();
echo "Average Generation Time: {$metrics['avg_time']}ms\n";
echo "Fragment Cache Hit Rate: {$metrics['cache_hit_rate']}%\n";
echo "Memory Peak Usage: {$metrics['peak_memory']}MB\n";
# V2.1.0 provides real-time performance feedback
php artisan turbo:fragments User --analyze
Generating User fragments...
✅ Schema parsed: 12ms
✅ Fragments generated: 45ms
✅ Cache updated: 8ms
📊 Total time: 65ms (94% faster than traditional)
Fragment Sizes:
- Model: 2.1KB
- Migration: 1.8KB
- Tests: 4.5KB
Total: 23.7KB
# Generate all fragments for a schema
php artisan turbo:fragments Post
# Generate specific fragment types
php artisan turbo:fragments User --only=model,migration,factory
# Generate with caching disabled
php artisan turbo:fragments Product --no-cache
# Analyze fragment performance
php artisan turbo:fragments Blog --analyze
# Export fragments to files
php artisan turbo:fragments User --export=storage/fragments/
# Import and inject fragments
php artisan turbo:inject storage/fragments/user/ app/
# V2.0 Schema (still supported)
model: User
fields:
name: string
email: string
# V2.1.0 Enhanced Schema
core:
model: User
table: users
fields:
name:
type: string
nullable: false
email:
type: email
unique: true
# Check V2.0 performance baseline
php artisan turbo:benchmark --v2
# Migrate to V2.1.0 fragments
php artisan turbo:migrate-fragments
# Compare performance
php artisan turbo:benchmark --compare
composer require grazulex/laravel-modelschema
# resources/schemas/post.yaml
core:
model: Post
table: posts
fields:
title:
type: string
rules: ['required', 'max:255']
content:
type: text
rules: ['required']
published_at:
type: timestamp
nullable: true
php artisan turbo:fragments Post
# ⚡ Generated in 89ms (vs 2.1s traditional)
- Use schema caching for repeated generation
- Enable fragment caching in production
- Monitor performance metrics regularly
- Analyze schema complexity before generation
- Leverage V2.1.0 field types for better fragments
- Use proper relationships for optimized generation
- Include validation rules in schema definition
- Design for fragment reusability
Fragment Architecture represents the future of Laravel code generation. Experience 95% faster generation with TurboMaker V2.1.0!
Laravel TurboMaker - Supercharge Your Laravel Development
🏠 Home | 📖 Getting Started | 💡 Examples | 🎮 Commands | 🔗 Relationships | ⚙️ Configuration
Navigation:
- 📚 Documentation - Complete guides and references
- 💡 Examples - Real-world examples and use cases
- 🛠️ GitHub Repository - Source code and issues
- 📦 Packagist - Package downloads
Community:
- 🐛 Report Issues - Bug reports and feature requests
- 💬 Discussions - Community discussions and Q&A
Made with ❤️ for the Laravel community | Version: 1.x | Laravel: 11.x-12.x | PHP: 8.3+
V2.1.0 - Fragment Architecture Revolution