Open Scouts

repository·main·Indexed 23 days ago

https://github.com/firecrawl/open-scouts

An AI-powered monitoring platform for creating automated 'scouts' that continuously search the web for specific information and provide notifications upon discovery. Built with Next.js, Supabase, OpenAI GPT-4, and the Firecrawl API for search and content extraction.

Tokens
8.6K
Snippets
13
Records
42
Agent score
80%

What's inside open-scouts

  1. Overview of the Firecrawl Design System architecture

    main

    The Firecrawl design system uses a modular component architecture organized within the components-new/ directory. It integrates Tailwind CSS for utility-first styling, shadcn/ui (built on Radix UI) for core components, and custom libraries for animations and data visualization.

    Directory Structure

    • components-new/ui/: Core UI primitives including shadcn/, magic/ (animated components), tremor/ (data visualization), and motion/ (animation utilities).
    • components-new/shared/: Reusable application components like icons/, buttons/, cards/, effects/, and layout/ utilities.
    • components-new/app/: Components specific to application routes, such as brand/, pricing/, and (home)/.
    • components-new/providers/: Context providers and theme management logic.
    components-new/
    ├── ui/                    # Core UI components
    │   ├── shadcn/           # shadcn/ui components
    │   ├── magic/            # Magic UI animated components
    │   ├── tremor/           # Tremor data visualization components
    │   └── motion/           # Motion and animation utilities
    ├── shared/               # Shared application components
    │   ├── icons/            # Icon components and brand assets
    │   ├── buttons/          # Custom button components
    │   ├── cards/            # Card components
    │   ├── effects/          # Visual effects and animations
    │   ├── layout/           # Layout utilities
    │   └── ui/               # Shared UI utilities
    ├── app/                  # Application-specific components
    │   ├── brand/            # Brand-related components
    │   ├── pricing/          # Pricing page components
    │   └── (home)/           # Home page components
    └── providers/            # Context providers and theme management
  2. Understand the PostHog tracking architecture

    main

    PostHog tracking in Open Scouts is distributed across the entire stack to capture both UI interactions and background system processes:

    1. Browser (posthog-js): Handles user identification, page views, UI interactions, and client-side events.
    2. Next.js Server (posthog-node): Captures server-side events and API route tracking.
    3. Supabase Edge Functions: Captures the execution lifecycle of scouts, email notification tracking, and performance metrics via an HTTP Capture API.
  3. Understand the Firecrawl Custom Sizing System

    main

    🚨 Critical: Custom Sizing System

    Unlike standard Tailwind which uses rem units, the Firecrawl design system uses a custom sizing system where numeric values equal literal pixels.

    Key Differences

    ClassStandard TailwindFirecrawl System
    w-30.75rem (12px)3px
    h-82rem (32px)8px
    size-41rem (16px)4px
    p-123rem (48px)12px
    gap-246rem (96px)24px

    Usage Guidelines

    Use for Spacing (padding, margin, gap):

    <div className="p-24 gap-16 mb-8"> {/* 24px padding, 16px gap, 8px margin-bottom */} ```
    
    ✅ **Use for Border Radius** (pixel-based):
    ```tsx
    <div className="rounded-8"> {/* 8px border radius */} ```
    
    ✅ **Use for Border Width** (explicit pixels):
    ```tsx
    <div className="border-1"> {/* 1px border */} ```
    
    ❌ **AVOID for Component Heights/Widths** (unless using large pixel values):
    ```tsx
    {/* WRONG - Button will be 9px tall! */}
    <Button className="h-9" />
    
    {/* WRONG - Icon will be 4px × 4px! */}
    <Icon className="size-4" />

    Working with Components

    If a component (like an Icon or Button) appears too small because it's using h-* or size-* utilities, use explicit pixel values or the style prop:

    {/* Instead of size-4 (4px), use explicit values */}
    <Icon className="w-16 h-16" />  {/* 16px × 16px icon */}
    
    {/* Or use style prop for non-spacing dimensions */}
    <Icon style={{ width: '1rem', height: '1rem' }} />  {/* 16px × 16px */}
    const sizes = Array.from({ length: 1000 }, (_, i) => i).reduce(
      (acc, curr) => {
        acc[curr] = `${curr}px`;  // 3 = "3px", 8 = "8px", 100 = "100px"
        return acc;
      },
      { /* fractional percentages */ }
    );
  4. Security and Data Isolation

    main

    Open Scouts implements several layers of security to protect user data:

    • Row Level Security (RLS): All database tables use RLS policies to ensure users only access their own data.
    • User Isolation: Scouts, messages, and executions are strictly tied to authenticated users.
    • Secure Auth: OAuth tokens and sessions are managed via Supabase Auth.
    • Privileged Access: Server-side operations (cron jobs, edge functions) use a service role for necessary privileged access.
    • API Key Security: Firecrawl API keys (via partner integration) are stored server-side in user_preferences and are never exposed to the client.
  5. How the Scout System works

    main

    A 'Scout' is a monitoring agent that tracks specific queries or topics. The lifecycle of a scout includes:

    1. Definition: Define a monitoring goal (e.g., "Scout for any AI news").
    2. AI Configuration: The system automatically sets up search queries and strategies using OpenAI GPT-4.
    3. Scheduling: Set a frequency (hourly, every 3 days, weekly).
    4. Execution: A dispatcher checks every minute and triggers due scouts individually.
    5. Summarization: Successful executions generate a one-sentence summary with semantic embeddings.
    6. Notification: If an email is configured in Settings, users receive alerts when new results are found.
    7. Manual Override: You can trigger an immediate execution by clicking the "Run Now" button on any scout page.
  6. Architecture of Open Scouts

    main

    Open Scouts is built on a modern stack designed for scalability and real-time updates:

    • Frontend: Next.js with Supabase Realtime.
    • Database: PostgreSQL (Supabase) utilizing pg_cron for scheduling and pgvector for semantic search.
    • Authentication: Supabase Auth (Email/Password + Google OAuth).
    • AI Agent: OpenAI GPT-4 with function calling (search & scrape tools).
    • Edge Function: Deno-based serverless functions that orchestrate agent execution.
    • Web Scraping: Firecrawl API for search and content extraction.

    Scalable Dispatcher Pattern

    To handle thousands of scouts, the system uses a dispatcher pattern:

    1. pg_cron triggers dispatch_due_scouts() every minute.
    2. The function identifies due scouts and uses pg_net to fire individual HTTP POST requests.
    3. Each request triggers an isolated Edge Function invocation (256MB memory, 400s timeout) for a specific scout.
    4. A separate cron job cleans up stuck executions every 5 minutes.
  7. Understand the Firecrawl Component Architecture

    main

    The UI layer is organized into three distinct tiers based on the component's purpose and complexity:

    1. UI Components (components-new/ui/): Low-level, accessible building blocks.

      • shadcn/ui: Standard form controls, layouts, navigation, feedback, and data components.
      • Magic UI: Animated and interactive components like animated-shiny-text, dot-pattern, and ripple.
      • Tremor: Data visualization components including various charts (LineChart, BarChart, etc.) and dashboard controls.
    2. Shared Components (components-new/shared/): Reusable brand and utility elements used across the application.

      • Icons: Organized exports for brand symbols and utility icons (e.g., GitHub, Check).
      • Buttons: Custom brand-styled buttons like SlateButton, HeatButton, and FireActionLink.
      • Layout & Effects: Specialized components for animations (flame/, animated-beam) and layout (curvy-rect, unified-blur-overlay).
    3. Application Components (components-new/app/): High-level, page-specific components, such as those in app/brand/ used for brand presentation (e.g., BrandHero).

  8. Understand the User Authentication Flow

    main

    Open Scouts uses a gated authentication model to ensure user isolation. The flow is as follows:

    1. Public Access: Users can browse the landing page without signing in.
    2. Triggered Authentication: Attempting to 'Create Scout' (by entering a query) prompts the user to sign in.
    3. Authentication Methods: Supports email/password or Google OAuth via Supabase Auth.
    4. Seamless Continuation: After successful authentication, the scout creation process continues automatically.
    5. Data Isolation: Once authenticated, users can only see and manage their own scouts, messages, and executions due to Row Level Security (RLS).
  9. Understand the Firecrawl Color System

    main

    The color system is defined in colors.json and styles/colors.json and is designed for consistent light and dark mode theming. Colors are mapped to CSS custom properties and can be used via Tailwind CSS classes.

    Color Categories

    Heat Colors (Brand)

    Primary brand color (#fa5d19) with opacity variants:

    • heat-4 to heat-100 (4% to 100% opacity).

    Accent Colors (Semantic)

    • accent-black: Dark neutral (#262626)
    • accent-white: Pure white (#ffffff)
    • accent-amethyst: Purple (#9061ff)
    • accent-bluetron: Blue (#2a6dfb)
    • accent-crimson: Red (#eb3424)
    • accent-forest: Green (#42c366)
    • accent-honey: Yellow (#ecb730)

    Alpha Variants (Layering)

    • black-alpha-1 to black-alpha-88: Black overlays (1% to 88% opacity).
    • white-alpha-56 and white-alpha-72: White overlays (56% and 72% opacity).

    UI Colors (Interface)

    • Borders: border-faint, border-muted, border-loud.
    • Illustrations: illustrations-faint, illustrations-muted, illustrations-default.
    • Backgrounds: background-lighter, background-base.
  10. Configure PostHog integration

    main

    To enable PostHog analytics in Open Scouts, you must set the following environment variables. Note that the PostHog key must be available to both the Next.js frontend and Supabase edge functions to ensure both client-side and server-side tracking work correctly.

    NEXT_PUBLIC_POSTHOG_KEY=your_project_api_key
    NEXT_PUBLIC_POSTHOG_HOST=https://us.posthog.com  # Optional
  11. Configure Supabase Extensions for Open Scouts

    main

    Open Scouts requires specific PostgreSQL extensions to handle scheduled jobs, HTTP requests, and semantic search. Enable these in your Supabase Dashboard under Database → Extensions:

    • pg_cron: For running scheduled scout jobs.
    • pg_net: For making HTTP requests from the database.
    • vector: For AI-powered semantic search on execution summaries.
    • supabase_vault: For secure credential storage (usually enabled by default).

    Note: The setup:db script will check for these extensions and prompt you if they are missing.

  12. Set up SuisseIntl font files for the design system

    main

    To ensure the typography matches the marketing design system, you must manually copy the SuisseIntl font files into the project's public directory.

    1. Create the target directory: public/fonts/SuisseIntl/.
    2. Copy the following files from the marketing app source to the new directory:
      • 400.woff2
      • 450.woff2
      • 500.woff2
      • 600.woff2
      • 700.woff2