# Project Memory - Todo & Future Improvements

## Last Updated: 2026-05-29 (Phase 4 Complete)

---

## Completed in Phase 4

- ✅ **Auto Replies module** — Filament resource + webhook integration
- ✅ **Media Attachment support** — Upload, storage, download endpoints (pending WhatsApp send)
- ✅ **Real-time/WebSocket** — Laravel Reverb configured + Echo listeners (requires `php artisan reverb:start`)
- ✅ **Message Search** — Role-scoped API endpoint
- ✅ **Bulk Actions** — bulk_close + bulk_mark_read on ConversationResource
- ✅ **CSV Export** — Conversations, employee performance, team performance
- ✅ **Activity Timeline** — Migration + model + logging on key events

## Remaining Issues

| # | Issue | Priority | Notes |
|---|-------|----------|-------|
| 1 | PHP 8.2+ required for production | High | System currently uses PHP 8.2 (needs upgrade from 8.1) |
| 2 | WhatsApp Cloud API sendMedia | Medium | Files stored locally with pending status; actual send not implemented |
| 3 | Typing indicator not functional | Low | Requires per-conversation WebSocket channels |
| 4 | Dark/Light mode not synced with Filament | Low | Works independently |
| 5 | Role switcher is local-only | Low | Doesn't change real permissions |
| 6 | WHATSAPP_APP_SECRET not configured | High | Webhook signature verification will fail until real secret is set |
| 7 | No charts/graphs in reports | Low | Data displayed in tables and KPI cards only |
| 8 | Settings page is read-only | Low | No editable forms yet — status dashboard only |
| 9 | Permissions management UI | Low | Currently placeholder |
| 10 | Horizon/Redis queue not active | Medium | QUEUE_CONNECTION=database, Horizon config expects Redis |

## Future Improvements

| # | Improvement | Priority | Notes |
|---|-------------|----------|-------|
| 1 | Switch to Redis queue + Horizon | High | For production scalability |
| 2 | WhatsApp sendMedia implementation | Medium | Upload stored files to WhatsApp Cloud API |
| 3 | Build Permissions management UI | Medium | Replace placeholder page |
| 4 | Scheduler for cleanup tasks | Medium | Old logs, failed uploads |
| 5 | Dashboard widgets for auto-reply | Low | Auto-reply performance metrics |
| 6 | Per-conversation Echo channels | Low | For typing indicators and finer-grained real-time |
| 7 | Charts/graphs in reports | Low | Visual charts for KPI trends |
| 8 | Settings management UI | Low | Editable configuration forms |
| 5 | WebSocket/SSE integration | Medium | Pending | Replace polling with real-time |
| 6 | Code splitting | Low | Pending | Load CSS/JS on demand |
| 7 | CDN integration | Low | Pending | Serve static files faster |
| 8 | Image optimization | Low | Pending | Auto-compress images |
| 9 | Browser caching headers | Low | Pending | Improve cache policies |

## Feature Improvements

| # | Improvement | Priority | Status | Notes |
|---|-------------|----------|--------|-------|
| 1 | Real-time notifications | High | Pending | Via WebSocket |
| 2 | Reports & Analytics page | High | Done | Phase 3C — KPI cards, tables, filters, role-scoped |
| 3 | Settings & WhatsApp Health page | High | Done | Phase 3D — read-only status dashboard |
| 4 | Charts/graphs for reports | Medium | Pending | Add visual charts (bar, line, pie) |
| 5 | CSV/Excel export for reports | Low | Pending | Export button placeholder shown |
| 6 | Auto-replies module | Medium | Pending | Manage auto-reply rules |
| 7 | Editable settings forms | Medium | Pending | Make Settings configurable |
| 8 | File/media upload | Medium | Pending | Full WhatsApp media support |
| 9 | Message search | Medium | Pending | Search conversation history |
| 10 | Bulk actions | Medium | Pending | Bulk close, assign, transfer |
| 11 | Email notifications | Low | Pending | Notify agents via email |
| 12 | Custom permissions UI | Low | Pending | Admin panel for permissions |
| 13 | Activity timeline | Low | Pending | Visual conversation events |

## Design Improvements

| # | Improvement | Priority | Status | Notes |
|---|-------------|----------|--------|-------|
| 1 | Mobile app | Medium | Pending | Native iOS/Android app |
| 2 | Advanced animations | Low | Pending | Micro-interactions |
| 3 | Custom themes | Low | Pending | User-selectable themes |
| 4 | Accessibility improvements | Medium | Pending | WCAG 2.1 compliance |
| 5 | Print styles | Low | Pending | Print-friendly layouts |

## Completed Improvements

