How senshinya/moontv works
Main Components
a. Client (Browser / PWA)
b. Next.js Application Server
• App Router (React pages under src/app)
• API Routes (serverless functions under src/app/api)
• Middleware (src/middleware.ts)
c. Data Stores (pluggable)
• LocalStorage (client-side)
• Redis (native or Upstash)
• Cloudflare D1
d. External Services
• Third-party video/content APIs (as configured in config.json)
• Douban API (via lib/douban.client.ts)
e. Proxy Worker (proxy.worker.js) for image or cross-origin requests
f. CI/CD & Deployment
• GitHub Actions → Docker image / Vercel / Cloudflare Pages
Interactions & Data Flows
a. Browser → Next.js SSR pages (renders React + Tailwind CSS)
b. Browser → Next.js API endpoints (fetch JSON for search, detail, playrecords, auth, image-proxy, admin)
c. API endpoints → Data Store (read/write play records, favorites, user credentials)
d. API endpoints → External Content APIs & Douban API → transform & cache (lib/*)
e. Proxy Worker → browser for images (bypass CORS)
f. CI/CD triggers → build & deploy container or serverless
Architectural Patterns & Principles
• Monolithic BFF (Backend-for-Frontend): UI pages and JSON API co-located
• App Router (Next.js 14) differentiates server vs. client components
• Serverless-style API routes, each in its own folder under src/app/api
• Pluggable storage layer (LocalStorage / Redis / D1 / Upstash), selected via NEXT_PUBLIC_STORAGE_TYPE
• PWA offline cache & asset serving from public/ + service worker
• Configuration-driven aggregation (config.json drives source APIs)
Relevant Technologies & Libraries
• Next.js 14 (App Router + Middleware)
• Tailwind CSS 3, TypeScript 4
• ArtPlayer & HLS.js (client-side video player)
• Redis / Upstash SDK (lib/redis.db.ts, lib/upstash.db.ts)
• Cloudflare D1 adapter (lib/d1.db.ts)
• Axios/fetch wrappers (lib/downstream.ts, lib/douban.client.ts)
• CI/CD: GitHub Actions (.github/workflows), Dockerfile, vercel.json
Details to Capture
• The “App Router” vs. “API Routes” separation inside the Next.js server.
• The pluggable storage strategy (local vs. server DB) and environment-variable switch.
• The external-API aggregation layer (lib/downstream.ts & config.json).
• Proxy Worker’s role in image-proxy requests.
• CI/CD pipelines (.github/workflows/docker-image.yml for Docker, sync.yml for fork sync).
• Admin panel (/admin) as part of the API & rendering sub-layer.