# 🛡️ Strict Project Development Rules

These rules are mandatory and must be strictly followed throughout the entire development lifecycle of this project.

---

## 1. Database & Migration Safety
* **No Direct `migrate:fresh`:** Never execute `php artisan migrate:fresh`, `migrate:reset`, or `migrate:rollback` directly. Destructive database actions require prior verification and explicit developer consent.
* **No Direct Migration Execution:** Do not run database migrations directly on the database without prior schema inspection, review, and verification of the migration files.

---

## 2. Mandatory UUID Primary Key Standard
* **UUID as Primary Key:** Do not use auto-incrementing integer IDs (`$table->id()`) on entity tables. Every table must use UUID as its primary key:
  * In Migration: `$table->uuid('id')->primary();`
  * In Eloquent Model: `use Illuminate\Database\Eloquent\Concerns\HasUuids;` and `use HasUuids;` trait.
  * In Foreign Key References: Use `$table->foreignUuid('entity_id')` or `$table->uuid('entity_id')`.
  * In Polymorphic Relations: Use `$table->uuidMorphs(...)` / `$table->nullableUuidMorphs(...)` instead of standard `morphs()`.

---

## 3. Mandatory Multi-Tenant `team_id` Standard
* **Mandatory Team Scoping:** Whenever creating tables for application data (e.g. `users`, `settings`, `posts`, `categories`, `products`), always add a `team_id` column:
  * In Migration: `$table->uuid('team_id')->nullable()->index();`
  * In Eloquent Model: Add `team_id` to `$fillable` and cast as string.
  * It must be `nullable()` to ensure single-tenant applications remain fully functional, while enabling seamless multi-tenant / team-scoped access control whenever needed.

---

## 4. Mandatory Soft Deletes Standard
* **Mandatory Soft Deletes on Tables:** Every primary entity/data table must mandatorily implement soft deletes:
  * In Migration: `$table->softDeletes();`
  * In Eloquent Model: `use Illuminate\Database\Eloquent\SoftDeletes;` and `use SoftDeletes;` trait.
* **Strict Exceptions:** Only omit soft deletes on intermediate pivot tables, transient cache/session tables, or activity log tables where soft deleting is completely unnecessary. Always recommend and obtain confirmation before omitting soft delete on any table.

---

## 5. High-Performance Database Indexing & Search Standard
* **Mandatory Indexing on Search & Filter Columns:** Every column used for searching (e.g. `name`, `phone`, `code`, `title`) or filtering (e.g. `status`, `type`, foreign keys) must be indexed in migration files (`->index()`).
* **Compound Indexing for Common Queries:** Where multiple columns are queried together (e.g. `team_id` + `status`), create composite indexes: `$table->index(['team_id', 'status']);`.
* **Standard Searchable Trait:** All searchable Eloquent models must use `App\Traits\Searchable` and declare `protected array $searchable = [...]` so that Livewire components can query data with `$model::search($query)->paginate()`.

---

## 6. Form Inputs Standard (WireUI Required)
* **Always Use WireUI for Forms:** For all forms across Admin, Frontend, and Auth layouts, always utilize WireUI components.
  * Inputs: `<x-input />`
  * Passwords: `<x-password />`
  * Textareas: `<x-textarea />`
  * Checkboxes: `<x-checkbox />`
  * Toggles: `<x-toggle />`
  * Date/Time: `<x-datetime-picker />`
* Raw HTML inputs (`<input>`, `<textarea>`) are strictly prohibited in forms.

---

## 7. Select Dropdowns Standard (WireUI Async Required)
* **Always Use WireUI Select:** All dropdowns must use WireUI's `<x-select>` component.
* **Async URL for Searchable Options:** Select components must be configured using `async-data` (endpoint URL) to ensure searchability, high performance, and seamless handling of large datasets.
  ```html
  <x-select
      label="Select User"
      placeholder="Search and select a user"
      wire:model="user_id"
      :async-data="route('api.users.search')"
      option-label="name"
      option-value="id"
  />
  ```

---

## 8. Language & Localization Enforcement
* **English Only in Codebase:** All source code, PHP classes, Livewire components, Blade templates, UI text, labels, validation messages, comments, commit messages, and documentation files must be strictly written in **English**.
* **Gujarati Usage Restriction:** Gujarati language is strictly restricted to chat discussions and user explanations. No Gujarati text or transliteration is allowed within project files or code.

---

## 9. Centralized Theme Colors (No Hardcoded Colors)
* **Strict Prohibition of Hardcoded Colors:** Never use arbitrary hardcoded hex codes (e.g. `bg-[#D41B2D]`, `text-[#123456]`) or inline styles (`style="color: ..."`) in Blade templates, Livewire components, or CSS files.
* **Always Use Semantic Theme Tokens:**
  * For Tailwind: Use `bg-primary`, `text-primary`, `border-primary`, `bg-primary-600`, `text-primary-700`, etc.
  * For DaisyUI: Use `d-btn-primary`, `d-badge-primary`, `bg-base-100`, `text-base-content`, etc.
  * For WireUI: Use built-in color props (e.g., `<x-button primary />`, `<x-badge primary />`).
* **Brand Primary Color:** The brand primary color (`#D41B2D` - BU Crimson Red) is configured centrally in `tailwind.config.js` and propagated automatically across Tailwind, WireUI, and DaisyUI themes.

---

## 10. Architectural Consistency
* **Theme Styling:** Use DaisyUI prefixed utility classes (`d-card`, `d-badge`, `d-drawer`, etc.) alongside WireUI without style conflicts.
* **Reusability:** Ensure every module, trait, and component is modular, decoupled, and reusable for future projects.

---

## 11. Multi-Tier Routing Architecture Standard
* **Frontend Web Routes (`routes/web.php`):**
  * Strictly dedicated to frontend, public-facing pages (e.g., landing page, public blog/services, user portal).
  * No admin dashboard or backend management routes should ever be placed in `web.php`.
* **Admin / Backend Routes (`routes/admin.php`):**
  * All administration, staff management, dashboard, and backend CRUD routes must reside in `routes/admin.php`.
  * **Mandatory URL Prefix:** Every admin route must automatically have the `/admin` URL prefix (e.g., `/admin/dashboard`, `/admin/users`, `/admin/settings`).
  * **Mandatory Route Name Prefix:** All admin routes must be prefixed with `admin.` (e.g., `admin.dashboard`, `admin.users.index`).
  * **Middleware Group:** Defaulted to `['web', 'auth']` in `RouteServiceProvider`, with role/permission middleware added as needed.
* **WireUI Async Select Endpoints (`routes/api.php`):**
  * Whenever a WireUI select dropdown (`<x-select>`) utilizes `:async-data` for asynchronous search and loading, the corresponding lookup endpoint route MUST be registered in `routes/api.php`.
  * **Route Naming Convention:** Namespaced with `api.` prefix (e.g., `api.users.search`, `api.roles.search`, `api.permissions.search`).
  * **URL Prefix:** Automatically prefixed with `/api` (e.g., `/api/users/search`).

