laraavel chat instruction file

This commit is contained in:
2025-12-03 16:42:53 +05:30
commit d212343354
3 changed files with 423 additions and 0 deletions

View File

@@ -0,0 +1,162 @@
# Copilot Configuration for Laravel AI Guidelines
This file is intended to be used with GitHub Copilot or any AI code assistant.
It enforces the rules defined in **ai-guidelines.md** and ensures consistent,
optimized, secure, and validated Laravel 12.x code generation.
## 📌 Configuration Instructions
Place this file in one of the following locations:
```
/.copilot/config.json
```
or
```
/.github/copilot-instructions.md
```
---
# ✅ Copilot Instructions (Auto-Formatting, Auto-Validation, Optimized Laravel 12.x Code)
Copilot MUST follow these rules for all Laravel code:
---
## 1⃣ General Laravel Code Rules
- Always write **clean, readable, maintainable** Laravel code.
- Follow **Laravel 12.x documentation**: https://laravel.com/docs/12.x/releases
- Use PSR-12 formatting.
- Follow naming conventions:
- Classes → PascalCase
- Methods/variables → camelCase
- Database → snake_case
- Functions must be short and meaningful.
- Avoid unnecessary complexity.
---
## 2⃣ Controllers (Thin Controllers Only)
- Must always use **try/catch**.
- Must always use **FormRequest validation**, never inline validation.
- Must return **standardized JSON responses** using ApiResponseTrait.
- Must use correct HTTP status codes:
- 200 OK
- 201 Created
- 400 Bad Request
- 401 Unauthorized
- 404 Not Found
- 422 Validation Error
- 500 Server Error
- No DB logic allowed inside controllers.
---
## 3⃣ Services (Business Logic)
- All core logic must be placed here.
- Must always use try/catch and log exceptions.
- Must use optimized Eloquent:
- select()
- when()
- with()
- paginate()
- Use DB::transaction for multi-step operations.
- Never return JSON (controller handles responses).
---
## 4⃣ Models
- Use $fillable or $guarded.
- Use casts for JSON, arrays, and booleans.
- Use relationships and scopes.
- No business logic inside models.
---
## 5⃣ Validation (Strict)
- Must always use FormRequest.
- All input must be validated.
- Never trust raw request data.
---
## 6⃣ API Response Standardization
Use ApiResponseTrait:
```
success(data, message, status)
error(message, status)
```
- Every success/error response must use these wrappers.
---
## 7⃣ Jobs / Queues
- All heavy tasks must be queued using Jobs.
- Jobs must use try/catch and log errors.
- Never handle heavy tasks inside controller/service.
---
## 8⃣ Performance Rules
- Never return entire tables → must use pagination.
- Avoid N+1 → always use eager loading.
- Use select() to reduce data load.
- Use indexes in migrations.
- Optimize filters using when().
- Use caching for repeated queries.
---
## 9⃣ Security Rules
- Hash passwords, never store plain text.
- Validate all inputs.
- Sanitize user data.
- Prevent SQL/XSS injection.
- Do not expose stack traces in responses.
---
## 🔟 Forbidden
Copilot must NOT:
- Use Repository Pattern.
- Use SOLID over-engineered architecture.
- Write raw SQL inside controllers.
- Put business logic inside controllers.
- Write nested DB queries inside loops.
- Generate large unpaginated queries.
- Return raw models in API.
---
# 🎯 Final Result
Copilot will now automatically generate:
- Clean Laravel 12.x code
- Always validated
- Always optimized
- Always readable
- Always secure
- Always using try/catch
- Always using proper HTTP codes
- Always using Laravel best practices
---
**End of Copilot Configuration**

View File

