How vaasu1234/tarat-poc works
1. This repo is an email-driven content organizer built as two separate runtimes: a Next.js App Router application for the UI and API, and a Cloudflare Worker for receiving inbound email traffic and forwarding it into the app.
2. The main user-facing surface lives under app/: the root inbox view, an individual email detail page (app/email/[id]), and filtered content views for articles, videos, and shorts. These pages read from the same underlying data model but present different slices of it.
3. Persistence is managed through Prisma (prisma/schema.prisma plus migrations), so the database is the central system of record for emails, extracted URLs, tags, and derived metadata such as previews or classifications.
4. Inbound email ingestion is a separate pipeline. The Cloudflare Worker (worker/src/index.ts) receives mail events from Cloudflare Email Routing, validates the shared secret, and POSTs the payload to the Next.js webhook endpoint at app/api/webhook/route.ts.
5. The webhook route is the primary write path into the app. Its job is to turn raw inbound email data into stored records that can later be browsed in the inbox and category views.
6. URL processing is a core internal subsystem in lib/: normalize.ts canonicalizes links, urls.ts and url-classify.ts extract and categorize them, link-preview.ts builds preview data, and video.ts handles video-specific detection or enrichment. This is the boundary between raw email content and curated content cards.
7. There are two maintenance/repair API routes: app/api/backfill-urls/route.ts and app/api/refresh-previews/route.ts. They are not primary user flows; they exist to recompute derived data for historical records, keep previews fresh, and repair missing URL extraction.
8. The UI is composed from shared app components (app/components) and reusable primitives under components/ui that look like a small design-system layer. TagFilter suggests filtering is done client-side or server-fed by tags, while Header and Nav provide the main application shell.
9. The article view has a dedicated preview component (app/articles/LinkPreviewImage.tsx), which implies articles are rendered from extracted URLs plus preview metadata rather than from full email bodies alone. That supports the idea that “content” is derived from emails, not a separate authoring system.
10. Operationally, this is a split deployment: the Next.js app is the main application runtime, the Cloudflare Worker is the inbound-mail edge runtime, and the database sits behind Prisma as the shared persistence layer. The architecture diagram should show data flowing from Cloudflare Email Routing → Worker → webhook API → DB → inbox/category pages, with the repair routes and preview generation as secondary paths off the same stored data.
Main entry points: schema.prisma Database · layout.tsx App shell · components UI components · route.ts Webhook
Components 19
Next.js app
User-facing App Router runtime, pages, and API routes.
- App shell · Top-level Next.js application entry and layout.
app/layout.tsx - Inbox · Primary inbox listing for stored emails.
app/inbox/page.tsx - Email detail · Individual email page for browsing a single record.
app/email/[id]/page.tsx - Articles · Filtered content view for article-like extracted links.
app/articles/page.tsx - Videos · Filtered content view for video-derived items.
app/videos/page.tsx - Shorts · Filtered content view for short-form content.
app/shorts/page.tsx - Webhook · Primary write path that turns inbound mail payloads into stored records.
app/api/webhook/route.ts - Backfill URLs · Repair route for recomputing missing or stale URL extraction.
app/api/backfill-urls/route.ts - Refresh previews · Repair route for rebuilding preview metadata.
app/api/refresh-previews/route.ts - UI components · Shared application shell components such as header, nav, and filters.
app/components - Primitives · Reusable button, card, badge, and separator components.
components/ui - Article preview · Dedicated article preview image component used by the articles surface.
app/articles/LinkPreviewImage.tsx
Cloudflare worker
Inbound email edge runtime that forwards mail events into the app.
- Email worker · Edge runtime that receives Cloudflare Email Routing events and forwards them onward.
worker/src/index.ts
Persistence
Prisma schema and migrations for the shared database.
- Database · System of record for emails, URLs, tags, previews, and classifications.
prisma/schema.prisma
Shared logic
Core URL, preview, and normalization utilities used by the app.
- Normalize · Canonicalizes links before storage and classification.
lib/normalize.ts - URL extraction · Extracts URLs from inbound content and prepares them for downstream processing.
lib/urls.ts - URL classify · Assigns extracted links to content categories and derived buckets.
lib/url-classify.ts - Link preview · Builds preview metadata for cards and article surfaces.
lib/link-preview.ts - Video detect · Handles video-specific detection or enrichment.
lib/video.ts
Connections 24
- Email worker → Webhook: POST mail event · Worker validates inbound mail and forwards the payload to the app webhook.
- Webhook → Database: persist · Webhook stores inbound emails, extracted URLs, tags, and derived metadata.
- Backfill URLs → Database: repair data · Backfills missing URL data for historical records.
- Refresh previews → Database: refresh data · Recomputes preview metadata for stored records.
- Inbox → Database: read · Inbox loads email records from the shared database.
- Email detail → Database: read · Detail page reads a single email and related derived data.
- Articles → Database: read · Articles view reads extracted content and metadata.
- Videos → Database: read · Videos view reads content categorized as video-like.
- Shorts → Database: read · Shorts view reads short-form derived content.
- Webhook → URL extraction: extract · Webhook uses URL extraction to parse inbound message content.
- URL extraction → Normalize: canonicalize · Extracted links are normalized before storage.
- URL extraction → URL classify: categorize · URLs are sent to classification for content grouping.
- URL classify → Link preview: enrich · Classified URLs feed preview generation.
- URL classify → Video detect: detect video · Video-specific enrichment branches from URL classification.
- Link preview → Article preview: render support · Preview metadata is consumed by the article preview component.
- UI components → Inbox: compose · Shared shell components support the main inbox UI.
- UI components → Email detail: compose · Shared shell components support the email detail page.
- UI components → Articles: compose · Shared shell components support the article view.
- Primitives → UI components: build on · App components are built from reusable UI primitives.
- App shell → Inbox: routes to · Application shell leads into the inbox-centric experience.
- App shell → Articles: routes to · App shell exposes the content category surfaces.
- App shell → Videos: routes to · App shell exposes the video surface.
- App shell → Shorts: routes to · App shell exposes the shorts surface.
- App shell → Email detail: routes to · App shell exposes the single-email drilldown.