| # | Improvement | Date | Notes |
|---|-------------|------|-------|
| 1 | Design unification | 2026-05-29 | unified-theme.css applied |
| 2 | Database query optimization | 2026-05-29 | 65% fewer queries |
| 3 | Polling frequency reduction | 2026-05-29 | 47% less server load |
| 4 | Cache clearing automation | 2026-05-29 | View, config, route caches |
| 5 | Eager loading implementation | 2026-05-29 | N+1 queries eliminated |
| 6 | CSS consolidation | 2026-05-29 | Unified design system |
| 7 | Performance monitoring | 2026-05-29 | Metrics documented |
| 8 | Textarea auto-grow input | 2026-05-29 | Multi-line message support with Enter/Shift+Enter |
| 9 | CSS duplication cleanup | 2026-05-29 | Removed 4 duplicate blocks (1517→1239 lines) |
| 10 | Firefox scrollbar support | 2026-05-29 | scrollbar-width thin + scrollbar-color for textarea |
| 11 | Firefox scrollbar support | 2026-05-29 | scrollbar-width thin + scrollbar-color for textarea |
| 12 | Reports Dashboard (Phase 3C) | 2026-05-29 | KPI cards, tables, filters, role-scoped |
| 13 | Settings & WhatsApp Health (Phase 3D) | 2026-05-29 | Status dashboard, health checks, routing rules |

## Next Sprint Priorities

### Week 1
1. Add Redis cache for statistics
2. Add database indexes
3. Add charts/graphs to reports

### Week 2
1. Set up WebSocket/SSE
2. Implement CSV/Excel export
3. Implement auto-replies module

### Week 3
1. Complete file upload feature
2. Add message search
3. Implement bulk actions

### Week 4
1. Add email notifications
2. Create export functionality
3. Improve accessibility

---

## Phase 2 Tasks From Phase 1 Audit - 2026-05-29 11:38:13 +03:00

| # | Task | Priority | Notes |
|---|---|---|---|
| 1 | Configure PHPUnit to use an isolated test database | Critical | Current `phpunit.xml` does not use `:memory:` or a separate test DB; `artisan test` reset the local SQLite data during audit. |
| 2 | Restore/reseed development data only after approval | Critical | After the test run, local SQLite table counts became zero. Do not run more tests against the local DB. |
| 3 | Scope chat workspace CSS so it does not hide Filament navigation globally | High | `chat-workspace.css` hides `.fi-sidebar` and `.fi-topbar` on all admin pages. |
| 4 | Replace misleading sidebar aliases | High | Reports currently opens Webhook Events; Permissions and Settings open Users. |
| 5 | Fix Assignment Log permissions | Critical | Agent resource logic can access all assignment rows; add backend/resource filtering or block access. |
| 6 | Align dashboard role values with backend roles | High | Dashboard selector uses `manager/support/supervisor`; backend uses `admin/supervisor/agent`. |
| 7 | Align sidebar role access with resource policies | High | Dashboard allows supervisor for Contacts/Team/Reports, but backend blocks or routes to wrong screen. |
| 8 | Decide and enforce whether employees can transfer conversations | High | Current backend allows agents to transfer own conversations; expected behavior says employees should handle assigned chats only. |
| 9 | Create a clear Team / Employees screen | High | User creation exists, but employee management is spread between Users and Teams. |
| 10 | Add employee profile/detail panels | Medium | Include role, team, active status, WhatsApp phone ID, assigned conversations, and assignment history. |
| 11 | Create a real Permissions screen or remove item until implemented | High | Spatie permissions table is empty and no permission matrix exists. |
| 12 | Create a real Settings screen or remove item until implemented | High | Settings currently routes to Users. |
| 13 | Create a real Reports screen | High | Current Reports route is technical webhook events. |
| 14 | Implement true Waiting List workflow | High | Incoming messages are assigned to manager/admin as open, not pending/unassigned. |
| 15 | Wire contact dedicated agent into routing or hide field | Medium | Contact form supports dedicated agent, but `ConversationRouter` ignores it. |
| 16 | Add duplicate-conversation cleanup/merge plan | Medium | Historical duplicate conversations existed for the same contact before test DB reset. |
| 17 | Reduce full page reload navigation after structure is fixed | Medium | Dashboard sidebar uses `window.location.href`. |
| 18 | Reduce polling overlap | Medium | Dashboard polls workspace data, ConversationResource polls table every 3s, and Filament notifications poll every 5s. |

## Phase 2 Status and Phase 3 TODO - 2026-05-29 12:09:31 +03:00

### Completed in Phase 2

| Task | Status |
|---|---|
| Configure PHPUnit isolated test database | Done |
| Scope chat workspace CSS | Done |
| Replace misleading sidebar routes | Done |
| Create real Reports, Permissions, Settings placeholders | Done |
| Create real Waiting List route/placeholder | Done |
| Fix Assignment Log employee access gap | Done |
| Block employee conversation transfer | Done |
| Filter supervisor transfer targets to team employees | Done |
| Align role labels with backend roles | Done |
| Clarify Team / Employees nav and employee form | Done |

### Phase 3 Recommended Tasks

