How 996wuxian/template-web works
Project type and purpose
• This is a full-stack web application built with Next.js (React), Prisma, and Pusher.
• It functions as a personal blog/portfolio template supporting static content (markdown blogs), dynamic pages (chat, comments, reactions), real-time features (Pusher), and theme toggling.
File structure
• Top-level:
• next.config.ts, tsconfig.json, vercel.json: framework and deployment config
• prisma/schema.prisma: DB schema
• public/: static assets (images, SVGs, CI data)
• scripts/: utility scripts (count blogs, watch for changes)
• service/: HTTP request wrappers and API method definitions
• src/: main application code
• src/ hierarchy:
• pages/: Next.js routing (UI pages in /pages, plus serverless API routes under /pages/api)
• contexts/: React context for theme management
• lib/: Prisma and Pusher client instances
• data/: hard-coded data (experience, works, tag configs)
• utils/: helper functions (content filtering)
• blogs/: markdown content, read at build or runtime for static pages
• Deployment:
• Vercel: serverless functions for each API route, static hosting for public/ and built pages
• Neon (PostgreSQL) for database
• Pusher for WebSocket-style real-time messaging
Key architectural patterns and design principles
• Monorepo-style Next.js app combining SSR/SSG pages with API routes
• Separation of concerns:
• service/ layer abstracts HTTP calls client-side
• API routes encapsulate server-side business logic, using Prisma to talk to DB and Pusher for real-time events
• lib/ provides singletons for DB and Pusher connections
• Modular, component-driven front end with React Context for theme
• Static content (markdown blogs) alongside dynamic content (chat, comments)
a. Main components
1. Client (Browser / Mobile)
2. Next.js Server (Vercel Serverless Functions)
– Pages (SSR/SSG)
– API Routes
3. Database (Neon Postgres via Prisma)
4. Real-time Messaging Service (Pusher)
5. CDN / Static Assets (Vercel Edge, public/)
b. Relationships and data flow
• Client → Next.js Pages: request HTML/CSS/JS
• Client → API Routes (/api/blogs, /api/comments, /api/chat/...): CRUD, data fetching
• API Routes → Prisma Client → PostgreSQL: persist/fetch data
• API Routes → Pusher: publish/subscribe chat messages, notifications
• Client Pusher SDK ↔ Pusher: real-time updates
• Client fetches static markdown via file system or service layer for blog pages
c. Architectural patterns
• Serverless micro-endpoints for each API
• Shared client/server code in monorepo
• Context-driven state (theme)
• SSG for markdown blogs (build time)
d. Key technologies
• Next.js / React
• Prisma ORM
• Pusher SDK
• Vercel serverless
• Markdown processing for blogs
Essential architectural elements
• Client’s dual role: static page consumption vs. dynamic API interaction
• Separation of build-time static rendering (markdown) from runtime server logic
• Single point of truth for DB access via Prisma
• Pusher integration for chat/comment real-time updates
• The service/ layer as thin client wrapper for API calls