๐๏ธSystem Architecture
@divz.mysterious ยท Eco Resin ยท Crochet ยท Handmade Decor ยท Slow Crafting
Frontend
Backend (API Layer)
Data Layer
Data Flow Pipeline
User authenticates with each platform via OAuth 2.0 flow
Encrypted tokens saved to Supabase with expiry tracking
Scheduled jobs pull analytics from each platform API
Normalized data stored as snapshots and post records
Compute signals, patterns, trends from historical data
Feed processed data to LLM for recommendations
Real-time rendered via Supabase subscriptions
Database Schema
id (uuid PK), email, name, avatar_url, created_at, updated_at
id, user_id (FK), platform (enum), access_token (encrypted), refresh_token (encrypted), scopes, token_expires_at, platform_user_id, connected_at
id, user_id (FK), platform, followers, reach, engagement_rate, saves, shares, watch_time_hrs, snapshot_date
id, user_id (FK), platform, platform_post_id, title, type (reel/short/pin/video), views, saves, shares, comments, completion_rate, posted_at, fetched_at
id, topic, platform, category, growth_rate, heat_score, search_volume, detected_at, expires_at
id, user_id (FK), concept, hook, video_length, shot_list (jsonb), editing_style, music, caption, hashtags (text[]), virality_score, generated_at
id, user_id (FK), insight, impact, category, data_points, detected_at
id, handle, platform, followers, growth_rate, niche, format_description, last_checked
API Endpoints
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/auth/[platform] | Initiate OAuth redirect for given platform | Public |
| GET | /api/auth/callback | Handle OAuth callback, exchange code for tokens | Public |
| POST | /api/auth/refresh | Refresh expired platform tokens | Cron |
| GET | /api/analytics/overview | Cross-platform summary metrics | Auth |
| GET | /api/analytics/growth | Historical follower growth data | Auth |
| GET | /api/analytics/posts | Post-level performance with sorting/filters | Auth |
| GET | /api/analytics/signals | Algorithm signal scores and benchmarks | Auth |
| GET | /api/trends/topics | Current trending topics with heat scores | Auth |
| GET | /api/trends/keywords | Rising keywords with search volume | Auth |
| POST | /api/ai/recommend | Generate AI content recommendations | Auth |
| POST | /api/ai/patterns | Run viral pattern detection analysis | Auth |
| GET | /api/creators/trending | List trending creators in niche | Auth |
| GET | /api/opportunities | Content gap analysis results | Auth |
| POST | /api/cron/fetch-analytics | Scheduled analytics data fetch | Cron |
| POST | /api/cron/detect-trends | Scheduled trend detection pipeline | Cron |
AI Analysis Pipeline
Trend Detection Engine
Aggregate search data from Pinterest Trends, YouTube Search Suggest, IG Explore
Calculate velocity scores: growth rate over 7/14/30 day windows
Cross-reference with creator's niche keywords for relevance scoring
Rank by heat score (velocity ร relevance ร recency)
Content Recommendation Engine
Input: top trends + creator analytics + algorithm signals + top posts
LLM prompt: generate content concepts optimized for creator's strengths
Score each concept: virality probability based on historical pattern match
Output: ranked list with full production briefs (hook, shots, caption, tags)
Viral Pattern Detector
Analyze top 50 posts: extract duration, hook timing, camera angle, audio type
Statistical correlation: which attributes correlate with high save/share rates
Generate natural language insights with confidence intervals
Refresh weekly as new content is published
Opportunity Gap Analyzer
Demand signal: keyword search volume + engagement on related content
Supply signal: count of active creators + content frequency in niche
Gap score: demand / supply ratio normalized to 0-100
Suggest specific content ideas to fill each gap