📊 Dashboard Data Integration Plan
Overview
Transform the mobile dashboard from mock data to real data using existing database tables and patterns established in the web app.
Database Schema (Available Tables)
- ✅
rec_swipes- User swipe interactions - ✅
recommendations_with_movies- View with recommendations + movie data - ✅
movies- Movie metadata - ✅
gang_members- User profiles
✅ IMPLEMENTED - API-Centralized Approach
Architecture Decision:
Instead of direct database queries from clients, we implemented a centralized API approach:
- Backend API Route:
/api/dashboard- Handles all database queries and business logic - Mobile Hook:
useDashboardData.ts- Calls API endpoint with auth token - Web Hook:
useDashboardData.ts(ready for future dashboard implementation)
Benefits:
- 🔒 Security: No direct database access from clients
- 🔄 Consistency: Same data source for web and mobile
- 📈 Performance: Optimized queries in single location
- 🛠️ Maintainability: Business logic centralized in backend
Phase 1: Core Recommendation Metrics 🎯
✅ COMPLETED - API-based implementation
Implementation Tasks:
- Create
/api/dashboardroute in backend - Update
useDashboardDatahook in RN app to use API - Create
useDashboardDatahook for web app (future-ready) - Remove direct Supabase queries from mobile client
- Add proper authentication and error handling
Current Mock Stats → Real Data Mapping:
| Mock Stat | Real Data Source | Description |
|---|---|---|
moviesRated: 12 | rec_swipes count | Total swipes (liked + disliked) |
newRecommendations: 3 | recommendations_with_movies count | Total saved recommendations |
matchRate: 85 | rec_swipes like ratio | % of liked swipes vs total swipes |
Query Keys Strategy:
// Follow existing pattern, ensure cache invalidation
const queryKeys = {
dashboard: {
stats: (userId: string) => ["dashboard", "stats", userId],
recommendations: (userId: string) => ["dashboard", "recommendations", userId],
},
// Ensure these align with existing recommendation queries for smart invalidation
recommendations: {
list: (userId: string) => ["recommendations", "list", userId],
},
}
Phase 2: Enhanced Recent Recommendations 📽️
Priority: Medium - Better recommendation context
Current Mock → Real Data:
- Use existing
recommendations_with_moviesview (like web app) - Include real movie data (title, year, rating, poster)
- Add swipe status (from
rec_swipestable) - Show recommendation freshness
Implementation Tasks:
- Extend
RecentRecommendationinterface to match web app - Query
recommendations_with_movieswith limit (3-5 items) - Join with
rec_swipesto get swipe status - Add "View All" navigation to full recommendations screen
- Handle empty states for new users
Phase 3: Behavioral Insights (Future) 📈
Priority: Low - Advanced analytics
Potential Additional Metrics:
- Recent swipe sessions
- Genre preference breakdown
- Weekly activity trends
- Recommendation success rate
- Time-based patterns
Technical Implementation Details
Environment & Patterns:
- API Base URL: Use ENV vars (follow existing hook patterns)
- Authentication: Use Zustand session (
session.user.id) - Caching: React Query with smart staleness
- Error Handling: Follow existing hook error patterns
Query Invalidation Strategy:
// When new recommendations are created, invalidate dashboard cache
queryClient.invalidateQueries(["dashboard", "stats"])
queryClient.invalidateQueries(["dashboard", "recommendations"])
queryClient.invalidateQueries(["recommendations"]) // Existing web pattern
Data Flow:
- Dashboard loads →
useDashboardDatahook - Hook calls Supabase directly (like web app)
- Queries
rec_swipesandrecommendations_with_movies - Processes data and returns formatted stats
- UI updates with real data
Success Metrics:
- Dashboard shows real user swipe counts
- Recommendation counts match actual saved recommendations
- Like rate accurately reflects user preferences
- Recent recommendations show actual movie data
- Performance maintains good UX (loading states, caching)
Implementation Order:
- 📋 Create plan document (this file)
- 🏗️ Set up real data hooks in RN app
- 🔌 Connect to Supabase (following web patterns)
- 📊 Replace mock stats with real calculations
- 🎬 Enhance recent recommendations with real data
- ✅ Test and validate data accuracy
- 🚀 Deploy and monitor
Next Steps: Start with Phase 1 implementation - create the real data hooks and connect to Supabase.