SH.
Back to The Lab
The Lab · 02

Lens

A two-repository news analysis web app that transforms public article URLs into neutral summaries, verbatim-verified claims, and AI-generated perspectives. Explores SSRF-safe article ingestion, quote verification, streamed Server-Sent Events, and interactive 'Argue back' perspective threads.

01. Project Overview

Lens is a split frontend-and-backend editorial web application that accepts a public news article URL, extracts readable text, verifies claim quotes verbatim against the source, and streams clearly labeled AI-generated perspectives. Readers can inspect supporting quotes, challenge any perspective in a streamed conversation, flag problematic output, and generate shareable cards.

02. Problem & Exploration

Explores how to pair LLM-generated multi-perspective summaries with hard grounding checks, safe URL fetching, and progressive streaming UX so readers can inspect verbatim source evidence rather than opaque summaries.

What This Experiment Explores

Explores end-to-end streaming contracts across decoupled frontend and backend repositories, defensive URL ingestion against SSRF and redirect abuse, and deterministic verbatim quote verification.

03. Implemented Capabilities

  • SSRF-guarded article fetcher and Mozilla Readability / JSDOM extractor that keeps full article text transient and never persists it to the database.
  • Verbatim quote verifier normalizing Unicode (NFKC), quotes, dashes, and whitespace with a 25-word cap before claims or perspectives are persisted.
  • Progressive analysis pipeline streaming status, article metadata, verified summary/claims, and individual perspectives over Server-Sent Events with Zod validation on both REST and SSE payloads.
  • Interactive Next.js perspective explorer with swipe, keyboard, button, and map navigation, streamed 'Argue back' threads (capped at 6 user turns), salted-IP-hash flagging, and dynamic OG / image card routes.
  • Deterministic mock mode in both repositories, allowing the full UI and Fastify API to run and be tested offline without live Anthropic credentials.

04. Technical Approach & Stack

The Next.js 15 frontend talks to the Fastify 5 backend through a typed LensApi abstraction that switches between real REST/SSE calls (/api/v1/lenses, /lenses/:id/events, /perspectives/:id/argue) and deterministic local fixtures via NEXT_PUBLIC_USE_MOCKS. The backend uses PostgreSQL with Drizzle ORM, validates all routes with fastify-type-provider-zod, and abstracts the Anthropic SDK behind an LLMProvider interface.

Verified Technology Stack

  • Next.js
  • React
  • TypeScript
  • Tailwind CSS
  • Fastify
  • PostgreSQL
  • Drizzle ORM
  • Zod
  • Anthropic SDK
  • SSE

05. Known Limitations & Notes

  • The backend job registry uses an in-process EventEmitter; multi-instance deployments would require shared job coordination such as Redis pub/sub.
  • Live LLM analysis requires an Anthropic API key; otherwise both services run in deterministic mock mode.