How fanyuuu2006/fanyu works
Project Type and Purpose
• Full-stack, server-rendered React application built on Next.js (App Router).
• Delivers both UI pages (SSG/SSR/ISR) and API endpoints (serverless functions).
• Integrates external services: Google Drive for photo albums, GitHub Discussions (Giscus) for comments, Vercel analytics.
Main Components
1. Client / Browser
• Next.js React pages (src/app/*)
• Static assets (public/)
• SWR caching layer on client
2. CDN / Edge Network (Vercel)
• Serves static files (robots.txt, images)
• Edge caching for SSR/SSG pages
3. Next.js Server (Serverless Functions)
• App Router handlers (page.tsx, layout.tsx)
• API routes under src/app/api/* (album, image proxy, guestbook proxy)
• Dynamic routing for albums (/album/[year]/[eventName]) and projects ([title])
4. External Services
• Google Drive API (images, album metadata)
• GitHub Discussions via Giscus widget
• Vercel Analytics & Speed Insights
5. Data Stores (logical)
• Google Drive (source of truth for album images)
• GitHub (comments, discussions)
• In-memory / SWR cache (client)
6. Supporting Libraries & Frameworks (annotate near relevant components)
• Tailwind CSS, PostCSS, styled globals (styles/)
• Framer Motion (animations in components/)
• SWR (data fetching, caching)
• Context API (LanguageContext, AlbumContext)
• Next.js Image (lazy loading, responsive)
• next-sitemap, robots.txt (SEO)
• ESLint, Turbopack, TypeScript (build pipeline)
Interactions & Data Flow
a. User → Browser:
• Requests page or API via URL (e.g. /album/2023/SpringFest).
b. Browser → Vercel CDN:
• Static assets, pre-rendered HTML/CSS/JS served.
• SSR/ISR pages served by edge functions.
c. Browser (client JS) → Next.js API Routes:
• Fetch album metadata/image lists via /api/album/[year]/….
• Use SWR hooks to cache & revalidate.
d. Next.js API Route → Google Drive API:
• Secure proxy (src/app/api/proxy/route.ts) injects credentials from env vars.
• Fetch file lists, image URLs.
e. Browser → Giscus (GitHub Discussions):
• Embedded iframe/widget communicates directly with GitHub.
f. Analytics:
• Vercel Analytics and Speed Insights collect usage metrics asynchronously.
Architectural Patterns & Design Principles
• SSR & SSG Hybrid (Next.js App Router)
• Dynamic Routing & Nested Layouts (src/app/…)
• Serverless Functions as micro-endpoints (API routes)
• Context API for cross-cutting concerns (i18n, album state)
• SWR for client caching & revalidation
• Proxy Pattern for secure external API (Google Drive)
• Modular component library (components/, libs/, utils/)
• Responsive, mobile-first CSS (Tailwind)