System Overview
SENTi-radar is a serverless, event-driven sentiment analysis platform built on:- Frontend: React 18 + TypeScript + Vite + shadcn-ui
- Backend: Supabase (Postgres + Edge Functions)
- Data Sources: X (Twitter), Reddit, YouTube, Google News
- AI/ML: Gemini API + keyword-based fallback
- State Management: TanStack React Query
- Visualization: Recharts + Framer Motion
The architecture follows a tiered fallback strategy: Scrape.do → Parallel.ai → YouTube → Algorithmic generation, ensuring the system always returns data even when APIs fail.
High-Level Data Flow
Component Interaction Diagram
Core Components
1. Frontend Architecture
Main Dashboard (src/pages/Index.tsx)
The central orchestrator that manages search, topic selection, and real-time updates:
src/pages/Index.tsx
- Trigger analysis via
useAnalyzeTopicmutation - Manage selected topic state
- Coordinate sidebar and detail view
- Handle real-time refetching after analysis
Real-Time Data Hook (src/hooks/useRealtimeData.ts)
Manages all backend communication and real-time subscriptions:
src/hooks/useRealtimeData.ts
- React Query for caching and invalidation
- Real-time WebSocket subscriptions for live updates
- Automatic refetching on database changes
- Graceful degradation to mock data when backend fails
Topic Detail Component (src/components/TopicDetail.tsx)
Orchestrates data fetching and emotion analysis for a single topic:
src/components/TopicDetail.tsx
- Parallel data fetching from X, Reddit, YouTube, Google News
- Real-time emotion scoring from scraped content
- AI summary streaming with 3-tier fallback (Gemini → Groq → local)
- Source status indicators for transparency
2. Backend Architecture
Scrape.do Provider (src/services/scrapeDoProvider.ts)
Universal scraping provider for X and Reddit:
src/services/scrapeDoProvider.ts
- Abstraction: Single API for multiple platforms
- Extensibility: Add new sources by implementing
fetchXXXPosts() - Resilience: Returns structured
ScrapeDoResultwith status and error info - Performance: Parallel fetching via
fetchAllScrapeDoSources()
Edge Function: fetch-twitter (supabase/functions/fetch-twitter/index.ts)
Serverless function that fetches posts from X and Reddit:
supabase/functions/fetch-twitter/index.ts
- Scrape.do (X + Reddit) — primary source
- Parallel.ai — web search fallback
- YouTube — video content fallback
- Algorithmic — template-based generation
Edge Function: analyze-sentiment (supabase/functions/analyze-sentiment/index.ts)
Runs emotion analysis on fetched posts:
supabase/functions/analyze-sentiment/index.ts
- Fetch unanalyzed posts from database
- Batch analyze with Gemini API (or keyword fallback)
- Update posts with sentiment + emotion scores
- Compute aggregated stats (emotion breakdown, crisis level)
- Generate AI summary with context-aware prompts
- Store results in
topic_statstable
3. Database Schema
Core Tables
Data Flow Example
Here’s a complete trace of analyzing “climate change”:Extensibility
Adding a New Data Source
To add LinkedIn or Hacker News:- Create fetcher in
scrapeDoProvider.ts:
src/services/scrapeDoProvider.ts
- Add to
fetchAllScrapeDoSources:
- Update edge function:
supabase/functions/fetch-twitter/index.ts
Custom Emotion Models
Replace keyword-based scoring with a fine-tuned model:Performance Optimizations
Caching Strategy
- React Query cache: 5-minute stale time for topics, 30-second for live feed
- Edge function caching: Cache Scrape.do results for 60 seconds per query
- Database indexes: Composite indexes on
(topic_id, fetched_at)for fast queries
Parallel Processing
Database Query Optimization
Security Considerations
Production Security Checklist
- Move
VITE_SCRAPE_TOKENto Supabase secrets - Call Scrape.do only from edge functions (not frontend)
- Enable Row-Level Security (RLS) on all tables
- Implement rate limiting on edge functions
- Add CORS restrictions to Supabase API
- Use service role key only in edge functions
- Sanitize user input in search queries
- Validate Scrape.do responses before parsing
Example RLS Policy
Next Steps
Quickstart Guide
Get SENTi-radar running locally in 5 minutes
Edge Functions API
Explore edge function endpoints and request/response schemas
Development Guide
Contributing guidelines, testing, and local Supabase setup
Deployment
Deploy to production with Vercel and Supabase