| Priority | Task | Notes |
|---|---|---|
| Critical | Restore/reseed development data only after approval | Local SQLite data was already reset during Phase 1 testing. |
| High | Implement true pending/unassigned Waiting List workflow | New incoming conversations should enter pending/unassigned queue before assignment. |
| High | Build real Reports data | Add scoped KPIs, filters, exports. |
| High | Build real Settings forms | WhatsApp credentials, webhook status, routing rules, notifications. |
| High | Decide configurable permissions model | Keep policy-based roles or add permission matrix/per-employee overrides. |
| Medium | Add employee profile/detail panels | Role, team, supervisor, status, WhatsApp ID, assignment count/history. |
| Medium | Wire dedicated contact agent into routing or hide field | Current form field is not fully connected to router behavior. |
| Medium | Optimize navigation and polling | Reduce full reloads, duplicate polling, and heavy initial loads. |

## Phase 3A Completion - 2026-05-29 12:30:00 +03:00

### Completed in Phase 3A

| Task | Status |
|---|---|
| Implement true pending/unassigned Waiting List workflow | Done |
| Route unknown/unroutable WhatsApp messages to Waiting List | Done |
| Use active dedicated agent when configured | Done |
| Prevent duplicate pending conversations for the same customer | Done |
| Add Waiting List assignment action | Done |
| Add admin/supervisor/employee authorization for Waiting List | Done |
| Add Waiting List API endpoints | Done |
| Record Assignment Log on waiting-list assignment | Done |
| Add Phase 3A tests | Done |

### Remaining Phase 3B/3C Tasks

| Priority | Task | Notes |
|---|---|---|
| High | Build real Reports data | Conversation volume, response time, employee/team performance, filters, export. |
| High | Build real Settings forms | WhatsApp credentials, webhook status, routing rules, notifications. |
| High | Decide configurable Permissions matrix | Current system remains role/policy based. |
| Medium | Add employee profile/detail panels | Role, team, supervisor, status, WhatsApp ID, assignment history. |
| Medium | Define supervisor handling of global unscoped waiting rows | Current Phase 3A keeps them admin-only. |
| Medium | Add historical duplicate cleanup/merge plan | Runtime duplicate prevention is in place for active/pending flow. |
| Medium | Optimize polling/navigation | No WebSocket or full SPA rewrite was done in Phase 3A. |

## Phase 3B Completion - 2026-05-29 12:45:48 +03:00

### Completed in Phase 3B

| Task | Status |
|---|---|
| Add employee profile/detail page | Done |
| Show basic employee role/team/status/WhatsApp data | Done |
| Show workload summary | Done |
| Show assignment history | Done |
| Show latest assigned conversations | Done |
| Enforce admin/supervisor/employee profile access rules | Done |
| Add open-conversation warning on employee edit form | Done |
| Add Phase 3B tests | Done |

### Completed in Phase 3C

| Task | Status |
|---|---|
| Build real Reports Dashboard at `/admin/reports` | Done |
| Add KPI cards (8 metrics) | Done |
| Add conversation status report | Done |
| Add employee performance table | Done |
| Add team performance table | Done |
| Add assignment report | Done |
| Add time filters (today/yesterday/7d/30d/all) | Done |
| Add team filter (admin only) | Done |
| Add employee filter | Done |
| Enforce admin/supervisor/employee report access | Done |
| Write efficient aggregate queries (no N+1 loading) | Done |
| Add export placeholder (no fake export) | Done |
| Add Phase 3C tests (15 tests) | Done |

### Remaining Post-Phase 3C Tasks

| Priority | Task | Notes |
|---|---|---|
| Medium | Add charts/graphs to Reports | Bar charts for trends, pie charts for status breakdown |
| Low | Add CSV/Excel export | Export button exists but disabled |
| Low | Add custom date range picker | Predefined periods only currently |

### Completed in Phase 3D

| Task | Status |
|---|---|
| Build real Settings page at `/admin/settings` | Done |
| Add WhatsApp Integration Status section (6 config checks) | Done |
| Add Webhook Health section (events, endpoint, signature) | Done |
| Add Cloud API Health section (5 readiness checks) | Done |
| Add Routing Rules section (read-only behavior descriptions) | Done |
| Add Notification Settings section | Done |
| Add Chat Behavior section | Done |
| Add health warnings for missing config | Done |
| Mask secrets in UI (no plain-text tokens) | Done |
| Enforce admin-only access (supervisor/employee 403) | Done |
| Add Phase 3D tests (10 tests) | Done |

### Remaining Post-Phase 3D Tasks

| Priority | Task | Notes |
|---|---|---|
| High | Decide configurable Permissions matrix | Current permissions remain policy/role based. |
| Medium | Add My Profile route if needed | Employee self-view was not implemented in Phase 3B. |
| Medium | Add deactivation/transfer workflow | Current form warns about open conversations but does not transfer them automatically. |
| Medium | Add exact assigned-from audit field if required | Current profile infers assigned-from from previous assignment rows. |
| Medium | Add editable settings forms | Current Settings page is read-only status dashboard. |
| Low | Add charts/graphs to Reports | Bar charts for trends, pie charts for status breakdown |
| Low | Add CSV/Excel export | Export button exists but disabled |
| Low | Add custom date range picker for Reports | Predefined periods only currently |
| Low | Optimize polling/navigation | Still deferred. |
