How utkarshthedev/tweeterlens works
Main components
• User / Browser
– Interacts with the React-based UI in the browser
– Fetches pages (SSR) and calls client-side data hooks (TanStack Query)
• Next.js Server (App Router)
– Renders pages server-side via src/app
– Hosts serverless API routes under src/app/api/twitter and .../stats
• Upstash Redis (Caching Layer)
– Caches Twitter profiles, tweets, and stats for 8-hour TTL
• Social Data API (External Service)
– Provides Twitter data (user profiles, tweet lists, engagement metrics)
• Vercel (Hosting / Deployment)
– Hosts Next.js app and static assets (in /public)
• Client-side State & UI Libraries
– TanStack Query (data fetching/cache on client)
– Shadcn UI + Tailwind CSS + Framer Motion (UI & animation)
Relationships and data flows
• Page request (initial SSR)
1. Browser → Next.js Server → SSR page.tsx
2. Next.js Server calls internal API route (route.ts) if data needed
3. API route checks Upstash Redis → cache hit or miss
4. If miss, API route calls Social Data API → stores response in Redis → returns data
5. Server renders page HTML + initial JSON payload → Browser
• Client-side data fetching (interactions / pagination)
1. React components (e.g., Tweets.tsx) invoke TanStack Query hooks
2. Query hooks call Next.js serverless API endpoints
3. Same Redis + external API flow as above
4. Data returns to UI, updates components
• Static assets & fonts
– Served directly from /public via Vercel’s CDN
Architectural patterns
• Full-stack SSR with Next.js App Router
• Serverless Function API Layer for data aggregation
• Smart caching using Upstash Redis to minimize external API calls
• Client-side caching & state management with TanStack Query
• Separation of concerns:
– src/app for pages & API routes
– src/components for UI
– src/lib for utilities and providers
– src/context for React context