Skip to content

Commit 4bb8e67

Browse files
committed
Added patterns section
1 parent ebe918e commit 4bb8e67

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

docs/guides/example-projects/smart-spreadsheet.mdx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import RealtimeLearnMore from "/snippets/realtime-learn-more.mdx";
88

99
## Overview
1010

11-
Smart Spreadsheet is an AI-powered tool that enriches company data on demand. Input a company name or website URL and get verified information including industry, headcount, and funding details; each with source attribution. Results stream to the frontend in real-time as they're processed.
11+
Smart Spreadsheet is an AI-powered tool that enriches company data on demand. Input a company name or website URL and get verified information including industry, headcount, and funding details; each with source attribution. Results appear in the frontend in real-time as each task completes.
1212

1313
- A [Next.js](https://nextjs.org/) app with [Trigger.dev](https://trigger.dev/) for background tasks
1414
- [Exa](https://exa.ai/) – an AI-native search engine that returns clean, structured content ready for LLM extraction
1515
- [Claude](https://anthropic.com/) via the [Vercel AI SDK](https://sdk.vercel.ai/) for data extraction
1616
- [Supabase](https://supabase.com/) PostgreSQL database for persistence
17-
- Trigger.dev [Realtime](/realtime/overview) to stream updates to the frontend
17+
- Trigger.dev [Realtime](/realtime/overview) for live updates to the frontend
1818

1919
## Video
2020

@@ -42,16 +42,43 @@ The enrichment workflow:
4242
1. **Trigger enrichment** – User enters a company name or URL in the spreadsheet UI
4343
2. **Parallel data gathering** – Four subtasks run concurrently to fetch basic info, industry, employee count, and funding details
4444
3. **AI extraction** – Each subtask uses Exa search + Claude to extract structured data with source URLs
45-
4. **Real-time updates** – Results stream back to the frontend as each subtask completes
45+
4. **Real-time updates** – Results appear in the frontend as each subtask completes
4646
5. **Persist results** – Enriched data is saved to Supabase with source attribution
4747

4848
## Features
4949

5050
- **Parallel processing** – All four enrichment categories run simultaneously using [batch.triggerByTaskAndWait](/triggering#batch-trigger-by-task-and-wait)
5151
- **Source attribution** – Every data point includes the URL it was extracted from
52-
- **Real-time streaming** – Results appear in the UI as they're processed using [Realtime](/realtime/overview)
52+
- **Live updates** – Results appear in the UI as each task completes using [Realtime](/realtime/overview)
5353
- **Structured extraction** – Zod schemas ensure consistent data output from Claude
5454

55+
## Key code patterns
56+
57+
### Parallel task execution
58+
59+
The main task triggers all four enrichment subtasks simultaneously using `batch.triggerByTaskAndWait`:
60+
61+
```ts src/trigger/enrich-company.ts
62+
const { runs } = await batch.triggerByTaskAndWait([
63+
{ task: getBasicInfo, payload: { companyName, companyUrl } },
64+
{ task: getIndustry, payload: { companyName, companyUrl } },
65+
{ task: getEmployeeCount, payload: { companyName, companyUrl } },
66+
{ task: getFundingRound, payload: { companyName, companyUrl } },
67+
]);
68+
```
69+
70+
### Live updates from child tasks
71+
72+
Each subtask uses `metadata.parent.set()` to update the parent's metadata as soon as data is extracted:
73+
74+
```ts src/trigger/get-basic-info.ts
75+
// After Claude extracts the data, update the parent task's metadata
76+
metadata.parent.set("website", object.website);
77+
metadata.parent.set("description", object.description);
78+
```
79+
80+
The frontend subscribes to these metadata updates using [Realtime](/realtime/overview), so users see each field populate as it's discovered.
81+
5582
## Relevant code
5683

5784
| File | Description |

0 commit comments

Comments
 (0)