|
| 1 | +# Programming Rules & Guidelines |
| 2 | + |
| 3 | +**Aider, read and internalize these rules. You MUST adhere to them strictly.** |
| 4 | + |
| 5 | +## General Directives |
| 6 | + |
| 7 | +1. **Surgical Precision:** Make only the exact changes explicitly requested. Do not add, remove, or modify any code that |
| 8 | + is not directly pertinent to the current task. |
| 9 | +2. **No Extraneous Changes:** Do not auto-format, re-indent, reorder, or refactor code unless specifically instructed. |
| 10 | + Preserve the existing code style, formatting, and structure. |
| 11 | +3. **No Unsolicited Refactoring:** Do not introduce new classes, methods, or architectural patterns unless explicitly |
| 12 | + outlined in the task. If a suggestion for refactoring is implicit, ask for explicit approval first. |
| 13 | +4. **Prioritize Clarity over Brevity:** Code must be clear, readable, and maintainable. Do not optimize for line count |
| 14 | + at the expense of understanding. |
| 15 | + |
| 16 | +## Filament v4 Specific Directives (CRITICAL) |
| 17 | + |
| 18 | +1. **Exact Method Signatures:** When modifying or implementing Filament resource methods (`form()`, `table()`, |
| 19 | + `getColumns()`, `getActions()`, `getPages()`, `getHeaderActions()`, etc.), you **MUST** preserve their exact Filament |
| 20 | + v4 method signatures, including type hints and return types (e.g., `public static function form(Form $form): Form`, |
| 21 | + `public static function table(Table $table): Table`, `public static function makeHeaderActions(Page $page): array`). |
| 22 | +2. **Filament `Action` Syntax:** Use the correct Filament v4 `Action` syntax (`Action::make(...)`) with its fluent |
| 23 | + methods (`->label()`, `->icon()`, `->action()`, `->modal()`, `->requiresConfirmation()`, and dynamic properties using |
| 24 | + `fn (Model $record): type => ...`). |
| 25 | +3. **Resource `getPages()`:** When modifying `getPages()`, ensure it only lists the specified page routes. **Do NOT** |
| 26 | + automatically add `Create` or `Edit` pages unless explicitly instructed for that specific resource. |
| 27 | +4. **No Raw `created_at` or `updated_at` in Tables/Infolists:** Avoid directly displaying |
| 28 | + `TextColumn::make('created_at')` or `TextEntry::make('created_at')`. Use dedicated timestamp columns or accessors if |
| 29 | + temporal data is needed. |
| 30 | + |
| 31 | +## Database & Model Strictness |
| 32 | + |
| 33 | +1. **No `timestamps()` or `softDeletes()` in Migrations (Unless Specified):** Unless explicitly told otherwise for a |
| 34 | + specific table, new migrations and modifications to existing migrations **MUST NOT** include `->timestamps()` or |
| 35 | + `->softDeletes()`. |
| 36 | +2. **No `$fillable` Array in Models:** Models **MUST NOT** use the `$fillable` property. Rely on specific factory |
| 37 | + methods, service methods, or guarded properties if absolutely necessary. |
| 38 | +3. **No `timestamps` or `softDeletes` Properties/Traits in Models:** Unless explicitly told otherwise for a specific |
| 39 | + model, models **MUST NOT** use the `$timestamps = false;` property or the `SoftDeletes` trait. |
| 40 | +4. **Type Hinting & Casts:** Use native PHP type hints for properties and method arguments/return types. Utilize |
| 41 | + `$casts` for Enum fields and JSON columns. |
| 42 | + |
| 43 | +## SOLID Principles & Dynamic Programming |
| 44 | + |
| 45 | +1. **Single Responsibility Principle (SRP):** Each class and method should have only one reason to change. Break down |
| 46 | + complex logic into smaller, focused units. |
| 47 | +2. **Open/Closed Principle (OCP):** Software entities should be open for extension, but closed for modification. Favor |
| 48 | + composition and interfaces over inheritance where appropriate. |
| 49 | +3. **Liskov Substitution Principle (LSP):** Objects in a program should be replaceable with instances of their subtypes |
| 50 | + without altering the correctness of that program. Ensure proper use of polymorphism. |
| 51 | +4. **Interface Segregation Principle (ISP):** Clients should not be forced to depend on interfaces they do not use. |
| 52 | + Create small, role-specific interfaces. |
| 53 | +5. **Dependency Inversion Principle (DIP):** |
| 54 | + * Use interfaces where appropriate to define contracts for services and clients. |
| 55 | +6. **Dynamic & Flexible Code:** |
| 56 | + * **Enums for Fixed Options:** Use PHP Enums for fixed sets of options (e.g., `TranscriptStatus`, `AIProvider`). |
| 57 | + * **Factories for Implementations:** Use factory classes/methods to retrieve specific implementations of |
| 58 | + interfaces (e.g., `AIClientFactory`). |
| 59 | + |
| 60 | +## API Clients |
| 61 | + |
| 62 | +1. **All API Calls Through Clients:** Any interaction with external APIs (e.g., OpenAI, AWS, Salesforce) **MUST** go |
| 63 | + through a dedicated API client class (e.g., `OpenAIApiClient`, `AwsS3Client`, `SalesforceTaskApiClient`). These |
| 64 | + clients should wrap the HTTP calls and handle API-specific details. |
| 65 | + |
| 66 | +## Testing |
| 67 | + |
| 68 | +1. **Test Coverage:** For any new feature or significant refactoring, consider how unit and integration tests would be |
| 69 | + written. The design should facilitate easy testing through proper dependency injection. |
| 70 | + |
| 71 | +## Error Handling & Resilience |
| 72 | + |
| 73 | +1. **Explicit Error Handling:** Implement robust `try-catch` blocks for external API calls and critical operations. Log |
| 74 | + errors clearly. |
| 75 | +2. **Asynchronous Operations for External Systems:** For operations involving external APIs (especially write operations |
| 76 | + like Salesforce sync), favor asynchronous processing via jobs to prevent UI blocking and allow for retries. |
| 77 | + |
| 78 | +## Configuration |
| 79 | + |
| 80 | +1. **Use Configuration Files/Environment Variables:** All API keys, endpoint URLs, and changeable settings must be |
| 81 | + defined in `.env` and accessed via `config()` helpers, not hardcoded. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Api client -Specific Rules |
| 86 | + |
| 87 | +1. DTOs **must NOT have constructors** — all population happens in Transformers. |
| 88 | +2. Transformers use `toDto()` and `toSpotify()`. |
| 89 | +3. All mass data Clients use: |
| 90 | + |
| 91 | +```php |
| 92 | +public function getMassData(): Collection; |
| 93 | +public function saveMassData(object $dto): mixed; |
0 commit comments