# fanyuuu2006/fanyu architecture

> Architecture diagram of the GitHub repository fanyuuu2006/fanyu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fanyuuu2006/fanyu
- Repository: https://github.com/fanyuuu2006/fanyu

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Client Browser"]:::client
        ReactPages["Next.js React Pages"]:::client
        StaticAssets["Static Assets"]:::client
        SWRCache["SWR Cache (fetcher)"]:::data
    end

    %% Edge Layer
    VercelCDN["Vercel CDN / Edge Network"]:::external

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        SSR["SSR/SSG Page Render"]:::api
        subgraph "API Routes"
            direction TB
            AlbumMeta["Album Metadata Routes"]:::api
            ImageProxy["Image Proxy Route"]:::api
            GenericProxy["Generic Drive Proxy"]:::api
        end
    end

    %% Integration Layer
    subgraph "Integration Layer"
        direction TB
        GoogleDrive["Google Drive API"]:::external
        GitHubDisc["GitHub Discussions (Giscus)"]:::external
        VercelAnalytics["Vercel Analytics"]:::external
    end

    %% Data Stores & Utils
    subgraph "Utilities & Context"
        direction TB
        ContextAPI["Context API (Album, Language)"]:::util
        UIComponents["UI Component Library"]:::util
        Styles["Tailwind & CSS"]:::util
        Utils["Utility Modules"]:::util
    end

    %% Connections
    Browser -->|"HTTP Request"| VercelCDN
    VercelCDN -->|"Serves"| StaticAssets
    VercelCDN -->|"Edge Render"| SSR
    SSR -->|"HTML/CSS/JS"| Browser

    Browser -->|"fetch via SWR"| SWRCache
    SWRCache -->|"revalidate via fetcher"| AlbumMeta

    AlbumMeta -->|"fetch metadata"| GoogleDrive
    ImageProxy -->|"proxy image fetch"| GoogleDrive
    GenericProxy -->|"proxy generic API"| GoogleDrive

    Browser -->|"embed widget"| GitHubDisc
    Browser -->|"collect metrics"| VercelAnalytics

    SSR -->|uses| ContextAPI
    SSR -->|renders| UIComponents
    SSR -->|styles with| Styles
    SSR -->|helpers| Utils

    %% Click Events
    click ReactPages "https://github.com/fanyuuu2006/fanyu/blob/main/src/app/page.tsx"
    click StaticAssets "https://github.com/fanyuuu2006/fanyu/tree/main/public/"
    click SWRCache "https://github.com/fanyuuu2006/fanyu/blob/main/src/utils/fetcher.ts"
    click VercelCDN "https://github.com/fanyuuu2006/fanyu/blob/main/next.config.ts"
    click AlbumMeta "https://github.com/fanyuuu2006/fanyu/blob/main/src/app/api/album/route.ts"
    click AlbumMeta "https://github.com/fanyuuu2006/fanyu/blob/main/src/app/api/album/[year]/route.ts"
    click AlbumMeta "https://github.com/fanyuuu2006/fanyu/blob/main/src/app/api/album/[year]/[eventName]/route.ts"
    click AlbumMeta "https://github.com/fanyuuu2006/fanyu/blob/main/src/app/api/album/[year]/[eventName]/[index]/route.ts"
    click ImageProxy "https://github.com/fanyuuu2006/fanyu/blob/main/src/app/api/album/image/[fileId]/route.ts"
    click GenericProxy "https://github.com/fanyuuu2006/fanyu/blob/main/src/app/api/proxy/route.ts"
    click ContextAPI "https://github.com/fanyuuu2006/fanyu/blob/main/src/contexts/AlbumContext.tsx"
    click ContextAPI "https://github.com/fanyuuu2006/fanyu/blob/main/src/contexts/LanguageContext.tsx"
    click UIComponents "https://github.com/fanyuuu2006/fanyu/tree/main/src/components/"
    click Styles "https://github.com/fanyuuu2006/fanyu/blob/main/tailwind.config.ts"
    click Styles "https://github.com/fanyuuu2006/fanyu/blob/main/postcss.config.mjs"
    click Utils "https://github.com/fanyuuu2006/fanyu/blob/main/src/utils/url.ts"
    click Utils "https://github.com/fanyuuu2006/fanyu/blob/main/src/utils/className.tsx"
    click Utils "https://github.com/fanyuuu2006/fanyu/blob/main/src/utils/github.ts"

    %% Styles
    classDef client fill:#AEDFF7,stroke:#000
    classDef api fill:#C2F0C2,stroke:#000
    classDef external fill:#FFD9B3,stroke:#000
    classDef util fill:#E8E8E8,stroke:#000
    classDef data fill:#F0F0F0,stroke:#000
```
