# 996wuxian/template-web architecture

> Architecture diagram of the GitHub repository 996wuxian/template-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/996wuxian/template-web
- Repository: https://github.com/996wuxian/template-web

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        BrowserClient["Browser Client"]:::frontend
    end

    %% Next.js SSR/SSG
    subgraph "Next.js SSR/SSG Pages"
        Pages["SSR/SSG Pages"]:::backend
    end

    %% API Layer
    subgraph "Serverless API Routes"
        APIRoutes["API Routes"]:::backend
    end

    %% Service Layer
    ServiceLayer["Client-side Service Layer\n(service/)"]:::backend

    %% Data & Utilities
    DataUtils["Shared Data & Utilities"]:::backend

    %% Static Content
    Markdown["Markdown Blogs (SSG)"]:::static

    %% Static Assets / CDN
    StaticAssets["CDN / public/"]:::static

    %% Database
    PrismaDB["Prisma + PostgreSQL"]:::database

    %% Real-time Messaging
    PusherService["Pusher Channels"]:::pusher

    %% Connections
    BrowserClient -->|"HTTP Requests"| Pages
    BrowserClient -->|"API Calls"| ServiceLayer
    ServiceLayer -->|"HTTP Requests"| APIRoutes
    APIRoutes -->|"Prisma ORM"| PrismaDB
    APIRoutes -->|"Publish Events"| PusherService
    BrowserClient -->|"" real-time Events| PusherService
    Markdown -->|"SSG at Build Time"| Pages
    BrowserClient -->|"Fetch Static"| StaticAssets

    %% Click Events
    click BrowserClient "https://github.com/996wuxian/template-web/tree/main/src/pages"
    click Pages "https://github.com/996wuxian/template-web/blob/main/src/pages/index.tsx"
    click APIRoutes "https://github.com/996wuxian/template-web/blob/main/src/pages/api/blogs.ts"
    click PrismaDB "https://github.com/996wuxian/template-web/blob/main/prisma/schema.prisma"
    click PusherService "https://github.com/996wuxian/template-web/blob/main/src/lib/pusher.ts"
    click StaticAssets "https://github.com/996wuxian/template-web/tree/main/public/"
    click ServiceLayer "https://github.com/996wuxian/template-web/blob/main/service/request.ts"
    click Markdown "https://github.com/996wuxian/template-web/tree/main/src/blogs"
    click DataUtils "https://github.com/996wuxian/template-web/blob/main/src/data/experience.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#333,stroke-width:1px
    classDef database fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef pusher fill:#e2d5f9,stroke:#333,stroke-width:1px
    classDef static fill:#f0f0f0,stroke:#333,stroke-width:1px
```
