7

Phase 7: Code Generation

Powerful automated code generation tools that create complete Laravel components including models, Filament resources, factories, seeders, and policies with intelligent defaults and customization options.

Overview

Web-Based Generation

Generate Laravel components through intuitive web interfaces with real-time preview and intelligent suggestions.

  • Model analysis and field suggestions
  • Real-time code preview
  • Form-based configuration
  • Intelligent field type mapping

Available Generators

Complete set of code generators accessible through the admin panel under "Code Generators" navigation group.

  • Migration Generator
  • Model Generator
  • Factory Generator
  • Seeder Generator
  • Filament Resource Generator

Access Code Generators

1

Navigate

Go to "Code Generators" in admin panel navigation

2

Configure

Use web forms to configure generation options

3

Generate

Preview and generate files with one click

Model Generation

Web-Based Model Generator

Access the Model Generator through the admin panel under "Code Generators" → "Model Generator".

Available Features:

  • Namespace and class configuration
  • Table name mapping
  • Fillable, guarded, hidden fields
  • Type casting configuration
  • Relationship definitions

Intelligent Suggestions:

  • Database-driven field suggestions
  • Foreign key relationship detection
  • Security field detection
  • Laravel trait integration
  • Best practices compliance

Service Integration

The Model Generator uses dedicated service classes for intelligent generation.

ModelGeneratorService

Core service for generating Eloquent models with comprehensive feature support.

HkDevs\CodeForgeStudio\Services\ModelGeneratorService

IntelligentSuggestionService

Provides smart suggestions based on database schema analysis and Laravel conventions.

Filament Resource Generation

Comprehensive Resource Generator

Access through "Code Generators" → "Filament Resource" in the admin panel for complete resource generation.

Form Configuration

  • • Text Input with validation
  • • Email, Password, Number fields
  • • Textarea with row configuration
  • • Select, Radio, Checkbox components
  • • Date/Time pickers
  • • File/Image uploads
  • • Rich Text and Markdown editors
  • • Color picker and hidden fields
  • • Relationship fields (all types)

Table Configuration

  • • Text columns with formatting
  • • Badge columns with color mapping
  • • Boolean columns with icons
  • • Image columns with size control
  • • Date/DateTime formatting
  • • Color display columns
  • • Money columns with currency
  • • Relationship columns

Real-Time Features:

  • Live code preview with tabs
  • Model analysis and suggestions
  • Field type-specific configuration panels
  • Professional Filament code generation

Advanced Configuration

Type-specific configuration panels that show relevant options based on selected field types.

Model Selection

Choose from existing Laravel models

Field Configuration

Configure forms, tables, and filters

Live Preview

See generated code in real-time

Service Integration:

Powered by FilamentResourceGeneratorService for comprehensive resource generation with intelligent field mapping and relationship handling.

Factory & Seeder Generation

Factory Generator

Access through "Code Generators" → "Factory Generator" for intelligent model factory creation.

Available Features:

  • Model introspection and analysis
  • Intelligent field type detection
  • Faker method suggestions
  • Relationship-aware generation
  • Factory states and traits

Service Integration:

  • FactoryGeneratorService
  • Intelligent field mapping
  • Localization support
  • Custom provider integration

Seeder Generator

Access through "Code Generators" → "Seeder Generator" for comprehensive database seeding.

Intelligent Data Generation

Automatically generate realistic test data with proper relationships and constraints.

SeederGeneratorService Integration

Powered by dedicated service for comprehensive seeder generation with batch processing and relationship handling.

Configuration Options:

  • • Record count and batch size
  • • Factory integration
  • • Transaction handling
  • • Environment-specific seeding
  • • Foreign key management
  • • Table truncation options

Policy Generation

Feature Status

Policy generation is available through the AdvancedCodeGenerationService but does not have a dedicated web interface yet. Policies can be generated programmatically or through the code generation service integration.

Available Through Service Layer:

  • • Standard CRUD authorization methods
  • • Custom policy method generation
  • • User and model parameter handling
  • • Integration with generated resources

Available Commands

CodeForge Studio Commands

Available Artisan commands for CodeForge Database Studio operations.

Plugin Management

php artisan codeforge:install

Install and configure CodeForge Database Studio plugin.

Documentation Generation

php artisan codeforge:generate-docs

Generate comprehensive database documentation in multiple formats.

Data Management

php artisan codeforge:generate-data
php artisan codeforge:run-seeders

Generate test data and run database seeders.

Migration Management

php artisan codeforge:migration
php artisan codeforge:batch-migrate

Advanced migration management and batch operations.

Web Interface Recommended

While some commands are available, the primary interface for code generation is through the web-based generators in the admin panel. These provide better user experience with real-time preview and intelligent suggestions.

Access Generators:

Navigate to "Code Generators" in your admin panel for the full code generation experience.

Customization

Configuration File

Customize code generation through the configuration file published during installation.

Configuration Location:

config/codeforge-database-studio.php

Available Settings:

  • • Default namespaces for generated files
  • • Output path configurations
  • • Template customization options
  • • Field type mapping rules

Service Customization:

  • • Extend generator services
  • • Custom field type mappings
  • • Template overrides
  • • Custom suggestion logic

Stub Templates

The plugin uses stub template system for code generation, allowing for customization and extension.

Template Service Integration:

HkDevs\CodeForgeStudio\Services\StubTemplateService

Handles template loading, population, and customization for all code generation operations.

Field Type Mapping

Customize how database column types are mapped to form fields and table columns in Filament resources.

FilamentResourceGeneratorService

Contains comprehensive field type mapping logic with support for all Filament form and table components.

Intelligent Suggestions

The IntelligentSuggestionService provides context-aware suggestions based on field names, types, and Laravel conventions.

Best Practices

Code Generation Workflow

Follow these best practices for efficient and maintainable code generation using the web interface.

1

Use the Generator Overview

Start with the "Code Generator Overview" page to understand available generators and choose the right tool for your needs.

2

Preview Before Generation

Always review the generated code in the preview tabs before creating files to ensure it matches your requirements.

3

Leverage Intelligent Suggestions

Use the intelligent suggestions provided by the generators based on your existing models and database schema.

4

Customize After Generation

Use generated code as a starting point and customize it to match your specific business requirements and coding standards.

Service Integration

Understanding the service layer helps you make the most of the code generation features.

Core Services:

  • ModelGeneratorService
  • FilamentResourceGeneratorService
  • FactoryGeneratorService
  • SeederGeneratorService

Support Services:

  • IntelligentSuggestionService
  • StubTemplateService
  • SchemaAnalyzerService
  • AdvancedCodeGenerationService

Getting Started Guide

First Steps:

  • Navigate to "Code Generators" in admin panel
  • Start with the Generator Overview page
  • Try generating a simple model first
  • Explore the real-time preview features

Production Use:

  • Review and test all generated code
  • Customize based on business requirements
  • Use version control for generated files
  • Document customizations for team reference