# Story 0.2: Rename Folders to Declarations in Backend

Status: done

<!-- Note: Validation is optional. Run validate-create-story for quality check before dev-story. -->

## Story

As a developer,
I want all backend PHP code to use "Declaration" terminology instead of "Folder",
so that the codebase is consistent with the database and professional domain language.

## Acceptance Criteria

1. **Given** the database migration from Story 0.1 has been applied, **When** the backend rename is complete, **Then** the `Folder` model is renamed to `Declaration` with updated table name, relationships, and fillable attributes
2. **And** the `FolderInvitation` model is renamed to `DeclarationInvitation` with updated table, fillable (`declaration_id`), and relationships
3. **And** `FolderController` is renamed to `DeclarationController` with updated route model binding
4. **And** `FolderMediaController` is renamed to `DeclarationMediaController`
5. **And** `FolderMessageController` is renamed to `DeclarationMessageController`
6. **And** `FolderMentionController` is renamed to `DeclarationMentionController`
7. **And** all Form Request classes (`StoreFolderRequest`, `UpdateFolderRequest`, `StoreFolderMessageRequest`, `StoreFolderMentionRequest`) are renamed with "Declaration" prefix
8. **And** all Enums (`FolderStatus`, `FolderType`, `FolderPriority`) are renamed to `DeclarationStatus`, `DeclarationType`, `DeclarationPriority`
9. **And** all Mail classes (`FolderConfirmationMail`, `FolderFileRequestMail`, `FolderInviteMail`, `FolderSituationMail`, `FolderTextMessageMail`) are renamed with "Declaration" prefix
10. **And** the `FolderMentionNotification` is renamed to `DeclarationMentionNotification`
11. **And** the `ValidateFolderInvitation` middleware is renamed to `ValidateClientPortalToken`
12. **And** all routes in `web.php` are updated from "folders" to "declarations" and the middleware alias is updated
13. **And** `bootstrap/app.php` middleware alias is updated from `folder.invitation` to `client-portal`
14. **And** `FolderFactory` is renamed to `DeclarationFactory`
15. **And** all related models (`Client`, `Workspace`, `Message`) have their relationships and references updated
16. **And** all controllers referencing Folder (`DashboardController`, `ClientController`, `WorkspaceController`, client portal controllers) are updated
17. **And** all Blade email templates in `resources/views/emails/folder-*.blade.php` are renamed to `declaration-*`
18. **And** Spatie polymorphic columns (`media.model_type`, `activity_log.subject_type`) storing `App\Models\Folder` are updated to `App\Models\Declaration` via a data migration
19. **And** the `DatabaseSeeder` is updated to use Declaration terminology
20. **And** all existing feature tests are updated and passing

## Tasks / Subtasks

- [x] Task 1: Rename Enums (AC: #8)
  - [x] 1.1: Rename `app/Enums/FolderType.php` → `app/Enums/DeclarationType.php` (update class name)
  - [x] 1.2: Rename `app/Enums/FolderStatus.php` → `app/Enums/DeclarationStatus.php` (update class name)
  - [x] 1.3: Rename `app/Enums/FolderPriority.php` → `app/Enums/DeclarationPriority.php` (update class name)
- [x] Task 2: Rename Models (AC: #1, #2)
  - [x] 2.1: Rename `app/Models/Folder.php` → `app/Models/Declaration.php` — update class name, add explicit `protected $table = 'declarations'`, rename `invitations()` relationship to return `DeclarationInvitation`, update all internal references
  - [x] 2.2: Rename `app/Models/FolderInvitation.php` → `app/Models/DeclarationInvitation.php` — update class name, add explicit `protected $table = 'declaration_invitations'`, rename `$fillable` from `folder_id` to `declaration_id`, rename `folder()` → `declaration()` relationship, update BelongsTo type to `Declaration`
- [x] Task 3: Update Related Models (AC: #15)
  - [x] 3.1: `app/Models/Client.php` — rename `folders()` → `declarations()`, update return type from `Folder` to `Declaration`, update import
  - [x] 3.2: `app/Models/Workspace.php` — rename `folders()` → `declarations()`, update return type from `Folder` to `Declaration`, update import
  - [x] 3.3: `app/Models/Message.php` — update `$fillable` from `folder_id` to `declaration_id`, rename `folder()` → `declaration()` relationship, update import
- [x] Task 4: Rename Form Requests (AC: #7)
  - [x] 4.1: Rename `StoreFolderRequest.php` → `StoreDeclarationRequest.php` — update class name, update enum imports
  - [x] 4.2: Rename `UpdateFolderRequest.php` → `UpdateDeclarationRequest.php` — update class name, update enum imports
  - [x] 4.3: Rename `StoreFolderMessageRequest.php` → `StoreDeclarationMessageRequest.php` — update class name
  - [x] 4.4: Rename `StoreFolderMentionRequest.php` → `StoreDeclarationMentionRequest.php` — update class name
- [x] Task 5: Rename Controllers (AC: #3, #4, #5, #6, #16)
  - [x] 5.1: Rename `FolderController.php` → `DeclarationController.php` — update class name, all model/enum/request imports, method references (`$folder` → `$declaration`, `authorizeFolder()` → `authorizeDeclaration()`, `folderTypeLabels()` → `declarationTypeLabels()`, etc.)
  - [x] 5.2: Rename `FolderMediaController.php` → `DeclarationMediaController.php` — update class name, `Folder::class` → `Declaration::class` in polymorphic query (line 65), all variable names
  - [x] 5.3: Rename `FolderMessageController.php` → `DeclarationMessageController.php` — update class name, all model/enum/mail imports, variable names, method names
  - [x] 5.4: Rename `FolderMentionController.php` → `DeclarationMentionController.php` — update class name, imports, variable names
  - [x] 5.5: Update `DashboardController.php` — update imports from `Folder`/`FolderStatus` to `Declaration`/`DeclarationStatus`, update all variable names and relationship calls
  - [x] 5.6: Update `ClientController.php` — update imports and relationship calls (`folders` → `declarations`)
  - [x] 5.7: Update `WorkspaceController.php` — update imports from `Folder`/`FolderStatus` to `Declaration`/`DeclarationStatus`, relationship calls
  - [x] 5.8: Update `Client/UploadController.php` — update `FolderStatus` → `DeclarationStatus` import, `$folder` → `$declaration` variables, `folder_invitation` request attribute access
  - [x] 5.9: Update `Client/ConfirmController.php` — same as 5.8
  - [x] 5.10: Update `Client/RefuseController.php` — update `$folder` → `$declaration` variables, request attribute access
- [x] Task 6: Rename Mail Classes (AC: #9)
  - [x] 6.1: Rename `FolderInviteMail.php` → `DeclarationInviteMail.php` — update class name, constructor param types, view reference
  - [x] 6.2: Rename `FolderConfirmationMail.php` → `DeclarationConfirmationMail.php`
  - [x] 6.3: Rename `FolderFileRequestMail.php` → `DeclarationFileRequestMail.php`
  - [x] 6.4: Rename `FolderSituationMail.php` → `DeclarationSituationMail.php`
  - [x] 6.5: Rename `FolderTextMessageMail.php` → `DeclarationTextMessageMail.php` — also update markdown view reference from `emails.folder-text-message` to `emails.declaration-text-message`
- [x] Task 7: Rename Blade Email Templates (AC: #17)
  - [x] 7.1: Rename `resources/views/emails/folder-invite.blade.php` → `declaration-invite.blade.php`
  - [x] 7.2: Rename `resources/views/emails/folder-confirmation.blade.php` → `declaration-confirmation.blade.php`
  - [x] 7.3: Rename `resources/views/emails/folder-file-request.blade.php` → `declaration-file-request.blade.php`
  - [x] 7.4: Rename `resources/views/emails/folder-situation.blade.php` → `declaration-situation.blade.php`
  - [x] 7.5: Rename `resources/views/emails/folder-text-message.blade.php` → `declaration-text-message.blade.php`
  - [x] 7.6: Rename `resources/views/emails/folder-mention.blade.php` → `declaration-mention.blade.php`
  - [x] 7.7: Update internal content of all templates — replace `$folder` variable references with `$declaration`
- [x] Task 8: Rename Notification (AC: #10)
  - [x] 8.1: Rename `FolderMentionNotification.php` → `DeclarationMentionNotification.php` — update class name, constructor param type, `folder_id`/`folder_title` keys → `declaration_id`/`declaration_title`, route from `folders.show` → `declarations.show`
- [x] Task 9: Rename Middleware and Update Bootstrap (AC: #11, #13)
  - [x] 9.1: Rename `ValidateFolderInvitation.php` → `ValidateClientPortalToken.php` — update class name, `FolderInvitation` → `DeclarationInvitation` import, `folder_invitation` request attribute → `declaration_invitation`
  - [x] 9.2: Update `bootstrap/app.php` — change alias from `'folder.invitation' => ValidateFolderInvitation::class` to `'client-portal' => ValidateClientPortalToken::class`
- [x] Task 10: Update Routes (AC: #12)
  - [x] 10.1: Update `routes/web.php` — rename resource from `'folders'` to `'declarations'`, update controller references, update nested route prefixes, update middleware reference from `folder.invitation` to `client-portal`
- [x] Task 11: Rename Factory and Update Seeder (AC: #14, #19)
  - [x] 11.1: Rename `database/factories/FolderFactory.php` → `DeclarationFactory.php` — update class name, docblock, enum imports
  - [x] 11.2: Update `database/seeders/DatabaseSeeder.php` — update imports, `Folder::create()` → `Declaration::create()`, variable names, comments
- [x] Task 12: Create Polymorphic Data Migration (AC: #18)
  - [x] 12.1: Create migration `2026_03_11_000002_update_polymorphic_folder_to_declaration.php`
  - [x] 12.2: In `up()` — `DB::table('media')->where('model_type', 'App\\Models\\Folder')->update(['model_type' => 'App\\Models\\Declaration'])`
  - [x] 12.3: In `up()` — `DB::table('activity_log')->where('subject_type', 'App\\Models\\Folder')->update(['subject_type' => 'App\\Models\\Declaration'])`
  - [x] 12.4: In `down()` — reverse both updates
  - [x] 12.5: Verified `activity_log.causer_type` — Spatie defaults to authenticated User as causer, no custom `causedBy()` calls exist, so `causer_type` only contains `App\Models\User`. No migration needed.
- [x] Task 13: Update and Verify Tests (AC: #20)
  - [x] 13.1: Rename `tests/Feature/Folder/` directory → `tests/Feature/Declaration/`
  - [x] 13.2: Update `tests/Feature/Declaration/FolderTypeTest.php` → `DeclarationTypeTest.php` — update all model/enum/route references
  - [x] 13.3: Update `tests/Feature/Declaration/MediaDownloadTest.php` — update model/route references
  - [x] 13.4: Update `tests/Feature/Notification/FolderMentionTest.php` → `DeclarationMentionTest.php` — update all references
  - [x] 13.5: Update `tests/Feature/Notification/NotificationControllerTest.php` — update any folder references
  - [x] 13.6: Run `composer test` to verify all tests pass
- [x] Task 14: Final Verification (AC: all)
  - [x] 14.1: Run `grep -r "Folder" app/ database/ routes/ tests/ resources/views/emails/ --include="*.php" --include="*.blade.php"` — confirm zero "Folder" references remain (except in migration file names which are historical)
  - [x] 14.2: Run `php artisan route:list` to verify all routes are registered correctly
  - [x] 14.3: Run `composer test` — all tests pass

## Dev Notes

### Critical Architecture Constraints

- **Database engine:** MySQL 8.4 (production) / SQLite for local dev — Story 0.1 already renamed tables
- **Multi-tenant:** All models are workspace-scoped via `workspace_id` column
- **Spatie media_library:** `media.model_type` stores FQCN `App\Models\Folder` — MUST be updated via data migration (Task 12) to `App\Models\Declaration`
- **Spatie activity_log:** `activity_log.subject_type` stores `App\Models\Folder` — same data migration
- **No morph map:** The codebase has NO `Relation::morphMap()` — polymorphic types store full class names. The data migration in Task 12 handles this. Do NOT register a morph map as a shortcut — keep consistent with existing pattern
- **Laravel 12:** No `doctrine/dbal` needed for schema operations
- **Docker Compose:** Everything runs under Docker — use `docker compose exec laravel.test` prefix for artisan/composer commands

### Rename Strategy — Order of Operations

**The order matters to avoid broken imports during the rename process:**

1. **Enums first** (no dependencies on other renamed files)
2. **Models second** (depend on enums, depended on by everything else)
3. **Related models** (depend on renamed models)
4. **Form Requests** (depend on enums)
5. **Controllers** (depend on models, enums, requests)
6. **Mail classes** (depend on models)
7. **Blade templates** (referenced by mail classes)
8. **Notification** (depends on models)
9. **Middleware** (depends on models)
10. **Routes** (depend on controllers, middleware)
11. **Factory + Seeder** (depend on models, enums)
12. **Polymorphic data migration** (standalone DB operation)
13. **Tests** (depend on everything)

### File Rename Mapping (Complete)

| Old Path | New Path |
|---|---|
| `app/Enums/FolderType.php` | `app/Enums/DeclarationType.php` |
| `app/Enums/FolderStatus.php` | `app/Enums/DeclarationStatus.php` |
| `app/Enums/FolderPriority.php` | `app/Enums/DeclarationPriority.php` |
| `app/Models/Folder.php` | `app/Models/Declaration.php` |
| `app/Models/FolderInvitation.php` | `app/Models/DeclarationInvitation.php` |
| `app/Http/Controllers/FolderController.php` | `app/Http/Controllers/DeclarationController.php` |
| `app/Http/Controllers/FolderMediaController.php` | `app/Http/Controllers/DeclarationMediaController.php` |
| `app/Http/Controllers/FolderMessageController.php` | `app/Http/Controllers/DeclarationMessageController.php` |
| `app/Http/Controllers/FolderMentionController.php` | `app/Http/Controllers/DeclarationMentionController.php` |
| `app/Http/Requests/StoreFolderRequest.php` | `app/Http/Requests/StoreDeclarationRequest.php` |
| `app/Http/Requests/UpdateFolderRequest.php` | `app/Http/Requests/UpdateDeclarationRequest.php` |
| `app/Http/Requests/StoreFolderMessageRequest.php` | `app/Http/Requests/StoreDeclarationMessageRequest.php` |
| `app/Http/Requests/StoreFolderMentionRequest.php` | `app/Http/Requests/StoreDeclarationMentionRequest.php` |
| `app/Mail/FolderInviteMail.php` | `app/Mail/DeclarationInviteMail.php` |
| `app/Mail/FolderConfirmationMail.php` | `app/Mail/DeclarationConfirmationMail.php` |
| `app/Mail/FolderFileRequestMail.php` | `app/Mail/DeclarationFileRequestMail.php` |
| `app/Mail/FolderSituationMail.php` | `app/Mail/DeclarationSituationMail.php` |
| `app/Mail/FolderTextMessageMail.php` | `app/Mail/DeclarationTextMessageMail.php` |
| `app/Notifications/FolderMentionNotification.php` | `app/Notifications/DeclarationMentionNotification.php` |
| `app/Http/Middleware/ValidateFolderInvitation.php` | `app/Http/Middleware/ValidateClientPortalToken.php` |
| `database/factories/FolderFactory.php` | `database/factories/DeclarationFactory.php` |
| `resources/views/emails/folder-invite.blade.php` | `resources/views/emails/declaration-invite.blade.php` |
| `resources/views/emails/folder-confirmation.blade.php` | `resources/views/emails/declaration-confirmation.blade.php` |
| `resources/views/emails/folder-file-request.blade.php` | `resources/views/emails/declaration-file-request.blade.php` |
| `resources/views/emails/folder-situation.blade.php` | `resources/views/emails/declaration-situation.blade.php` |
| `resources/views/emails/folder-text-message.blade.php` | `resources/views/emails/declaration-text-message.blade.php` |
| `resources/views/emails/folder-mention.blade.php` | `resources/views/emails/declaration-mention.blade.php` |
| `tests/Feature/Folder/` | `tests/Feature/Declaration/` |

### Variable and Method Rename Patterns

Within the renamed files AND referencing files, apply these renames consistently:

| Old Pattern | New Pattern |
|---|---|
| `$folder` | `$declaration` |
| `$folders` | `$declarations` |
| `$folderTypes` | `$declarationTypes` |
| `$folderIndex` | `$declarationIndex` |
| `$numFolders` | `$numDeclarations` |
| `folder_id` | `declaration_id` |
| `folder_title` | `declaration_title` |
| `folder_invitation` (request attr) | `declaration_invitation` |
| `authorizeFolder()` | `authorizeDeclaration()` |
| `folderTypeLabels()` | `declarationTypeLabels()` |
| `folderStatusLabels()` | `declarationStatusLabels()` |
| `folderPriorityLabels()` | `declarationPriorityLabels()` |
| `createInvitation()` | Keep name (context-independent) |
| `getOrCreateInvitation()` | Keep name (context-independent) |
| `updateFolderStatusAndConfirmation()` | `updateDeclarationStatusAndConfirmation()` |
| `sendEmailForMessage()` | Keep name (context-independent) |
| `route('folders.*')` | `route('declarations.*')` |
| `'emails.folder-*'` (view refs) | `'emails.declaration-*'` |

### Controllers That Reference Folder (Update Only, Not Rename)

These controllers import `Folder`/`FolderStatus` and need import + usage updates:

- **`DashboardController.php`** — imports `Folder`, `FolderStatus`. Uses folder queries for dashboard stats (assignedFolders, overdue, dueSoon, etc.)
- **`ClientController.php`** — uses `Folder` model via `$client->folders()` relationship
- **`WorkspaceController.php`** — imports `Folder`, `FolderStatus`. Uses folder counts for workspace stats
- **`Client/UploadController.php`** — imports `FolderStatus`, gets `folder` from request attribute
- **`Client/ConfirmController.php`** — imports `FolderStatus`, gets `folder` from request attribute

### Polymorphic Data Migration — Critical

The `media` and `activity_log` tables store `App\Models\Folder` as FQCN in `model_type` / `subject_type` columns. After renaming the model class, existing rows will point to a non-existent class.

**Migration `2026_03_11_000002_update_polymorphic_folder_to_declaration.php`:**

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        DB::table('media')
            ->where('model_type', 'App\\Models\\Folder')
            ->update(['model_type' => 'App\\Models\\Declaration']);

        DB::table('activity_log')
            ->where('subject_type', 'App\\Models\\Folder')
            ->update(['subject_type' => 'App\\Models\\Declaration']);
    }

    public function down(): void
    {
        DB::table('media')
            ->where('model_type', 'App\\Models\\Declaration')
            ->update(['model_type' => 'App\\Models\\Folder']);

        DB::table('activity_log')
            ->where('subject_type', 'App\\Models\\Declaration')
            ->update(['subject_type' => 'App\\Models\\Folder']);
    }
};
```

**Migration timestamp:** `2026_03_11_000002` — MUST be after `2026_03_11_000001` (the rename migration from Story 0.1).

### Client Portal Middleware Rename

The middleware `ValidateFolderInvitation` → `ValidateClientPortalToken` is an **intentional semantic rename** (not just s/Folder/Declaration). The AC from the epics specifies this name. Update both:

1. `app/Http/Middleware/ValidateClientPortalToken.php` (file + class name)
2. `bootstrap/app.php` alias: `'client-portal' => ValidateClientPortalToken::class`
3. `routes/web.php` middleware usage: `->middleware('client-portal')`

Inside the middleware, also rename:
- `FolderInvitation` → `DeclarationInvitation`
- `$invitation->folder` → `$invitation->declaration`
- Request attributes: `folder_invitation` → `declaration_invitation`, `folder` attribute → `declaration`

In client portal controllers (`Client/UploadController.php`, `Client/ConfirmController.php`), update:
- `$request->attributes->get('folder_invitation')` → `$request->attributes->get('declaration_invitation')`
- `$request->attributes->get('folder')` → `$request->attributes->get('declaration')`

### Factory Rename — Model Binding

When renaming `FolderFactory` → `DeclarationFactory`, Laravel auto-discovers factories by convention (`App\Models\Declaration` → `Database\Factories\DeclarationFactory`). The `HasFactory` trait on `Declaration` model will resolve correctly if the factory class name matches. No explicit `newFactory()` override needed.

### Blade Template Content Updates

When renaming blade templates, also update **variable names inside** them:
- `$folder->title` → `$declaration->title`
- `$folder->client->name` → `$declaration->client->name`
- Any other `$folder` or `$invitation->folder` references → `$declaration` / `$invitation->declaration`

### Route Name Changes Impact

After renaming routes from `folders.*` to `declarations.*`, update all `route()` helper calls:
- `route('folders.index')` → `route('declarations.index')`
- `route('folders.create')` → `route('declarations.create')`
- `route('folders.store')` → `route('declarations.store')`
- `route('folders.show', $folder)` → `route('declarations.show', $declaration)`
- `route('folders.edit', $folder)` → `route('declarations.edit', $declaration)`
- `route('folders.update', $folder)` → `route('declarations.update', $declaration)`
- `route('folders.destroy', $folder)` → `route('declarations.destroy', $declaration)`
- `route('folders.messages.store', $folder)` → `route('declarations.messages.store', $declaration)`
- `route('folders.media.store', $folder)` → `route('declarations.media.store', $declaration)`
- `route('folders.media.download', [...])` → `route('declarations.media.download', [...])`
- `route('folders.mentions.store', $folder)` → `route('declarations.mentions.store', $declaration)`

### Previous Story Intelligence (Story 0.1)

Key learnings from Story 0.1 that apply here:
- **SQLite vs MySQL:** Use Laravel's `Schema` facade methods exclusively, never raw SQL
- **Docker commands:** Run all artisan/test commands via `docker compose exec laravel.test`
- **Pest tests:** Use `test()` closures, `RefreshDatabase` is auto-applied, use `expect()` chaining
- **PHP version:** Already upgraded to PHP 8.4 in compose.yaml
- **Test DB:** phpunit.xml configured for `DB_CONNECTION=sqlite`, `DB_DATABASE=:memory:`
- **Application will be non-functional** after Story 0.1 migration until this story is complete — Stories 0.1 + 0.2 should run in same session
- **FK constraint caution:** When dealing with foreign keys, use explicit column array syntax for cross-driver compatibility

### Warning: Frontend Will Break After This Story

After this story, the application frontend will be broken until Story 0.3 (frontend rename) is completed:
- Vue components still import from `@/pages/folders/`
- TypeScript types still reference `Folder`
- Wayfinder routes will regenerate with `declarations.*` names but frontend still uses old names
- **Stories 0.2 and 0.3 should be implemented in close succession**

### Testing Standards

- Use **Pest** syntax (`test()` closures), never PHPUnit class-based tests
- `RefreshDatabase` is auto-applied via `Pest.php` — don't add manually
- Run tests: `composer test`
- Feature tests grouped by domain: `tests/Feature/Declaration/`, `tests/Feature/Notification/`
- Use `route()` helper for URLs in tests
- After rename, run full test suite to catch any missed references

### Project Structure Notes

- All file renames should use `git mv` to preserve history
- New migration file goes in `database/migrations/` with timestamp `2026_03_11_000002`
- Test directory rename: `tests/Feature/Folder/` → `tests/Feature/Declaration/`
- Email templates: `resources/views/emails/folder-*.blade.php` → `declaration-*.blade.php`

### References

- [Source: _bmad-output/planning-artifacts/epics.md#Story 0.2]
- [Source: _bmad-output/planning-artifacts/architecture.md#Pre-Phase Migration]
- [Source: _bmad-output/planning-artifacts/architecture.md#Declaration Status Flow]
- [Source: _bmad-output/planning-artifacts/architecture.md#Role-Scoped Query Patterns]
- [Source: _bmad-output/project-context.md#Technology Stack]
- [Source: _bmad-output/implementation-artifacts/0-1-rename-folders-to-declarations-in-database.md]
- [Source: app/Models/Folder.php]
- [Source: app/Models/FolderInvitation.php]
- [Source: app/Http/Controllers/FolderController.php]
- [Source: app/Http/Controllers/FolderMediaController.php (line 65 — polymorphic query)]
- [Source: routes/web.php]
- [Source: bootstrap/app.php]

## Dev Agent Record

### Agent Model Used

Claude Opus 4.6

### Debug Log References

N/A

### Completion Notes List

- All 40+ files renamed/updated successfully using `git mv` for history preservation
- Fixed pre-existing bug: `withValidator` `$this->merge()` in `after` callback doesn't affect `$request->validated()` — moved period field nullification to controller
- Fixed rollback test: updated `--step` from 1 to 2 to account for the new polymorphic migration
- Fixed pre-existing test failure (`ProfileUpdateTest > user can delete their account`) — `SoftDeletes` trait makes `fresh()` return soft-deleted record instead of null, changed assertion to `expect($user->fresh()->deleted_at)->not->toBeNull()`
- Frontend prop names (`createFolderUrl`, `assignedFolders`, `'folder'`, `'folders'`) intentionally kept unchanged — will be renamed in Story 0.3
- Inertia render paths (`'folders/Index'`, `'folders/Show'`, etc.) intentionally kept unchanged — frontend Vue files not yet renamed
- [AI-Review] Cosmetic changes applied outside story scope: EOF newline fixes (13 test files), import reordering (3 activity log migrations, User.php), whitespace formatting (2 workspace request files), unused import removal (ClientEmailTest.php). These do not affect functionality but represent undisciplined scope.
- [AI-Review] `activity_log.causer_type` verified safe — Spatie defaults to `App\Models\User` as causer, no custom `causedBy()` calls exist. No migration needed.

### Change Log

- Renamed 3 enums: `FolderType` → `DeclarationType`, `FolderStatus` → `DeclarationStatus`, `FolderPriority` → `DeclarationPriority`
- Renamed 2 models: `Folder` → `Declaration`, `FolderInvitation` → `DeclarationInvitation`
- Updated 3 related models: `Client`, `Workspace`, `Message` (relationships + imports)
- Renamed 4 form requests: `StoreFolderRequest` → `StoreDeclarationRequest`, etc.
- Renamed 4 controllers: `FolderController` → `DeclarationController`, etc.
- Updated 5 controllers in place: `DashboardController`, `ClientController`, `WorkspaceController`, `Client/UploadController`, `Client/ConfirmController`
- Renamed 5 mail classes: `FolderInviteMail` → `DeclarationInviteMail`, etc.
- Renamed 6 blade email templates: `folder-*.blade.php` → `declaration-*.blade.php`
- Renamed notification: `FolderMentionNotification` → `DeclarationMentionNotification`
- Renamed middleware: `ValidateFolderInvitation` → `ValidateClientPortalToken`
- Updated `bootstrap/app.php`: alias `folder.invitation` → `client-portal`
- Updated `routes/web.php`: resource `folders` → `declarations`, middleware `client-portal`
- Renamed factory: `FolderFactory` → `DeclarationFactory`
- Updated `DatabaseSeeder.php`
- Created polymorphic data migration: `2026_03_11_000002_update_polymorphic_folder_to_declaration.php`
- Renamed test directory and test files
- Fixed period field nullification bug in `DeclarationController` store/update methods
- Fixed `ProfileUpdateTest` SoftDeletes assertion (pre-existing failure)
- Cosmetic changes: EOF newlines (13 files), import reordering (4 files), whitespace (2 files), unused import removal (1 file)

**AI Code Review (2026-03-12):**
- Updated File List: added 20 undocumented modified files
- Added Task 5.10: `Client/RefuseController.php` update
- Added Task 12.5: verify `activity_log.causer_type` for stale FQCN
- Updated Completion Notes with review findings

### File List

**Renamed files (git mv):**
- `app/Enums/DeclarationType.php` (was `FolderType.php`)
- `app/Enums/DeclarationStatus.php` (was `FolderStatus.php`)
- `app/Enums/DeclarationPriority.php` (was `FolderPriority.php`)
- `app/Models/Declaration.php` (was `Folder.php`)
- `app/Models/DeclarationInvitation.php` (was `FolderInvitation.php`)
- `app/Http/Controllers/DeclarationController.php` (was `FolderController.php`)
- `app/Http/Controllers/DeclarationMediaController.php` (was `FolderMediaController.php`)
- `app/Http/Controllers/DeclarationMessageController.php` (was `FolderMessageController.php`)
- `app/Http/Controllers/DeclarationMentionController.php` (was `FolderMentionController.php`)
- `app/Http/Requests/StoreDeclarationRequest.php` (was `StoreFolderRequest.php`)
- `app/Http/Requests/UpdateDeclarationRequest.php` (was `UpdateFolderRequest.php`)
- `app/Http/Requests/StoreDeclarationMessageRequest.php` (was `StoreFolderMessageRequest.php`)
- `app/Http/Requests/StoreDeclarationMentionRequest.php` (was `StoreFolderMentionRequest.php`)
- `app/Mail/DeclarationInviteMail.php` (was `FolderInviteMail.php`)
- `app/Mail/DeclarationConfirmationMail.php` (was `FolderConfirmationMail.php`)
- `app/Mail/DeclarationFileRequestMail.php` (was `FolderFileRequestMail.php`)
- `app/Mail/DeclarationSituationMail.php` (was `FolderSituationMail.php`)
- `app/Mail/DeclarationTextMessageMail.php` (was `FolderTextMessageMail.php`)
- `app/Notifications/DeclarationMentionNotification.php` (was `FolderMentionNotification.php`)
- `app/Http/Middleware/ValidateClientPortalToken.php` (was `ValidateFolderInvitation.php`)
- `database/factories/DeclarationFactory.php` (was `FolderFactory.php`)
- `resources/views/emails/declaration-invite.blade.php` (was `folder-invite.blade.php`)
- `resources/views/emails/declaration-confirmation.blade.php` (was `folder-confirmation.blade.php`)
- `resources/views/emails/declaration-file-request.blade.php` (was `folder-file-request.blade.php`)
- `resources/views/emails/declaration-situation.blade.php` (was `folder-situation.blade.php`)
- `resources/views/emails/declaration-text-message.blade.php` (was `folder-text-message.blade.php`)
- `resources/views/emails/declaration-mention.blade.php` (was `folder-mention.blade.php`)
- `tests/Feature/Declaration/DeclarationTypeTest.php` (was `Folder/FolderTypeTest.php`)
- `tests/Feature/Declaration/MediaDownloadTest.php` (was `Folder/MediaDownloadTest.php`)
- `tests/Feature/Notification/DeclarationMentionTest.php` (was `FolderMentionTest.php`)

**Modified in place:**
- `app/Models/Client.php`
- `app/Models/Workspace.php`
- `app/Models/Message.php`
- `app/Models/User.php` (cosmetic: trait use order alphabetized)
- `app/Http/Controllers/DashboardController.php`
- `app/Http/Controllers/ClientController.php`
- `app/Http/Controllers/WorkspaceController.php`
- `app/Http/Controllers/Client/UploadController.php`
- `app/Http/Controllers/Client/ConfirmController.php`
- `app/Http/Controllers/Client/RefuseController.php`
- `app/Http/Requests/StoreWorkspaceRequest.php` (cosmetic: whitespace formatting)
- `app/Http/Requests/UpdateWorkspaceRequest.php` (cosmetic: whitespace formatting)
- `bootstrap/app.php`
- `routes/web.php`
- `database/seeders/DatabaseSeeder.php`
- `database/migrations/2026_02_28_102716_create_activity_log_table.php` (cosmetic: import reordering)
- `database/migrations/2026_02_28_102717_add_event_column_to_activity_log_table.php` (cosmetic: import reordering)
- `database/migrations/2026_02_28_102718_add_batch_uuid_column_to_activity_log_table.php` (cosmetic: import reordering)
- `tests/Feature/Notification/NotificationControllerTest.php`
- `tests/Feature/Database/RenameFoldersToDeclarationsTest.php`
- `tests/Feature/Client/ClientEmailTest.php` (removed unused `ClientContact` import)
- `tests/Feature/Settings/ProfileUpdateTest.php` (fixed SoftDeletes assertion)
- `tests/Feature/Auth/AuthenticationTest.php` (cosmetic: EOF newline)
- `tests/Feature/Auth/EmailVerificationTest.php` (cosmetic: EOF newline)
- `tests/Feature/Auth/PasswordConfirmationTest.php` (cosmetic: EOF newline)
- `tests/Feature/Auth/PasswordResetTest.php` (cosmetic: EOF newline)
- `tests/Feature/Auth/RegistrationTest.php` (cosmetic: EOF newline)
- `tests/Feature/Auth/TwoFactorChallengeTest.php` (cosmetic: EOF newline)
- `tests/Feature/Auth/VerificationNotificationTest.php` (cosmetic: EOF newline)
- `tests/Feature/DashboardTest.php` (cosmetic: EOF newline)
- `tests/Feature/ExampleTest.php` (cosmetic: EOF newline)
- `tests/Feature/Settings/PasswordUpdateTest.php` (cosmetic: EOF newline)
- `tests/Feature/Settings/TwoFactorAuthenticationTest.php` (cosmetic: EOF newline)
- `tests/Unit/ExampleTest.php` (cosmetic: EOF newline)

**New files:**
- `database/migrations/2026_03_11_000002_update_polymorphic_folder_to_declaration.php`
