AI Assistance
Learn how to configure AI assistants like Cursor AI and GitHub Copilot to work seamlessly with GEMVC. Discover GEMVC's built-in AI assistance files and how they help generate correct, type-safe code.
What You'll Learn
AI Assistant Setup
Configure Cursor AI and GitHub Copilot
AI Assistance Files
Understand available AI context files
Code Generation
How AI assistants help generate GEMVC code
Video Coming Soon...
What is GEMVC AI Assistance?
GEMVC comes with comprehensive AI assistance files that help AI assistants (like Cursor AI, GitHub Copilot, Claude, etc.) understand the framework architecture and generate correct code. These files teach AI assistants about GEMVC's 4-layer architecture, security features, and coding patterns.
- Automatic Code Generation - AI assistants can generate complete CRUD operations following GEMVC patterns
- Type-Safe Code - AI understands PHPStan Level 9 requirements and generates type-safe code
- Correct Architecture - AI knows the mandatory 4-layer architecture and never skips layers
- Security Awareness - AI understands that 90% of security is automatic
- Framework-Specific - AI knows GEMVC is NOT Laravel or Symfony
Key Point: GEMVC provides specialized AI assistance files that teach AI assistants how to generate correct GEMVC code. These files are automatically included in your project when you run gemvc init.
How AI Assistance Works
AI Assistant Files
GEMVC provides multiple AI assistance files that are automatically copied to your project root during gemvc init. Each AI tool reads different files:
For Cursor AI
Primary File: .cursorrules
Cursor AI automatically loads .cursorrules from your project root. This file contains comprehensive framework rules, code patterns, and examples that Cursor uses to generate correct GEMVC code.
For GitHub Copilot
Primary Files:
- ✓
GEMVC_GUIDE.md- Code generation patterns - ✓
COPILOT_INSTRUCTIONS.md- Quick instructions - ✓
GEMVC_PHPDOC_REFERENCE.php- PHPDoc annotations for type hints
Copilot reads markdown files in your project root and uses PHPDoc annotations for code completion.
For All AI Assistants
Reference Files:
- ✓
AI_CONTEXT.md- Quick reference guide - ✓
AI_API_REFERENCE.md- Complete API documentation - ✓
QUICK_START_AI.md- Master instructions for AI assistants - ✓
gemvc-api-reference.jsonc- Structured framework data
Setting Up Cursor AI
Automatic Configuration
Cursor AI is automatically configured when you initialize a GEMVC project. The .cursorrules file is created in your project root and Cursor automatically loads it.
What Happens Automatically:
- 1. Run
gemvc initto initialize your project - 2. GEMVC copies
.cursorrulesto your project root - 3. Cursor AI automatically detects and loads
.cursorrules - 4. Cursor now understands GEMVC architecture and patterns
What Cursor AI Learns:
- ✓ 4-layer architecture (API → Controller → Model → Table)
- ✓ Security features (90% automatic)
- ✓ Code generation patterns
- ✓ Type safety requirements (PHPStan Level 9)
- ✓ Common mistakes to avoid
- ✓ Method signatures and return types
Example: Ask Cursor to Create CRUD
After setup, you can ask Cursor:
You:
"Create a Product CRUD endpoint"
Cursor AI:
Generates all 4 layers correctly:
- ✓
app/api/Product.phpwith schema validation - ✓
app/controller/ProductController.phpwith mapping - ✓
app/model/ProductModel.phpwith business logic - ✓
app/table/ProductTable.phpwith database operations
Setting Up GitHub Copilot
Automatic Configuration
GitHub Copilot is automatically configured when you initialize a GEMVC project. Copilot reads markdown files in your project root and uses PHPDoc annotations for code completion.
What Happens Automatically:
- 1. Run
gemvc initto initialize your project - 2. GEMVC copies AI assistance files to your project root:
- •
GEMVC_GUIDE.md - •
COPILOT_INSTRUCTIONS.md - •
GEMVC_PHPDOC_REFERENCE.php
- •
- 3. Copilot automatically reads these files when you code
- 4. Copilot now understands GEMVC patterns and generates correct code
What Copilot Learns:
- ✓ Code generation patterns from
GEMVC_GUIDE.md - ✓ Quick instructions from
COPILOT_INSTRUCTIONS.md - ✓ Type hints from
GEMVC_PHPDOC_REFERENCE.php - ✓ 4-layer architecture requirements
- ✓ Security best practices
Example: Copilot Code Completion
When you start typing, Copilot suggests correct GEMVC code:
<?php
// You type:
public function create(): JsonResponse
{
if(!$this->request->define
// Copilot suggests:
if(!$this->request->definePostSchema([
'name' => 'string',
'email' => 'email'
])) {
return $this->request->returnResponse();
}
return (new ProductController($this->request))->create();
Available AI Assistance Files
Complete File Reference
GEMVC provides multiple AI assistance files, each serving a specific purpose:
.cursorrules (Cursor AI Primary)
Purpose: Comprehensive framework rules for Cursor AI
- ✓ Complete framework understanding
- ✓ Code patterns and examples
- ✓ DO's and DON'Ts
- ✓ Key class references
- ✓ Automatically loaded by Cursor
GEMVC_GUIDE.md (Copilot Primary)
Purpose: Concise guide for code generation
- ✓ Quick start patterns
- ✓ Code generation examples
- ✓ CLI commands reference
- ✓ Essential patterns
COPILOT_INSTRUCTIONS.md (Copilot Reference)
Purpose: Simple instructions for GitHub Copilot
- ✓ Quick reference
- ✓ Essential patterns
- ✓ Common mistakes to avoid
GEMVC_PHPDOC_REFERENCE.php (Type Hints)
Purpose: PHPDoc annotations for code completion
- ✓ Proper type hints
- ✓ Method signatures
- ✓ Copilot-friendly documentation
AI_CONTEXT.md (Quick Reference)
Purpose: Fast lookup for all AI assistants
- ✓ Framework overview
- ✓ Key patterns
- ✓ Common tasks
- ✓ Quick examples
AI_API_REFERENCE.md (Complete API Docs)
Purpose: Complete API documentation for AI assistants
- ✓ Full class reference
- ✓ Method signatures
- ✓ Parameters and return types
- ✓ Common patterns
QUICK_START_AI.md (Master Instructions)
Purpose: MASTER instructions for AI assistants
- ✓ Forces AI to read ALL documentation
- ✓ Complete architecture understanding
- ✓ Code generation patterns
- ✓ Critical rules and conventions
gemvc-api-reference.jsonc (Structured Data)
Purpose: Machine-readable framework data
- ✓ Structured framework metadata
- ✓ Programmatic access
- ✓ Code generation tools
How AI Assistants Help
Code Generation Examples
With AI assistance configured, AI assistants can generate correct GEMVC code following all framework patterns:
Example 1: Generate Complete CRUD
You ask: "Create a Product CRUD endpoint"
AI generates: All 4 layers with correct patterns:
<?php
// app/api/Product.php
class Product extends ApiService
{
public function create(): JsonResponse
{
if(!$this->request->definePostSchema([
'name' => 'string',
'price' => 'float',
'?description' => 'string'
])) {
return $this->request->returnResponse();
}
return (new ProductController($this->request))->create();
}
}
AI automatically generates Controller, Model, and Table layers following the same patterns!
Example 2: Add Authentication
You ask: "Add authentication to Product create endpoint"
AI generates:
<?php
public function create(): JsonResponse
{
// AI knows to add authentication first!
if (!$this->request->auth(['admin', 'salesManager'])) {
return $this->request->returnResponse();
}
// Then schema validation
if(!$this->request->definePostSchema([
'name' => 'string',
'price' => 'float'
])) {
return $this->request->returnResponse();
}
return (new ProductController($this->request))->create();
}
Example 3: Type-Safe Code
You ask: "Create a method to get product by ID"
AI generates: PHPStan Level 9 compliant code:
<?php
// AI knows to use proper return types!
public function selectById(int $id): null|static
{
$result = $this->select()
->where('id', $id)
->limit(1)
->run();
return $result[0] ?? null; // ✅ Type-safe!
}
Benefits of AI Assistance
✅ Consistent Code Generation
AI generates code following GEMVC patterns consistently, ensuring all code follows the same architecture.
✅ Type-Safe Code
AI understands PHPStan Level 9 requirements and generates type-safe code with proper type hints.
✅ Security Built-In
AI knows that 90% of security is automatic and only adds necessary schema validation and authentication.
✅ Correct Architecture
AI never skips layers and always generates all 4 layers (API, Controller, Model, Table) correctly.
✅ Faster Development
AI can generate complete CRUD operations in seconds, following all GEMVC best practices.
✅ Fewer Mistakes
AI knows common mistakes to avoid (like using Laravel patterns) and generates correct GEMVC code.
File Location Reference
After running gemvc init, you'll find these files in your project root:
Usage Tips
💡 Be Specific in Your Requests
The more specific you are, the better AI can generate code:
✅ Good:
"Create a Product CRUD endpoint with authentication for admin and salesManager roles"
❌ Less Effective:
"Create product endpoint"
💡 Review Generated Code
Always review AI-generated code. Run PHPStan to check type safety, and test the generated endpoints to ensure they work correctly.
💡 Use CLI for Complete CRUD
For complete CRUD operations, you can also use CLI commands:
# Generate complete CRUD
gemvc create:crud Product
# Then customize with AI assistance
💡 Combine CLI and AI
Best practice: Use CLI to generate the structure, then use AI assistance to add custom logic, validations, or complex features.
Important Notes
-
Automatic Setup: AI assistance files are automatically copied during
gemvc init. No manual configuration needed! -
Cursor AI: Automatically loads
.cursorrulesfrom project root. Just initialize your project and Cursor will understand GEMVC. - GitHub Copilot: Automatically reads markdown files in project root. Make sure files are in the root directory for best results.
- Always Review: While AI generates correct code, always review and test it. Run PHPStan to ensure type safety.
- Framework-Specific: AI assistants understand that GEMVC is NOT Laravel or Symfony and will generate GEMVC-specific code.
🤖 AI Assistance Ready!
Excellent! You've learned how GEMVC's AI assistance works. After running gemvc init, your AI assistant will automatically understand GEMVC architecture and generate correct code!