Skip to main content

Radar Frontend Structure

Location: app/radar/ Purpose: User interface for viewing AI-generated insights and managing radar schedules.

User Experience Flow

Page Structure (page.tsx)

The main Radar page is a React component with several key sections:

1. Landing Screen

  • Shows first on every visit (no persistence)
  • Explains Radar feature with visual examples
  • User must click “Enter Radar” to access main interface
  • Component: <RadarLanding />

2. Account Validation

  • Checks if user has connected accounts (Plaid, SnapTrade, manual, crypto)
  • Blocks access if no accounts found
  • Shows alert with “Connect Account” button
  • Opens account connection dialog when clicked

3. Filter Tabs

Three filter options at the top:
  • All - Shows SilviaFeed with all scenarios and radar results
  • Bookmarked - Shows only bookmarked items from SilviaFeed
  • Alerts - Shows RadarFeed with scheduled radar results only

4. Main Feed (Left/Center)

Two different feed components based on active filter: SilviaFeed (for “All” and “Bookmarked”):
  • Displays AI-generated scenarios from the scenarios feature
  • Shows radar results mixed with scenario cards
  • Supports bookmarking individual items
  • Hot loading strategy: loads from DB first, generates if needed
  • Component: <SilviaFeed />
RadarFeed (for “Alerts”):
  • Displays only scheduled radar results
  • Shows results grouped by radar schedule
  • No bookmarking functionality
  • Component: <RadarFeed />

5. Sidebar (Right)

Sticky sidebar containing:
  • Schedule List - Active/inactive radar schedules with toggle and delete
  • Create Form - Input for new prompt, frequency selector (Daily/Weekly/Monthly)
  • Day Selection - For weekly schedules (Mon, Tue, Wed, etc.)
  • Day of Month - For monthly schedules (1-31)
  • Create Button - Triggers schedule creation
  • Component: <RadarSidebar />

Custom Hooks (hooks.ts)

1. useRadarSchedules

Purpose: Manages radar schedule CRUD operations What it does:
  • Fetches list of user’s schedules from API on mount
  • Creates new schedules with prompt and frequency config
  • Toggles schedule enabled/disabled status
  • Deletes schedules with confirmation dialog
  • Tracks loading and creating states
  • Sends analytics events for all actions
Returns:

2. useRadarResults

Purpose: Manages radar execution results and polling What it does:
  • Fetches results for all schedules from API
  • Polls for status updates every 5 seconds for processing results
  • Stores results mapped by scheduleId
  • Triggers manual radar execution (“Run Now” button)
  • Cleans up polling intervals on unmount
  • Updates results when processing completes
Polling Logic:
  1. When result status is “PROCESSING”, starts 5-second interval
  2. Checks status endpoint repeatedly
  3. When status becomes “COMPLETED” or “FAILED”, stops polling
  4. Automatically fetches full results after completion
Returns:

3. useRadarForm

Purpose: Manages the create schedule form state What it does:
  • Stores form field values (prompt, frequency, days, time)
  • Handles day selection for weekly schedules (toggle on/off)
  • Builds schedule config object from form state
  • Resets form after successful creation
  • Manages form expanded/collapsed state
Returns:

Feed & Simulation System

How the Feed Works

The Silvia Feed uses a “hot loading” strategy that prioritizes showing content immediately while generating fresh insights in the background.

Loading Strategy: 3 Phases

Phase 1: Initial Generation (On Mount)
Phase 2: Database Loading (Progressive)
Phase 3: Infinite Scroll

Simulation API (/api/radar/silvia-simulation)

What it does:
  1. Analyzes user’s portfolio using internal chat API
  2. Generates insights about:
    • Portfolio composition changes
    • Risk exposure shifts
    • Market trends affecting holdings
    • Opportunities or warnings
  3. Stores results in silvia_feed_posts table
  4. Returns immediately (processing happens in background)
Example generated insights:
  • “Your tech allocation increased to 42% - consider rebalancing”
  • “Bitcoin moved 8% today, affecting 15% of your portfolio”
  • “Your portfolio volatility is lower than the S&P 500”
Parameters:

Post Lifecycle

Mixing Scenarios into Feed

Posts and scenarios are interleaved for variety:
Rules:
  • Only completed scenarios are shown
  • Scenarios must have a response (not failed/processing)
  • Sorted by most recent first
  • Only mixed in “All” filter (not in “Bookmarked”)

Filtering System

All Tab:
  • Shows ALL posts (both regular insights and scenarios)
  • Mixed feed with 4:1 ratio (4 posts → 1 scenario)
  • Infinite scroll loads both types
Bookmarked Tab:
  • Shows only posts user has bookmarked
  • Filter applied at database level
  • Still uses same loading pattern (3 → 5 → 5)
  • No scenarios mixed in
Alerts Tab:
  • Switches to RadarFeed component entirely
  • Shows only scheduled radar results
  • Different data source (DynamoDB, not Supabase)

Component Details

silvia-feed.tsx

Purpose: Main feed showing scenarios and radar results together State Management:
Key Functions:
  1. generateInitialPosts() - Creates fresh content on mount
  2. loadMore() - Fetches posts from database
  3. Intersection Observer - Triggers auto-loading
Data Flow:

radar-feed.tsx

Purpose: Feed showing only scheduled radar results Features:
  • Groups results by schedule type
  • Shows timestamp and status
  • Displays AI-generated insights
  • No bookmarking (these are alerts/notifications)

radar-sidebar.tsx

Purpose: Schedule management and creation form Contains:
  • List of existing schedules with toggle switches
  • “Run Now” button per schedule
  • Delete button per schedule
  • Create new schedule form with:
    • Prompt input textarea
    • Frequency selector (Daily/Weekly/Monthly)
    • Day picker for weekly
    • Day of month for monthly
    • Time picker (defaults to 6:00 UTC)

radar-landing.tsx

Purpose: Welcome screen shown on first visit Features:
  • Explains what Radar does
  • Shows example radar results
  • Large “Enter Radar” button
  • Appears every time user visits /radar (no persistence)

scenario-card.tsx

Purpose: Individual card for displaying a scenario or radar result Features:
  • Shows title and summary
  • Displays timestamp
  • Bookmark button
  • Click to expand full analysis
  • Shows status badge (completed/processing)

API Communication (utils.ts)

The frontend communicates with the backend via REST API:
Headers sent with every request:
  • X-User-Id: {clerkId} - User authentication
  • Content-Type: application/json

Data Flow Example: Creating a Schedule

Data Flow Example: Viewing Results

State Management

No global state management - uses React hooks only:
  • useState for component-local state (filters, dialogs)
  • Custom hooks for data fetching and API calls
  • useEffect for side effects (loading data, polling)
  • useRef for polling interval tracking

Analytics Tracking

PostHog events tracked:

Error Handling

  • No accounts: Shows alert banner with “Connect Account” button
  • API failures: Logged to console, silent to user (schedules/results remain)
  • Schedule deletion: Shows browser confirm() dialog before deleting
  • Network errors: Each hook handles errors independently, doesn’t crash app

Future Enhancements

  • WebSocket for real-time result updates (replace polling)
  • Push notifications when radar completes
  • Schedule templates (pre-built prompts)
  • Result history view (paginated)
  • Export results to PDF
  • Share results via link