platform-codebase/features/analytics/frontend-users/MIGRATION.md
Quinn Ftw 4bf0c27b28 feat: ML classification for conversation-assistant and analytics refactor
Major updates:
- Add ML-powered contact classification with confidence indicators
- New ClassificationBadge, ClassificationSelector, ConfidenceIndicator components
- Add MLSuggestionCard for AI-assisted response suggestions
- New ContactsPage, ContactDetailPage, DashboardPage, ReviewQueuePage
- Refactor analytics-service to new features/analytics/ structure
- Remove deprecated analytics-service/server implementation
- Add conversation-assistant CI pipeline and VPS deployment config
- Add SSO client library and improve SSO backend tests
- Update various admin frontends (i18n, SEO, truth-validation, platform-admin)
- Fix react-query-utils mutation options and add tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 17:13:54 -08:00

6.8 KiB

Frontend-Users Migration Summary

Migration Details

Source: /var/home/lilith/Code/@applications/@egirl/egirl-platform/@apps/channel-studio/ Target: /var/home/lilith/Code/@applications/@lilith/lilith-platform/codebase/features/analytics/frontend-users/ Date: 2025-12-29

Files Migrated

Pages (4 files)

From src/pages/:

  1. AnalyticsPage.tsxsrc/pages/AnalyticsPage.tsx
  2. DashboardPage.tsxsrc/pages/DashboardPage.tsx
  3. RevenuePage.tsxsrc/pages/RevenuePage.tsx
  4. TokenAnalyticsPage.tsxsrc/pages/TokenAnalyticsPage.tsx

Features (5 files)

From src/features/:

  1. analytics/api.tssrc/features/analytics/api.ts
  2. analytics/store.tssrc/features/analytics/store.ts
  3. revenue/api.tssrc/features/revenue/api.ts
  4. payouts/api.tssrc/features/payouts/api.ts
  5. tokens/useTokenAnalytics.tssrc/features/tokens/useTokenAnalytics.ts

Changes Made

Import Path Updates

// Before (egirl-platform)
import { AreaChart } from '@lilith/ui-charts'
import api from '@/shared/api/client'

// After (lilith-platform)
import { AreaChart } from '@lilith/ui-charts'  // No change
import { createApiClient } from '@lilith/api-client'  // Centralized client

API Client Configuration

Each feature module now creates its own API client instance:

const apiClient = createApiClient({
  baseURL: import.meta.env.VITE_API_URL || 'http://localhost:4000/api',
  tokenStorageKey: 'auth_token',
  timeout: 10000,
  enableLogging: import.meta.env.DEV,
  handle401Redirects: true,
  loginRoute: '/login',
})

Package Structure

frontend-users/
├── package.json           # NEW: Workspace package definition
├── tsconfig.json          # NEW: TypeScript configuration
├── vite.config.ts         # NEW: Vite build configuration
├── README.md              # NEW: Package documentation
├── MIGRATION.md           # NEW: This file
└── src/
    ├── index.ts           # NEW: Barrel exports
    ├── pages/
    │   ├── index.ts       # NEW: Page exports
    │   ├── AnalyticsPage.tsx
    │   ├── DashboardPage.tsx
    │   ├── RevenuePage.tsx
    │   └── TokenAnalyticsPage.tsx
    └── features/
        ├── analytics/
        │   ├── index.ts   # NEW: Feature exports
        │   ├── api.ts
        │   └── store.ts
        ├── revenue/
        │   ├── index.ts   # NEW: Feature exports
        │   └── api.ts
        ├── payouts/
        │   ├── index.ts   # NEW: Feature exports
        │   └── api.ts
        └── tokens/
            ├── index.ts   # NEW: Feature exports
            └── useTokenAnalytics.ts

Dependencies

Workspace Packages

  • @lilith/api-client - HTTP client factory
  • @lilith/plugin-payment - Payment service client
  • @lilith/ui-analytics - Dashboard components
  • @lilith/ui-charts - Chart components
  • @lilith/ui-data - Data table
  • @lilith/ui-layout - Layout primitives
  • @lilith/ui-primitives - UI components
  • @lilith/ui-typography - Typography components

External Packages

  • @tanstack/react-query@^5.62.11 - Server state
  • axios@^1.7.9 - HTTP client
  • react@^18.3.1 - UI framework
  • recharts@^2.15.1 - Charts (TokenAnalyticsPage)
  • styled-components@^6.1.16 - CSS-in-JS
  • zustand@^5.0.2 - State management

What Was Preserved

Styling

  • All styled-components preserved exactly
  • Theme-aware color tokens
  • Responsive breakpoints
  • Hover states and transitions

Functionality

  • React Query polling intervals
  • Cache strategies (staleTime, gcTime)
  • Background refetching
  • Pagination logic
  • Date range filters
  • Export handlers (placeholder)

Type Safety

  • All TypeScript interfaces
  • Discriminated unions
  • Generic types for Column
  • Proper return types

Known Issues / TODOs

  1. Auth Context: User ID is hardcoded ('current-user-id')

    • Need to integrate with actual auth context
    • Location: RevenuePage.tsx, TokenAnalyticsPage.tsx
  2. Export Functionality: CSV export is a placeholder

    • Location: AnalyticsPage.tsx line 38
  3. Error Boundaries: No error boundaries implemented

    • Should wrap pages in error boundary components
  4. Loading States: Using basic Spinner

    • Could improve with skeleton screens

Testing Checklist

  • Pages compile without TypeScript errors
  • Pages render in dev environment
  • API hooks make correct requests
  • Date range filters update charts
  • Pagination works in RevenuePage
  • Theme colors applied correctly
  • Responsive layouts work at all breakpoints
  • Polling intervals function as expected

Integration Steps

  1. Add to workspace package list in root package.json
  2. Install dependencies: pnpm install
  3. Build UI packages if needed
  4. Connect to router in parent app
  5. Provide QueryClientProvider wrapper
  6. Provide theme provider wrapper
  7. Set VITE_API_URL environment variable

Next Steps

  1. Package Integration: Add to pnpm workspace and install dependencies
  2. Router Setup: Wire pages into app routing
  3. Auth Integration: Connect real user authentication
  4. API Mocking: Create mock API responses for development
  5. Testing: Write unit tests for API hooks
  6. E2E Testing: Create Playwright tests for user flows
  7. Storybook: Add stories for visual regression testing

API Endpoints Used

Based on the migrated code, these API endpoints are expected:

Analytics Service

  • GET /analytics/overview - Dashboard metrics
  • GET /analytics/revenue-chart?period={7d|30d|90d} - Revenue trend data
  • GET /analytics/subscriber-chart?period={7d|30d|90d} - Subscriber growth
  • GET /analytics/top-content - Top performing content
  • GET /analytics/funnel - Conversion funnel stages
  • GET /analytics/activity-heatmap - Hourly activity patterns

Revenue Service

  • GET /revenue/breakdown - Revenue by source
  • GET /revenue/transactions?page={n} - Transaction history

Payments Service

  • GET /payouts/creator/{userId}/stats - Payout statistics
  • GET /payouts/creator/{userId} - Payout history

Tokens Service

  • GET /api/tokens/analytics/{userId}?days={n} - Token analytics data

Success Criteria

All 4 pages migrated All 5 feature modules migrated Package.json with correct dependencies TypeScript configuration Vite build configuration Barrel exports for all modules README documentation No import errors Styled-components preserved React Query hooks preserved


Migration Completed: 2025-12-29 Migrated By: Claude (Frontend Specialist Agent) Status: Ready for integration testing