@@ -0,0 +1,234 @@
# Laravel Coding Standards for Copilot (With Examples)
## Version 1.0
This document defines the official Laravel coding standards enforced by Copilot for writing clean, secure, readable, and optimized code.
---
# 1. General Coding Rules
- Follow PSR-12 formatting.
- Use camelCase for variables & methods.
- Use PascalCase for classes.
- Use snake_case for database columns and tables.
- Limit functions to a clear, single responsibility.
### Example
```php
class UserProfileService
{
public function getFullName(User $user): string
{
return "{$user->first_name} {$user->last_name}";
}
}
```
---
# 2. Controller Standards
- Must remain thin.
- Use FormRequest for validation.
- Wrap logic in try/catch.
- Return standardized JSON responses.
- Use correct HTTP status codes.
### Example
```php
class UserController extends Controller
{
use ApiResponseTrait;
public function update(UpdateUserRequest $request, User $user)
{
try {
$updated = $this->service->updateProfile($user, $request->validated());
return $this->success($updated, 'Profile updated', 200);
} catch (\Throwable $e) {
Log::error('Update failed: '.$e->getMessage());
return $this->error('Unable to update profile', 500);
}
}
}
```
---
# 3. FormRequest Validation
- All inputs must be validated.
- No inline validator inside controllers.
### Example
```php
class UpdateUserRequest extends FormRequest
{
public function rules(): array
{
return [
'first_name' => 'required|string|max:150',
'last_name' => 'required|string|max:150',
'phone' => 'nullable|digits_between:10,12'
];
}
}
```
---
# 4. Service Layer Standards
- Wrap heavy logic in try/catch.
- Log exceptions.
- Use DB transactions for multi-step operations.
- Use optimized Eloquent queries.
### Example
```php
class UserProfileService
{
public function updateProfile(User $user, array $data)
{
try {
return DB::transaction(function () use ($user, $data) {
$user->update($data);
return $user->fresh();
});
} catch (\Throwable $e) {
Log::error('Service error: '.$e->getMessage());
throw $e;
}
}
}
```
---
# 5. Models
- Use fillable/guarded.
- Use casts.
- Use accessors/mutators where needed.
- Use query scopes.
### Example
```php
class User extends Model
{
protected $fillable = ['first_name','last_name','email','phone'];
protected $casts = [
'is_active' => 'boolean',
'email_verified_at' => 'datetime'
];
public function scopeActive($query)
{
return $query->where('is_active', true);
}
}
```
---
# 6. API Response Formatting
Use a shared trait.
### Example
```php
trait ApiResponseTrait
{
protected function success($data = null, $message = 'Success', $code = 200)
{
return response()->json([
'status' => true,
'message' => $message,
'data' => $data
], $code);
}
protected function error($message = 'Error', $code = 500)
{
return response()->json([
'status' => false,
'message' => $message
], $code);
}
}
```
---
# 7. Jobs & Queue Standards
- Heavy tasks must be queued.
- Wrap in try/catch.
### Example
```php
class SendReportJob implements ShouldQueue
{
public function handle()
{
try {
// generate report
} catch (\Throwable $e) {
Log::error('Report job failed: ' . $e->getMessage());
}
}
}
```
---
# 8. Linting (Pint)
### Install
```
composer require laravel/pint --dev
```
### Run
```
./vendor/bin/pint
```
---
# 9. Static Analysis (PHPStan)
### Install
```
composer require --dev phpstan/phpstan
```
### Run
```
vendor/bin/phpstan analyse
```
---
# 10. OpenTelemetry (Monitoring & Logs)
### Install
```
composer require open-telemetry/opentelemetry-laravel
```
### Publish
```
php artisan vendor:publish --provider="OpenTelemetry\Laravel\ServiceProvider"
```
### Enable auto-instrumentation
```
php artisan otel:install
```
---
# Final Notes
This standard ensures Copilot always writes clean, secure, maintainable, and production-ready Laravel code.

View File

@@ -0,0 +1,27 @@
# Prompt / Command Storage for Assistant
- Created: 2025-11-28
- Location: `.github/instructions/promptcommand.instructions.md`
- Purpose: Store each user prompt/command so the assistant can reference and follow them on further actions.
---
## Entry 1 (User Prompt)
Timestamp: 2025-11-28
User request:
"what ever i am giving prompt here and command store in separate promptcommand.instructions.md file in .github/instructions from there you can follow wait for my next instruction (See <attachments> above for file contents. You may not need to search or read the file again.)"
Assistant handling rules for this file:
- Do not modify or remove entries in this file without explicit permission from the user.
- For each future prompt or command the user provides in this chat, append a new numbered entry here with timestamp and the raw text.
- Before executing any action based on entries in this file, the assistant will confirm with the user unless the user explicitly instructs otherwise.
- This file is authoritative for prompt/command history used by the assistant; the assistant will read from it when the user asks it to follow stored commands.
---
## Status
- Assistant will now wait for the user's next instruction.