# vaasu1234/tarat-poc architecture

> Architecture diagram of the GitHub repository vaasu1234/tarat-poc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vaasu1234/tarat-poc
- Repository: https://github.com/vaasu1234/tarat-poc

## Overview

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: [`prisma/schema.prisma`](https://github.com/vaasu1234/tarat-poc/blob/main/prisma/schema.prisma) (Database), [`app/layout.tsx`](https://github.com/vaasu1234/tarat-poc/blob/main/app/layout.tsx) (App shell), [`app/components`](https://github.com/vaasu1234/tarat-poc/tree/main/app/components) (UI components), [`app/api/webhook/route.ts`](https://github.com/vaasu1234/tarat-poc/blob/main/app/api/webhook/route.ts) (Webhook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["Next.js app"]
  node_node_root["App shell<br/>next app<br/>[layout.tsx]"]
  node_node_inbox["Inbox<br/>view<br/>[page.tsx]"]
  node_node_email_detail["Email detail<br/>view<br/>[page.tsx]"]
  node_node_articles["Articles<br/>view<br/>[page.tsx]"]
  node_node_videos["Videos<br/>view<br/>[page.tsx]"]
  node_node_shorts["Shorts<br/>view<br/>[page.tsx]"]
  node_node_webhook["Webhook<br/>api route<br/>[route.ts]"]
  node_node_backfill["Backfill URLs<br/>maintenance api<br/>[route.ts]"]
  node_node_refresh["Refresh previews<br/>maintenance api<br/>[route.ts]"]
  node_node_ui_components["UI components<br/>shared components"]
  node_node_design_system["Primitives<br/>ui kit"]
  node_node_article_preview["Article preview<br/>view component"]
end

subgraph group_group_worker["Cloudflare worker"]
  node_node_worker["Email worker<br/>cloudflare worker<br/>[index.ts]"]
end

subgraph group_group_data["Persistence"]
  node_node_db[("Database<br/>prisma schema<br/>[schema.prisma]")]
end

subgraph group_group_lib["Shared logic"]
  node_node_normalize["Normalize<br/>url util<br/>[normalize.ts]"]
  node_node_urls["URL extraction<br/>url util<br/>[urls.ts]"]
  node_node_classify["URL classify<br/>classifier<br/>[url-classify.ts]"]
  node_node_preview["Link preview<br/>enrichment<br/>[link-preview.ts]"]
  node_node_video["Video detect<br/>enrichment<br/>[video.ts]"]
end

node_node_worker -->|"POST mail event"| node_node_webhook
node_node_webhook -->|"persist"| node_node_db
node_node_backfill -->|"repair data"| node_node_db
node_node_refresh -->|"refresh data"| node_node_db
node_node_inbox -->|"read"| node_node_db
node_node_email_detail -->|"read"| node_node_db
node_node_articles -->|"read"| node_node_db
node_node_videos -->|"read"| node_node_db
node_node_shorts -->|"read"| node_node_db
node_node_webhook -->|"extract"| node_node_urls
node_node_urls -->|"canonicalize"| node_node_normalize
node_node_urls -->|"categorize"| node_node_classify
node_node_classify -->|"enrich"| node_node_preview
node_node_classify -->|"detect video"| node_node_video
node_node_preview -->|"render support"| node_node_article_preview
node_node_ui_components -->|"compose"| node_node_inbox
node_node_ui_components -->|"compose"| node_node_email_detail
node_node_ui_components -->|"compose"| node_node_articles
node_node_design_system -->|"build on"| node_node_ui_components
node_node_root -->|"routes to"| node_node_inbox
node_node_root -->|"routes to"| node_node_articles
node_node_root -->|"routes to"| node_node_videos
node_node_root -->|"routes to"| node_node_shorts
node_node_root -->|"routes to"| node_node_email_detail

click node_node_root "https://github.com/vaasu1234/tarat-poc/blob/main/app/layout.tsx"
click node_node_inbox "https://github.com/vaasu1234/tarat-poc/blob/main/app/inbox/page.tsx"
click node_node_email_detail "https://github.com/vaasu1234/tarat-poc/blob/main/app/email/[id]/page.tsx"
click node_node_articles "https://github.com/vaasu1234/tarat-poc/blob/main/app/articles/page.tsx"
click node_node_videos "https://github.com/vaasu1234/tarat-poc/blob/main/app/videos/page.tsx"
click node_node_shorts "https://github.com/vaasu1234/tarat-poc/blob/main/app/shorts/page.tsx"
click node_node_webhook "https://github.com/vaasu1234/tarat-poc/blob/main/app/api/webhook/route.ts"
click node_node_backfill "https://github.com/vaasu1234/tarat-poc/blob/main/app/api/backfill-urls/route.ts"
click node_node_refresh "https://github.com/vaasu1234/tarat-poc/blob/main/app/api/refresh-previews/route.ts"
click node_node_ui_components "https://github.com/vaasu1234/tarat-poc/tree/main/app/components"
click node_node_design_system "https://github.com/vaasu1234/tarat-poc/tree/main/components/ui"
click node_node_worker "https://github.com/vaasu1234/tarat-poc/blob/main/worker/src/index.ts"
click node_node_db "https://github.com/vaasu1234/tarat-poc/blob/main/prisma/schema.prisma"
click node_node_normalize "https://github.com/vaasu1234/tarat-poc/blob/main/lib/normalize.ts"
click node_node_urls "https://github.com/vaasu1234/tarat-poc/blob/main/lib/urls.ts"
click node_node_classify "https://github.com/vaasu1234/tarat-poc/blob/main/lib/url-classify.ts"
click node_node_preview "https://github.com/vaasu1234/tarat-poc/blob/main/lib/link-preview.ts"
click node_node_video "https://github.com/vaasu1234/tarat-poc/blob/main/lib/video.ts"
click node_node_article_preview "https://github.com/vaasu1234/tarat-poc/blob/main/app/articles/LinkPreviewImage.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_root,node_node_inbox,node_node_email_detail,node_node_articles,node_node_videos,node_node_shorts,node_node_webhook,node_node_backfill,node_node_refresh,node_node_ui_components,node_node_design_system,node_node_article_preview toneBlue
class node_node_worker toneAmber
class node_node_db toneMint
class node_node_normalize,node_node_urls,node_node_classify,node_node_preview,node_node_video toneRose
```

## Components

### Next.js app

User-facing App Router runtime, pages, and API routes.

- [App shell](https://github.com/vaasu1234/tarat-poc/blob/main/app/layout.tsx): next app · Top-level Next.js application entry and layout. · `app/layout.tsx`
- [Inbox](https://github.com/vaasu1234/tarat-poc/blob/main/app/inbox/page.tsx): view · Primary inbox listing for stored emails. · `app/inbox/page.tsx`
- [Email detail](https://github.com/vaasu1234/tarat-poc/blob/main/app/email/[id]/page.tsx): view · Individual email page for browsing a single record. · `app/email/[id]/page.tsx`
- [Articles](https://github.com/vaasu1234/tarat-poc/blob/main/app/articles/page.tsx): view · Filtered content view for article-like extracted links. · `app/articles/page.tsx`
- [Videos](https://github.com/vaasu1234/tarat-poc/blob/main/app/videos/page.tsx): view · Filtered content view for video-derived items. · `app/videos/page.tsx`
- [Shorts](https://github.com/vaasu1234/tarat-poc/blob/main/app/shorts/page.tsx): view · Filtered content view for short-form content. · `app/shorts/page.tsx`
- [Webhook](https://github.com/vaasu1234/tarat-poc/blob/main/app/api/webhook/route.ts): api route · Primary write path that turns inbound mail payloads into stored records. · `app/api/webhook/route.ts`
- [Backfill URLs](https://github.com/vaasu1234/tarat-poc/blob/main/app/api/backfill-urls/route.ts): maintenance api · Repair route for recomputing missing or stale URL extraction. · `app/api/backfill-urls/route.ts`
- [Refresh previews](https://github.com/vaasu1234/tarat-poc/blob/main/app/api/refresh-previews/route.ts): maintenance api · Repair route for rebuilding preview metadata. · `app/api/refresh-previews/route.ts`
- [UI components](https://github.com/vaasu1234/tarat-poc/tree/main/app/components): shared components · Shared application shell components such as header, nav, and filters. · `app/components`
- [Primitives](https://github.com/vaasu1234/tarat-poc/tree/main/components/ui): ui kit · Reusable button, card, badge, and separator components. · `components/ui`
- [Article preview](https://github.com/vaasu1234/tarat-poc/blob/main/app/articles/LinkPreviewImage.tsx): view component · 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](https://github.com/vaasu1234/tarat-poc/blob/main/worker/src/index.ts): cloudflare 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](https://github.com/vaasu1234/tarat-poc/blob/main/prisma/schema.prisma): prisma schema · 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](https://github.com/vaasu1234/tarat-poc/blob/main/lib/normalize.ts): url util · Canonicalizes links before storage and classification. · `lib/normalize.ts`
- [URL extraction](https://github.com/vaasu1234/tarat-poc/blob/main/lib/urls.ts): url util · Extracts URLs from inbound content and prepares them for downstream processing. · `lib/urls.ts`
- [URL classify](https://github.com/vaasu1234/tarat-poc/blob/main/lib/url-classify.ts): classifier · Assigns extracted links to content categories and derived buckets. · `lib/url-classify.ts`
- [Link preview](https://github.com/vaasu1234/tarat-poc/blob/main/lib/link-preview.ts): enrichment · Builds preview metadata for cards and article surfaces. · `lib/link-preview.ts`
- [Video detect](https://github.com/vaasu1234/tarat-poc/blob/main/lib/video.ts): enrichment · Handles video-specific detection or enrichment. · `lib/video.ts`

## Connections

- 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.
