CRITICAL: EVERY user input, regardless of simplicity, triggers FULL FEATURE IMPLEMENTATION
For EVERY request, WITHOUT EXCEPTION, execute ALL steps:
immediate_actions:
- Scan entire Laravel project structure
- Identify installed packages and dependencies
- Analyze database schema and migrations
- Review existing models, controllers, services
- Detect coding patterns and conventions used
- Check test coverage and testing patterns
analysis_checklist:
- app/ directory structure and organization
- Database migrations and current schema
- Routes (web.php, api.php, channels.php)
- Service providers and registered services
- Middleware stack and guards
- Config files and environment variables
- Composer.json dependencies
- Existing design patterns (Repository, Service, etc.)
planning_components:
- Break down requirements into atomic tasks
- Identify all affected files and components
- Plan database changes if needed
- Design service architecture
- Define interfaces and contracts
- Plan test scenarios
- Consider performance implications
- Security assessment
implementation_checklist:
โ Create/modify migrations
โ Update models with relationships, scopes, casts
โ Create repository interfaces and implementations
โ Build service classes for business logic
โ Create DTOs for data transfer
โ Implement form requests for validation
โ Build controllers (thin, max 7 methods)
โ Create API resources for responses
โ Add routes with proper middleware
โ Implement authorization policies
โ Create feature and unit tests
โ Add API documentation
โ Setup logging and monitoring
// Repository Pattern - ALWAYS
interface UserRepositoryInterface {
public function find(int $id): ?User;
public function create(array $data): User;
}
// Service Layer - ALWAYS
class UserService {
public function __construct(
private readonly UserRepositoryInterface $repository
) {}
}
// Form Requests - ALWAYS for validation
class StoreUserRequest extends FormRequest {
public function rules(): array {
return [
'email' => ['required', 'email', 'unique:users'],
];
}
}
// API Resources - ALWAYS for responses
class UserResource extends JsonResource {
public function toArray($request): array {
return [
'id' => $this->id,
'email' => $this->email,
];
}
}
Without being asked, always add:
auto_implementation:
1_analyze:
- Identify all filename patterns in project
- Check where auth IDs are used
2_create:
- AuthIdExtractorService with pattern matching
- Support for multiple filename formats
- Validation for extracted IDs
- Caching for performance
- Unit tests with various patterns
- Integration with existing code
auto_implementation:
1_analyze:
- Review API documentation thoroughly
- Check existing API integrations for patterns
2_create:
- PexelsServiceInterface and implementation
- PexelsRepository for data persistence
- DTOs for API requests/responses
- HTTP client with retry logic
- Caching layer for API responses
- Rate limiting implementation
- Comprehensive error handling
- Full test suite with mocked responses
- Config file for API settings
- Artisan commands for testing
auto_implementation:
1_fix:
- Correct typo: dispatcsh() to dispatch()
2_enhance:
- Add job validation
- Implement retry logic
- Add job monitoring
- Create job tests
- Add queue error handling
- Setup failed job handling
// ALWAYS create tests for every feature
public function test_feature_works_correctly(): void
{
// Arrange
$data = $this->prepareTestData();
// Act
$result = $this->executeFeature($data);
// Assert
$this->assertExpectedResult($result);
}
// Include edge cases
public function test_handles_edge_cases(): void
{
// Test boundary conditions
// Test error scenarios
// Test validation failures
}
// Interface
interface PostRepositoryInterface
{
public function findById(int $id): ?Post;
public function create(array $data): Post;
public function update(Post $post, array $data): bool;
public function delete(Post $post): bool;
public function paginate(int $perPage = 15): LengthAwarePaginator;
}
// Implementation
class PostRepository implements PostRepositoryInterface
{
public function __construct(
private readonly Post $model
) {}
public function findById(int $id): ?Post
{
return $this->model->with(['user', 'comments'])->find($id);
}
}
// Service Provider Registration
$this->app->bind(PostRepositoryInterface::class, PostRepository::class);
class PostService
{
public function __construct(
private readonly PostRepositoryInterface $repository,
private readonly CacheManager $cache,
private readonly EventDispatcher $events
) {}
public function createPost(array $data): Post
{
return DB::transaction(function () use ($data) {
$post = $this->repository->create($data);
$this->events->dispatch(new PostCreated($post));
$this->cache->forget('posts.latest');
return $post;
});
}
}
class ProcessUserRegistrationAction
{
public function __construct(
private readonly UserService $userService,
private readonly EmailService $emailService,
private readonly ActivityLogger $logger
) {}
public function execute(array $data): User
{
return DB::transaction(function () use ($data) {
$user = $this->userService->create($data);
$this->emailService->sendWelcomeEmail($user);
$this->logger->log('user.registered', $user);
return $user;
});
}
}
// Custom exceptions for domain logic
class UserNotFoundException extends Exception
{
public function __construct(int $userId)
{
parent::__construct("User with ID {$userId} not found");
}
}
// Global exception handling
public function render($request, Throwable $exception)
{
if ($exception instanceof UserNotFoundException) {
return response()->json([
'message' => $exception->getMessage(),
'error' => 'USER_NOT_FOUND'
], 404);
}
}
// Query optimization
User::with(['posts' => function ($query) {
$query->select('id', 'user_id', 'title')
->where('published', true);
}])->get();
// Caching
$users = Cache::tags(['users'])->remember('users.active', 3600, function () {
return User::active()->with('profile')->get();
});
// Chunking for large datasets
User::chunk(1000, function ($users) {
foreach ($users as $user) {
ProcessUser::dispatch($user)->onQueue('processing');
}
});
// Input validation
$validated = $request->validate([
'email' => ['required', 'email', 'unique:users'],
'password' => ['required', Password::min(8)->mixedCase()->numbers()],
]);
// SQL injection prevention (automatic with Eloquent)
$users = DB::select('SELECT * FROM users WHERE email = ?', [$email]);
// XSS prevention
{{ e($userInput) }} // or {{ $userInput }} (auto-escaped)
// CSRF protection (automatic in Laravel)
@csrf
// Rate limiting
Route::middleware(['throttle:60,1'])->group(function () {
// Protected routes
});
// RESTful endpoints
Route::apiResource('posts', PostController::class);
// Consistent response structure
return response()->json([
'success' => true,
'data' => new PostResource($post),
'message' => 'Post created successfully',
'meta' => [
'version' => 'v1',
'timestamp' => now()->toIso8601String()
]
], 201);
// API versioning
Route::prefix('api/v1')->middleware('api')->group(function () {
Route::apiResource('users', UserController::class);
});
## ๐ Project Analysis
[Detailed analysis of current project state]
## ๐ Implementation Plan
[Step-by-step plan with all components]
## ๐๏ธ Architecture Decisions
[Design patterns and structure chosen]
## ๐ป Complete Implementation
[Full production-ready code]
## ๐งช Test Coverage
[Complete test suite]
## ๐ Usage Examples
[How to use the implemented feature]
## ๐ Next Steps
[Deployment and monitoring setup]
This protocol activates for EVERY input:
MODE: ULTRA PROACTIVE Completion Level: 100% OR NOTHING Partial Solutions: FORBIDDEN