Skip to content

Shareable Search Links: Viral loop infrastructure #172

Description

@DevanshuNEU

Shareable Search Links: Viral Loop Infrastructure

Parent Epic: #166
Depends on: #169 (Search Results), #173 (Anonymous Sessions)

The Viral Mechanic

Every search result should be shareable. When someone finds something useful, they should be able to share it with a teammate, and that teammate should see the exact same results without needing an account.

This is how developer tools go viral. Loom did it with video links. Calendly did it with booking links. We do it with search links.

URL Structure

Short, memorable, shareable:

codeintel.dev/s/abc123

Expands to:

codeintel.dev/search?repo=flask&q=authentication+middleware&results=847-858,1203-1210

The short link stores:

  • Repository reference
  • Search query
  • Specific result positions (optional, for "share this result")

Share Flow

Share Entire Search

  1. User runs a search
  2. Clicks "Share" button in header
  3. Short link is generated and copied to clipboard
  4. Toast: "Link copied. Anyone can view these results."

Share Specific Result

  1. User hovers over a result
  2. Click share icon on that result
  3. Short link includes that specific result highlighted
  4. Recipient lands with that result scrolled into view and highlighted

Database Schema

CREATE TABLE shared_searches (
  id VARCHAR(12) PRIMARY KEY,      -- Short ID (abc123)
  repo_id VARCHAR(100) NOT NULL,
  query TEXT NOT NULL,
  result_context JSONB,            -- Optional: specific results to highlight
  created_at TIMESTAMP DEFAULT NOW(),
  created_by UUID,                 -- NULL for anonymous users
  view_count INT DEFAULT 0,
  expires_at TIMESTAMP             -- Optional expiration
);

API Endpoints

Create Share Link

POST /api/v2/share
{
  "repo_id": "flask",
  "query": "authentication middleware",
  "highlight_results": [
    { "file": "src/flask/app.py", "lines": [847, 858] }
  ]
}

Response:
{
  "short_id": "abc123",
  "url": "https://codeintel.dev/s/abc123",
  "expires_at": null
}

Resolve Share Link

GET /api/v2/share/abc123

Response:
{
  "repo_id": "flask",
  "query": "authentication middleware",
  "highlight_results": [...],
  "created_at": "2026-01-06T...",
  "view_count": 42
}

Landing Experience for Shared Links

When someone clicks a shared link:

  1. Page loads with the search already executed
  2. Results visible immediately (no signup)
  3. Highlighted result is scrolled into view
  4. Subtle banner: "Shared by a CodeIntel user. Try your own search."
  5. Full functionality available (Explain, Copy, etc.)

Share UI Components

Header Share Button

[Share Search]  <- Always visible when results exist

Per-Result Share

[Explain] [Copy] [Share] [GitHub]
                   ^

Copied Toast

┌─────────────────────────────────┐
│  Link copied to clipboard       │
│  codeintel.dev/s/abc123        │
└─────────────────────────────────┘

Share Modal (Optional Enhancement)

┌─────────────────────────────────────────┐
│  Share this search                      │
│                                         │
│  [codeintel.dev/s/abc123    ] [Copy]   │
│                                         │
│  [Twitter] [Slack] [Email]              │
│                                         │
│  Anyone with this link can view         │
│  the search results.                    │
└─────────────────────────────────────────┘

Social Sharing

Pre-formatted messages for each platform:

Twitter/X:

Found this useful code pattern in Flask: [search query]
[link]

Slack:

[link]
^ Check out this code I found - [search query] in [repo]

Analytics

Track:

  • Share link created (with repo, query length)
  • Share link clicked (with referrer)
  • Share link converted (viewer signs up)

This tells us which queries are most share-worthy and helps optimize the viral loop.

Implementation Tasks

  • Create database table for shared searches
  • Create POST /api/v2/share endpoint
  • Create GET /api/v2/share/:id endpoint
  • Create components/search/ShareButton.tsx
  • Create components/ui/ShareModal.tsx (optional)
  • Create /s/[id] page route
  • Add copy-to-clipboard functionality
  • Add social share links
  • Add view count tracking
  • Add analytics events

Acceptance Criteria

  • Share button visible on search results
  • Clicking generates short link and copies to clipboard
  • Short link resolves to full search experience
  • No account required to view shared search
  • Highlighted result scrolls into view
  • View count increments on each visit
  • Works on mobile

Rate Limiting

Anonymous users: 20 share links per hour
Authenticated users: Unlimited

This prevents abuse while allowing legitimate sharing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions