#}

RESTful API Features

You are the master of your code — GEMVC recommends, never forces

API Features & Code Generation

GEMVC Philosophy

GEMVC believes you are the master of your code. We provide powerful tools and recommendations, but never force any particular structure. Customize everything to match your team's standards!

Customizable Template System

GEMVC's template system lets you define exactly how your generated code should look:

Custom Code Style

Match your team's coding standards and conventions

Add Helper Methods

Include custom utility methods in generated classes

Change Structure

Use Repository pattern or any architecture you prefer

Project Comments

Add team-specific documentation and notes

How It Works

1. Initialize Project

Templates are copied to your project root

2. Customize Templates

Edit templates to match your style

3. Generate Code

Your custom templates are used!

Template Workflow
# Step 1: Initialize project (copies templates to your project)
gemvc init

# Templates are now in your project:
# templates/cli/
#    ├── service.template
#    ├── controller.template
#    ├── model.template
#    └── table.template

# Step 2: Customize templates (optional)
vim templates/cli/service.template

# Step 3: Generate code using YOUR templates
gemvc create:crud Product
# Generated files match YOUR custom template!
Tip: After gemvc init, you own the templates! Edit them freely to match your coding standards. Version control them so your entire team uses the same style.

CLI Commands

1

Initialize Project

Terminal
gemvc init
Tip: Creates project structure + copies templates to your project root
2

Create Complete CRUD

Terminal
gemvc create:crud Product
Tip: Generates Service, Controller, Model, Table using YOUR templates
3

Migrate Database

Terminal
gemvc db:migrate ProductTable
Tip: Creates database table based on your Table class

Generated Files

Running gemvc create:crud Product generates:

# 4-Layer Architecture
✅ app/api/Product.php ← API Service (endpoint handlers)
✅ app/controller/ProductController.php ← Business logic
✅ app/model/ProductModel.php ← Data validation
✅ app/table/ProductTable.php ← Database operations

Template Customization Example

Here's how you can customize your templates:

Customized Service Template
<?php
// templates/cli/service.template - YOUR CUSTOM VERSION

/**
 * {$serviceName} API Service
 * 
 * @team Backend Team
 * @project MyApp
 * @generated Auto-generated by GEMVC CLI
 */
class {$serviceName} extends ApiService
{
    /**
     * Create new {$serviceName}
     * Custom implementation with logging
     */
    public function create(): JsonResponse
    {
        // Your custom logging
        error_log('Creating {$serviceName}: ' . json_encode($this->request->post));
        
        // Your custom validation
        if (!$this->validateBusinessRules()) {
            return $this->request->returnResponse()->badRequest('Validation failed');
        }
        
        // Original CRUD logic
        $controller = new {$serviceName}Controller($this->request);
        return $controller->create();
    }
    
    // Add your custom helper method
    private function validateBusinessRules(): bool
    {
        // Your business logic here
        return true;
    }
}
info: Variables like {$serviceName} and {$tableName} are automatically replaced during generation. You can add your own patterns!

Template Lookup Priority

  1. 1 Your project templates: {project}/templates/cli/*.template ✅ Used first!
  2. 2 Vendor defaults: vendor/gemvc/.../templates/ ← Fallback only

Best Practices

  • Version control templates: git add templates/cli/*.template
  • Team consistency: All team members use same templates via Git
  • Test changes: Generate test entity first to verify template changes
  • Backup originals: Keep original templates before heavy customization

Next Steps