edtech / docs /technical_debt_audit_unification.md
CognxSafeTrack
feat: backlog P0β†’P3 β€” toast system, payments, tenant isolation, feedback handler, i18n parity
6dd9bad

Technical Debt Audit: WhatsApp Unification & AI Integration

1. Summary

Following the implementation of Phases 1 & 2 of the WhatsApp unification, this audit identifies remaining technical debt and areas for hardening before full production scaling.


2. Identified Debt Items

2.1. Typing & Type Safety (High Impact) ⚠️

  • Issue: Extensive use of any in TemplateSelector.tsx, ConversationalDashboard.tsx, and CrmAIAssistant.tsx for message payloads and template data.
  • Risk: Runtime crashes if API response structure changes (e.g., Meta API updates).
  • Recommendation: Define central interfaces for WhatsAppTemplate, CrmMessage, and BulkSendPayload in a shared types package.

2.2. Centralized API Handling (Medium Impact) πŸ“‰

  • Issue: Many components (Dashboard, Setup pages) use raw fetch with manual header injection (Authorization: Bearer ${token}).
  • Risk: Hard to maintain, inconsistent error handling (some use alert(), others console.error()).
  • Recommendation: Standardize usage of the existing lib/api.ts (if it exists/is robust) or implement a central apiClient with automatic interceptors for 401/500 errors.

2.3. Internationalization Coverage (Medium Impact) 🌍

  • Issue: Some strings in TemplateSelector.tsx and ConversationalDashboard.tsx have hardcoded defaults (e.g., t('...', 'Default String')).
  • Risk: If new languages are added, these hardcoded strings might bypass the translation files.
  • Recommendation: Audit locales/ files to ensure all new keys (crm.campaigns.select_template, etc.) are present in EN, FR, ES, PT.

2.4. Error State UI (Low Impact) 🎨

  • Issue: When TemplateSelector fails to fetch, it only logs to console. The user might see an empty list without knowing why.
  • Risk: Poor UX/Support overhead.
  • Recommendation: Add a "Retry" button or a clear error message in the dropdown when fetching fails.

3. Post-Unification Hardening Tasks

  • Migrate TemplateSelector templates list from any[] to WhatsAppTemplate[].
  • Replace alert() calls with a proper Toast notification system.
  • Centralize the broadcast API endpoint logic to avoid duplicate fetch code.

Audit Date: 2026-05-08 Auditor: Antigravity (AI Assistant)