架构笔记Architecture notes
浏览器Browser
模拟Simulation架构笔记Architecture notes从这里查看网页与聊天请求的路径。Follow the paths of page requests and chat messages.正文可读Text is readable脚本功能就绪Scripted controls are ready展开一行Open a note
两条路径都经过 Nginx。Both routes pass through Nginx.浏览器先显示 HTML 正文,需要脚本的控件随后就绪。The browser displays the HTML first. Controls that need JavaScript become interactive as their scripts load.
从正文可读到控件可操作From readable to interactive模拟SimulationAstro 预先生成 HTML。一打开页面,就能读到正文。Astro builds the HTML ahead of time. Open the page and the text is ready to read.浏览器每读完一行,就把里面的文字接到同一个回答气泡。The browser reads each complete line and appends its text to the same reply.
浏览器如何追加回答How the reply growsNginxNginx
模拟SimulationGET /docs/docs/index.html200 · text/html浏览器打开这一页时,Nginx 发回已经构建好的 HTML 文件。Nginx serves the built HTML file when the browser asks for this page.
静态文件服务规则Static delivery rulesAWS 认证AWS certification模拟Simulation请求 · 浏览器 → FlaskRequest · Browser → FlaskPOST /cloudchat/deepseek_chatPOST /deepseek_chat响应 · Flask → 浏览器Response · Flask → browserproxy_buffering off{"text":"Astro 预先生成 HTML。"}{"text":"一打开页面,"}{"text":"就能读到正文。"}{"text":"Astro builds the HTML ahead of time. "}{"text":"Open the page "}{"text":"and the text is ready to read."}响应随到随转,浏览器可以边接收边显示回答。Nginx relays the JSON lines as they arrive, so the browser can start showing the reply.
Chat 转发与缓冲Chat proxy and buffering静态 HTMLStatic HTML
模拟Simulationdocs/index.html<h1>架构笔记</h1> <p>从这里查看网页与聊天请求的路径。</p><h1>Architecture notes</h1> <p>Follow the paths of page requests and chat messages.</p>Astro 在构建时就把这页正文写进了 HTML。Astro writes the page text into HTML during the build.
构建时写入了什么What the build writesFlaskFlask
带去 ChatAsk in Chat模拟Simulation{"text":"Astro 预先生成 HTML。"}{"text":"一打开页面,"}{"text":"就能读到正文。"}{"text":"Astro builds the HTML ahead of time. "}{"text":"Open the page "}{"text":"and the text is ready to read."}Flask 把每个非空模型片段封装成一个带 text 字段的 JSON 行。Flask turns each nonempty model fragment into a JSON line with a text field.
Flask 流式接口Flask’s streaming API模型 APIModel API
模拟SimulationAstro 预先生成 HTML。一打开页面,就能读到正文。Astro builds the HTML ahead of time. Open the page and the text is ready to read.模型一边生成回答,一边返回文字片段。The model produces pieces of text as it generates the reply.
片段从哪里来Where fragments come from
参考架构
打开页面时,浏览器从 Nginx 取得静态文件。发送问题时,浏览器才走另一条路径,经 Nginx 到 Flask。
构建时写入正文
Astro 在构建阶段生成 HTML。标题、正文和普通链接已经在文件里,部署后 Nginx 直接提供这些文件。
从正文到可操作控件
浏览器先解析 HTML 并显示内容。需要交互的 React 组件各自加载脚本,接管已有控件。正文在这个过程中仍然可读。
模型怎样产生片段
Flask 向模型 API 请求流式响应。模型逐步生成文字,SDK 将增量文本交给 Flask。模型增量还不是前端使用的 JSON 行。
浏览器怎样接成一条回答
Chat 从 /deepseek_chat/ 打开,提问发送到 /cloudchat/deepseek_chat。浏览器缓存尚未完整的一行,读到换行再解析 text,并把它追加到同一个回答。
Reference Architecture
Opening a page fetches static files from Nginx. Sending a question follows a different route through Nginx to Flask.
What the build writes
Astro generates HTML at build time. Headings, text, and ordinary links are already in the files Nginx serves after deployment.
From readable text to working controls
The browser parses the HTML and displays its content first. Interactive React components load their scripts and attach behavior to the existing controls while the text stays readable.
Where model fragments come from
Flask requests a stream from the model API. The model generates text incrementally and the SDK passes those text deltas to Flask. These deltas have yet to be packaged as the JSON lines sent to the browser.
How the browser builds one reply
Open Chat at /deepseek_chat/. Questions go to /cloudchat/deepseek_chat. The browser buffers an incomplete line, parses its text field when a newline arrives, and appends that text to the same reply.
完整参考Full reference
- 张人大 · 轻量级网站
- 简介
- PersonalWeb 项目概览
- 技术栈
- 前端
- 后端
- Nginx 服务器
- 文档说明
- Git 分支与发布流程
- CI/CD 工作流
- 运维维护命令索引
- 依赖与安全风险登记
- Astro 7 升级预检
- Astro 6 迁移预检
- 前端架构约定
- 前端目录所有权地图
- Chat Widget 协议说明
- 前端体验平台 RFC
- 交互组件标准
- 人性化表达与个人风格
- 内容可信度与个人定位
- Site Intelligence 与访客路径
- 作品证明与访问转化
- Chat Guide 质量架构
- SEO / GEO 维护说明
- BUG 记录
- 开发需求
- 用户认证与密码重置规范
- 原生到 Astro + React 升级
- 响应式图片系统维护
- 错误跟踪
- 工具函数参考文档
- 预提交钩子综合指南
- 测试指南
- JS ➜ TS 迁移指南
- 样式体系说明
- 🤝 贡献指南
- 🔒 开源许可证
- 📬 联系方式
张人大 · 轻量级网站
- 作者: 张人大
- 最后更新: November 24, 2026, 17:05 (UTC+08:00)
简介
Click here to view the English Version in Github
这是我维护的个人网站,也是一个持续演进的公开工程项目。它把中英双语作品集、AI 对话、 技术文档、测试和自动部署放在同一个可审查的代码库中。
网站链接: 🌐 www.rendazhang.com
公开页面也包含 SEO / GEO、结构化数据和 AI 摘要入口,方便搜索与阅读。
PersonalWeb 项目概览
我同时把 PersonalWeb 当作中英双语作品集和一个持续维护的工程项目。主要页面由 Astro 生成静态 HTML,导航、主题、语言、表单、证书信息和 Chat 等交互再由 React 负责。
AI Chat 提供独立页面和首页浮动窗口;两者通过同源地址连接 Flask 后端。导览问题只依据网站和 公开仓库信息回答,普通 Chat 仍保留原有请求方式。
Vitest、Playwright 浏览器检查、Astro 构建和 GitHub Actions 组成可重复执行的验证与发布流程。 仓库还记录了前端、后端、Nginx、CSP、目录所有权和运维命令之间的边界。
可以从以下入口继续了解:
- 参考架构:了解前端、后端、Nginx 与部署之间的关系。
- AI 聊天页面:体验流式输出、Markdown 和代码渲染。
- Chat Widget 协议说明:查看同源 iframe 的加载与消息边界。
- 测试指南:查看 Vitest、覆盖率、Playwright 与浏览器 QA。
- CI/CD 工作流:查看静态构建、部署与发布流程。
- SEO / GEO 维护说明:查看公开内容如何面向搜索与 AI 摘要保持一致。
PersonalWeb 是我持续维护的个人项目,不能说明高流量规模、私人客户系统或大型商业 SaaS。 公开仓库不会包含密钥、访客消息、表单内容、私人日志或服务器细节。
另一个公开仓库 📁 Renda Cloud LAB 聚焦云原生服务器架构,可用于查看与 PersonalWeb 不同的设计范围。
技术栈
| 分类 | 技术 |
|---|---|
| 前端 | Astro, React, TypeScript |
| 状态管理 | React useState、useContext(可扩展 Zustand 等) |
| 构建工具 | Astro 内置 (基于 Vite) |
| 后端 | Flask + OpenAI API |
| 部署 | GitHub Actions + Nginx |
目录结构
src/
├── assets/
├── constants/ # 站点元信息、资源路径与应用设置
├── features/ # 按业务划分的模块
│ ├── chat/
│ │ ├── components/
│ │ ├── hooks/
│ │ └── services/
│ └── auth/
│ ├── components/
│ ├── hooks/
│ └── services/
├── hooks/ # 业务逻辑自定义 hooks
├── styles/
│ ├── core/ # 核心变量
│ │ ├── tokens.css # 设计 Token(颜色、间距等)
│ │ └── _gradients.css # 渐变系统
│ ├── components/ # 组件样式
│ ├── utilities/ # 工具类
│ └── theme.css # 主入口文件
├── scripts/
├── utils/ # 通用工具函数
├── models/ # 领域模型
├── services/ # API interaction layer
└── components/
├── ui/
├── layouts/
├── forms/
├── chat/
├── sections/
└── providers/
参考架构
ASCII 图示:
Web Application Architecture
============================
Frontend (
Astro + React
- 负责用户界面和交互
) → CI/CD (
GitHub Actions 自动构建部署
) → Server (
Ubuntu (操作系统)
↓
Nginx (静态文件服务)
↓
systemd 服务 (进程管理)
↓
Gunicorn + Gevent (WSGI 服务器)
↓
Backend: Flask App (处理业务逻辑和 API 请求)
)
Mermaid Flow 图示:
flowchart TD
A[Web] --> B[Frontend: Astro + React]
A --> C[Server]
B -->|负责用户界面和交互| C
subgraph Server
direction TB
D[Ubuntu: 操作系统] --> E[Nginx: 静态服务]
E --> F[systemd 服务: 进程管理]
F --> G[Gunicorn + Gevent: WSGI 服务器]
G --> H[Backend: Flask App: 处理业务逻辑和 API 请求]
end
前端
本仓库就是前端项目:📁 Renda Zhang WEB
架构说明
BaseLayout 组件设计说明
src/layouts/BaseLayout.astro 是站点的全局页面框架,用于设置 <head> 元信息、SEO 标签以及根级插槽。导航栏与汉堡菜单虽然依赖浏览器环境,但现在通过 client:load 先在服务端渲染静态结构,再在客户端水合以避免语言闪烁等问题。保留该文件为 Astro 组件的主要考虑如下:
- 静态内容无需 JavaScript:布局结构和元数据生成属于纯静态内容,Astro 可以直接输出 HTML,无需引入 React 运行时。
- 保持局部客户端渲染:当前仅对导航栏等交互区使用 React,并通过
client:load在服务端输出静态 HTML 后于客户端水合,其余内容保持零 JS,以最小化 bundle 体积。如果整体改写为 React,会带来额外脚本和水合开销。 - 充分利用 Astro 特性:
<slot>、is:inline等 Astro 专属语法在布局中被广泛使用,若迁移到 React 需额外封装或插件支持,增加维护成本。
只有在计划将站点全面迁移到 React,或需要在布局层共享复杂的 React 状态/上下文时,才考虑改写 BaseLayout.astro。在现阶段,维持 Astro 版本更简洁高效。
为满足 Nginx 的 CSP 限制并在 404/500 等纯静态页面中复用主题与语言逻辑,原有的内联初始化脚本已抽离为阻塞式外部脚本 /js/base-layout-init.js。该文件由 src/scripts/base-layout-init.ts 编译生成,并通过 data-theme-key、data-palette-key、data-lang-key 等属性向脚本传递存储键,在渲染前完成主题 mode、调色板和语言初始化。
本地开发和预览
安装依赖并启用 pre-commit:
npm install pip install pre-commit pre-commit install运行本地开发服务器:
npm run dev构建并预览生产版本:
npm run build npm run preview如需连接自定义后端接口,可在根目录
.env/.env.local文件设置PUBLIC_API_BASE_URL:PUBLIC_API_BASE_URL=https://api.example.comSentry 集成还需要以下变量:
SENTRY_DSN=<server dsn> PUBLIC_SENTRY_DSN=<browser dsn> SENTRY_PROJECT=<your project> SENTRY_AUTH_TOKEN=<auth token>本地检查或提交前如需跳过 Sentry 上报,可临时添加环境变量:
SKIP_SENTRY=true pre-commit run --all-files SKIP_SENTRY=true npm run astro -- check --incremental如需临时跳过 ESLint 检查以加快提交,可设置:
SKIP_ESLINT=true pre-commit run --all-files环境变量说明
本地可以配置在
.env或者.env.local,并通过src/utils/env.ts的getEnv()读取:# 公开信息 PUBLIC_SITE_BASE_URL = "https://www.rendazhang.com" PUBLIC_CDN_BASE="https://cdn.jsdelivr.net/gh/rendazhang/rendazhang@1.0.1/" PUBLIC_API_BASE_URL="/cloudchat" PUBLIC_SENTRY_DSN="https://e184a284f1b7342d197ee0a0151f8353@o4509770577543168.ingest.us.sentry.io/4509770780377088" PUBLIC_TAG_NAME="v1.0.1" NODE_ENV="production" PUBLIC_NODE_ENV="development" # 本地调试覆盖为 development SKIP_SENTRY="true" # 跳过 Sentry SKIP_ESLINT="true" # 跳过 ESLint 检查 # 敏感配置(如下为示例) SENTRY_AUTH_TOKEN="sntrys_xxx" SENTRY_DSN="https://private-key@xxx.ingest.us.sentry.io/xxx" SENTRY_PROJECT="xxx" SENTRY_ORG="xxx"
执行 npm run build 后,dist/_astro 目录会生成带有哈希后缀的静态文件,方便浏览器长时间缓存。
浏览器访问 http://localhost:4321 查看效果。
构建后的静态文件可使用 npm run preview 验证。
GitHub Actions
Push 到 master 分支会触发 GitHub Actions 自动部署:
- 使用
actions/checkout@v5检出代码。 - 使用
actions/setup-node@v6安装 Node.js 24,并启用 npm 缓存。 - 执行
npm ci,以package-lock.json为准安装依赖。 - 构建前执行
npm run sync、npm run lint、npm run typecheck、npm run check和npm run test:coverage。 - 执行
npm run build生成dist/静态文件;生产环境会删除 source map。 - 通过
appleboy/scp-action将dist/内容上传到服务器指定目录(如/var/www/html)。 - 发布 release 分支、重建版本标签、创建 GitHub Release,并尝试清理 jsDelivr 版本缓存。
- 部署完成后即可通过 Nginx 提供服务;静态站点不需要重启前端服务。
本地提交不会自动运行完整 Astro 检查,如需校验请手动执行:
npm run check
需要在仓库 Secrets 中配置服务器 IP、SSH 用户和私钥等信息。详情见 📄 配置 GitHub Actions。
使用说明
部署完成后可直接访问各模块页面。
如下是我的网站的每个页面的链接:
网站功能
关于网站的核心功能体系,请参考以下文档链接:📄 核心功能体系。该文档详细描述了网站的核心功能模块,包括功能设计和技术实现,是开发与维护的重要参考。
- 主题切换(浅色 / 深色)
- 语言切换(中文 / 英文)
- 与 AI 在线对话
- 浮动 AI 聊天窗口
- 回到顶部按钮
- 技术文档渲染展示页 (docs/)
- 登录与注册表单
- 已登录用户账号信息页(登录后可从汉堡菜单访问账号注册信息)
- 联系表单
- 内容平台链接
- 证书展示
- 简历下载
页面功能
各页面核心职责如下(均由 .astro 文件生成):
index.astro:主页,也是张人大介绍页,展示张人大的信息、教育、技能、博客及工作经验。certifications.astro:证书列表页。deepseek_chat.astro:AI 聊天界面。docs.astro:技术文档页面。profile.astro:用户账号信息页。login.astro:登录页。register.astro:注册页。404.astro,500.astro:错误页面。
页面跳转
返回主页
- 所有页面均包含导航栏中的“主页”按钮,点击后可返回主页。
导航栏菜单跳转
- 导航栏与汉堡菜单在服务端输出静态标记,并通过
client:load在客户端水合,既保留交互又避免 Hydration 报错。 - 桌面直接从页头打开 AI 聊天、证书和文档,手机在菜单中按同一顺序显示。登录后还可以打开账号。
- 官网文档可以对照静态页面和流式回答两条路径。构建、CI/CD 和维护资料在「完整参考」中。
- 导航栏与汉堡菜单在服务端输出静态标记,并通过
登录页面跳转
- 通过点击导航栏的“人像图标”按钮,用户可跳转到登录页面。
Mermaid Flow 图示:
flowchart TD
A[主页] -->|页头或手机菜单| B[AI 聊天页]
A -->|页头或手机菜单| C[证书页]
A -->|页头或手机菜单| D[文档 /docs/]
A -->|登录后| F[账号信息页]
A -->|人像图标| E[登录页面]
B -->|主页按钮| A
C -->|主页按钮| A
D -->|主页按钮| A
E -->|主页按钮| A
F -->|主页按钮| A
style A fill:#9f9,stroke:#333
style B fill:#f9f,stroke:#333
style C fill:#ff9,stroke:#333
style D fill:#99f,stroke:#333
style E fill:#f99,stroke:#333
style F fill:#9ff,stroke:#333
页面内容
index.astro:多 Section 主页,包含 "Hero"、"自我介绍"、"教育"、"博客"、"技能与能力"、"经历"、"联系我吧" 等模块,并默认悬挂ChatWidget浮标。certifications.astro:栅格卡片形式展示证书,并嵌入 Credly 验证链接。deepseek_chat.astro:由聊天记录区域与输入框组成的对话界面,支持流式输出并实时渲染 AI 返回的 Markdown 内容,提供一键复制原始内容的功能,并在页面刷新后自动保留历史记录,同时加载github-code-highlight.css和github-markdown-light.css以保持代码高亮与排版一致。聊天组件已拆分为ChatMessageList、ChatInput等子组件,方便复用与维护。docs.astro:技术文档页面,使用同样的两份 GitHub 样式表配合 highlight.js 渲染 Markdown 与代码。profile.astro:账号信息页,展示当前登录用户的信息。login.astro:登录表单页。register.astro:注册表单页。404.astro / 500.astro:用于处理页面不存在(404)和服务器内部错误(500)的定制化错误页面,提供清晰的错误信息、友好的用户引导和返回主页的链接,以提升用户体验。
页面优化
自适应布局:优化页面在不同设备上的显示效果,减少不必要的资源加载和布局计算,从而提高性能。确保页面在不同屏幕尺寸(如桌面、平板、手机)上都能良好显示,提升用户体验。
懒加载:所有图片开启了懒加载 + Loading 动画,其中,针对高清图片采用 LQIP 懒加载优化(比如主页的 Hero 区域)
配色方案
当前提供墨与朱、银与钴蓝、石墨与松绿三套主题,各含浅色与深色。六组 sRGB 参考色通过语义 Token 映射到页面和交互状态;既有 OKLCH 基础值仍保留,但不覆盖当前主题契约。 完整颜色、状态与偏好兼容规则见 个人主题配色契约。
详情参考文档内容:📄 配色方案
后端
后端部署的具体步骤和配置,请参考以下项目:📁 Python Cloud Chat。该项目提供了完整的后端实现和部署指南,帮助您快速搭建和运行后端服务。
Nginx 服务器
前端项目通过 GitHub Actions 自动化构建后,会直接推送到服务器的
/var/www/html目录,并由 Nginx 提供静态资源服务。
关于 Nginx 的详细配置和操作说明,请查看以下仓库:📁 Nginx Conf。该仓库包含了常用的 Nginx 配置文件和使用示例,方便您快速上手。
为充分利用构建生成的指纹文件,可在 Nginx 中为
/_astro/路径添加长效缓存配置:
location /_astro/ {
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
}
如果您需要更重量级的服务器解决方案,可以参考我的云原生项目:📁 Renda Cloud LAB。该项目提供了基于云原生的完整架构设计,适用于大规模和高可用性场景。
文档说明
Git 分支与发布流程
项目采用轻量主干流程:文档和小修复可直接在干净的
master上完成;依赖升级和较大行为变更使用短分支,验证发布后清理。每个 Slice 都有开工检查和收尾清理,不要求常驻develop或每次创建 PR。详见:Git Workflow。
CI/CD 工作流
deploy.yml定义了推送到master时触发的自动部署流程,包括标签管理、发布分支与环境变量映射等,可参考:📄 CI / CD Pipeline。
运维维护命令索引
前端验证、deploy run 检查、deploy log 噪声分类、依赖审计、后端/Nginx docs-only 同步规则、生产只读检查和本地 roadmap 维护命令见:📄 Operations Maintenance Guide。
依赖与安全风险登记
当前 dependency audit / Dependabot 状态、
npm audit fix --force禁止原因、Astro 7 实施结果和安全补丁升级阈值见:📄 Dependency Security Risk Register。
Astro 7 升级预检
Astro 7 的 Go/No-Go 结论、实施结果、目标包集合、Vite 8/Rolldown 风险、Sentry source-map、CSP、Chat Widget smoke 和回滚计划见:📄 Astro 7 Upgrade Precheck。
Astro 6 迁移预检
Astro 6 升级前的当前基线、目标包集合、Node/Vite/Sentry 兼容性风险、验证清单和回滚策略见:📄 Astro 6 迁移预检。
前端架构约定
Astro 页面、
BaseLayout、React Islands、Hydration、服务层、工具函数、样式 Token、CSP 与 iframe 约束的当前约定见:📄 前端架构约定。
前端目录所有权地图
src/components、src/services、src/utils、src/styles、src/content、src/stores和src/controllers的目录职责边界见:📄 前端目录所有权地图。
Chat Widget 协议说明
浮动 Chat Widget 与
/deepseek_chat/同源 iframe 的postMessageready 协议、origin/source 校验、加载生命周期和后续重构约束见:📄 Chat Widget 协议说明。
前端体验平台 RFC
Phase 8 的浏览器 smoke、hydration 安全、主题 mode 与 palette/accent 分离、调色板切片顺序和交互标准规划见:📄 前端体验平台 RFC。
交互组件标准
modal、popover/menu、toast/status、loading、disabled/empty/error state、键盘行为、focus 管理和 browser smoke 门禁见:📄 交互组件标准。
人性化表达与个人风格
Phase 15 的中英文写作语气、第一人称表达、技术术语、CTA、证据边界、视觉个性和 owner 输入规则见:📄 Human Voice And Personal Expression。
内容可信度与个人定位
Phase 10 的个人品牌内容、可信证明、PersonalWeb 项目证明、证书、工作/学习经历与 SEO/GEO 一致性规划见:📄 内容可信度与个人定位。
Site Intelligence 与访客路径
Phase 11 的访客路径、隐私安全匿名事件、first-party telemetry 边界和 Chat Guide 公开内容范围见:📄 Site Intelligence And Visitor Journey。
作品证明与访问转化
Phase 14 的作品证明、访问路径、PersonalWeb case-study surface、首页 proof path、Chat Guide 入口和浏览器/移动端转化 QA 规划见:📄 Portfolio Proof And Visitor Conversion。
Chat Guide 质量架构
Phase 12 的 Chat Guide 公开知识边界、答案质量问题、后端公共知识包方案和后续切片顺序见:📄 Chat Guide Quality Architecture。
SEO / GEO 维护说明
canonical host、sitemap、
llms.txt、/docs/SSR 正文和 soft-404 验证规则见:📄 SEO / GEO 维护说明。
BUG 记录
前端开发过程中遇到的 BUG 及其解决方案,请参考以下文档:📄 前端 BUG 跟踪数据库。该文档详细记录了 BUG 的描述、复现步骤、解决方案以及相关开发者的处理记录,帮助您快速定位和解决问题。
开发需求
项目的功能需求、优先级以及开发计划,请参考以下文档:📄 项目需求清单。该文档列出了当前版本的所有需求,并提供了需求的详细描述和开发状态,方便您了解项目进展和规划开发任务。
用户认证与密码重置规范
用户认证与密码重置的页面路由、API 契约、密码策略和安全注意事项等内容,请参考:📄 用户鉴权规范。
原生到 Astro + React 升级
前端目前采用 Astro + React 的架构,基于分层设计理念,通过 GitHub Actions 实现自动化构建,并将构建产物部署到服务器 Nginx 的指定目录下。
具体的从原生前端升级的操作步骤,请参考以下文档内容:📄 升级计划。该文档详细描述了从旧版原生前端逐步迁移到基于 Astro 和 React 的新前端架构的完整计划与实施步骤。
开发环境准备的具体步骤,请参考以下文档内容:📄 环境准备。该文档详细说明了如何完成开发环境的配置以及 Astro 项目的初始化工作,确保您能够顺利开始后续的开发任务。
响应式图片系统维护
网站图片通过自动化脚本生成响应式版本并内置 LQIP 占位效果,方便在不同设备上快速加载。
详细操作流程与扩展指南请参阅:📄 通用响应式图片处理系统维护文档
错误跟踪
Sentry 用于收集运行时异常与网络错误。配置步骤请见 📄 错误跟踪集成.
工具函数参考文档
src/utils/env.ts、src/utils/langUtils.ts、src/utils/storage.ts 与 src/utils/logger.ts 提供统一的环境变量访问、语言解析、多后端存储方案与可扩展的日志接口。
文档详见:📄 工具函数参考文档.
预提交钩子综合指南
详细预提交钩子说明请参阅:预提交钩子综合指南
测试指南
项目使用 Vitest 进行单元测试。运行 npm test 即可执行所有测试;npm run test:watch 可在开发过程中持续监听;如需覆盖率报告,可使用 npm run test:coverage。测试文件需以 .test.ts 或 .spec.ts 命名,通常与源码放在同一目录或 __tests__ 子目录下。更多示例与编写说明参见:测试指南。
JS ➜ TS 迁移指南
汇总从 JavaScript 到 TypeScript 的完整迁移过程与经验,包括配置、分步策略和常见报错排查。详见:📄 JS ➜ TS 全量迁移实战指南。
样式体系说明
介绍项目的 CSS 架构、语义 Token 体系与构建流程,展示
postcss-import如何在编译阶段内联theme.css引用的核心与工具样式以减少运行时请求,详见:📄 样式说明。
🤝 贡献指南
- Fork 并克隆这个仓库。
- 进入虚拟环境:
# 如果还没安装虚拟环境,执行命令:python -m venv venv source venv/bin/activate - 安装依赖并启用 pre-commit:
pip install pre-commit pre-commit install - 在每次提交前,钩子会自动运行,执行以下操作:
- 自动修复基础格式问题(行尾空格、文件末尾换行符等)
- 更新文档目录和最后更新时间
- 同步 README 文件到 assets 目录
- 验证静态资源命名规范
- 自动生成模块
index.ts文件 - 执行代码格式化和静态检查
所有提交必须通过 pre-commit 检查;当前前端 CI 在
masterpush 后验证并部署,不提供 PR 自动门禁。合入前请完成本地验证。
🔒 开源许可证
本项目以 MIT 许可证 发布,你可以自由使用与修改。请在分发时保留原始许可证声明。
📬 联系方式
- 联系人:张人大(Renda Zhang)
- 📧 邮箱:952402967@qq.com
⏰ 维护者:@张人大 — 如果本项目对你有帮助,请不要忘了点亮 ⭐️ Star 支持我们!
- Renda Zhang · Lightweight Website
- Introduction
- PersonalWeb Project Overview
- Tech Stack
- Frontend
- Backend
- Nginx Server
- Documentation
- Git Branching & Release Workflow
- CI/CD Workflow
- Operations Maintenance Guide
- Dependency Security Risk Register
- Astro 7 Upgrade Precheck
- Astro 6 Migration Precheck
- Frontend Architecture Conventions
- Frontend Directory Ownership Map
- Chat Widget Protocol
- Frontend Experience Platform RFC
- Interaction Component Standards
- Human Voice And Personal Expression
- Content And Credibility Positioning
- Site Intelligence And Visitor Journey
- Portfolio Proof And Visitor Conversion
- Chat Guide Quality Architecture
- SEO / GEO Maintenance
- BUG Tracking
- Development Requirements
- User Authentication and Password Reset Specification
- Native to Astro + React Migration
- Responsive Image System Maintenance
- Error Tracking
- Utilities Reference
- Comprehensive Pre-Commit Guide
- Style System Description
- 🤝 Contribution Guide
- 🔒 Open Source License
- 📬 Contact
Renda Zhang · Lightweight Website
- Author: Renda Zhang
- Last Updated: November 24, 2026, 17:05 (UTC+08:00)
Introduction
This is my personal website and an evolving public engineering project. It brings a bilingual portfolio, AI Chat, technical documentation, tests, and automated delivery into one inspectable repository.
Live Site: 🌐 www.rendazhang.com
The public pages also include SEO/GEO, structured data, and an AI-summary entry point.
PersonalWeb Project Overview
I maintain PersonalWeb as both a bilingual portfolio and a working engineering project. Astro generates the main pages as static HTML, while React handles navigation, theme and language controls, forms, certification details, and Chat.
AI Chat is available as a direct page and as a floating homepage window. Both use a same-origin route to the Flask backend. Guided questions use public site and repository information, while ordinary Chat keeps its existing request path.
Vitest, Playwright browser checks, Astro builds, and GitHub Actions provide a repeatable validation and delivery path. The repository also documents the boundaries between the frontend, backend, Nginx, CSP, directory ownership, and routine operations.
Continue with:
- Reference Architecture: see how the frontend, backend, Nginx, and deployment fit together.
- AI Chat: try streaming responses, Markdown, and code rendering.
- Chat Widget Protocol: inspect the same-origin iframe loading and message boundary.
- Testing Guide: review Vitest, coverage, Playwright, and browser QA.
- CI/CD Pipeline: review the static build, deployment, and release flow.
- SEO / GEO Maintenance: see how public content stays aligned for search and AI summaries.
PersonalWeb is a maintained personal project. It does not demonstrate high-traffic scale, private customer systems, or a large commercial SaaS. The public repository leaves out secrets, visitor messages, form contents, private logs, and server details.
Another public repository, 📁 Renda Cloud LAB, focuses on cloud-native server architecture and shows a different project scope from PersonalWeb.
Tech Stack
| Category | Technologies |
|---|---|
| Frontend | Astro, React, TypeScript |
| State Management | React useState, useContext (Zustand compatible) |
| Build Tools | Astro built-in (Vite-based) |
| Backend | Flask + OpenAI API |
| Deployment | GitHub Actions + Nginx |
Directory Structure
src/
├── assets/
├── constants/ # Site metadata, asset paths, and app settings
├── features/ # Feature-based modules
│ ├── chat/
│ │ ├── components/
│ │ ├── hooks/
│ │ └── services/
│ └── auth/
│ ├── components/
│ ├── hooks/
│ └── services/
├── hooks/ # Custom hooks for business logic
├── styles/
│ ├── core/ # Core variables
│ │ ├── tokens.css # Design tokens (colors, spacing, etc.)
│ │ └── _gradients.css # Gradient system
│ ├── components/ # Component styles
│ ├── utilities/ # Utility classes
│ └── theme.css # Main entry file
├── scripts/
├── utils/ # Utility helpers
├── models/ # Domain models
├── services/ # API interaction layer
└── components/
├── ui/
├── layouts/
├── forms/
├── chat/
├── sections/
└── providers/
Reference Architecture
ASCII Diagram:
Web Application Architecture
============================
Frontend (
Astro + React
- Handles UI and interactions
) → CI/CD (
GitHub Actions auto-build & deploy
) → Server (
Ubuntu (OS)
↓
Nginx (static file serving)
↓
systemd service (process management)
↓
Gunicorn + Gevent (WSGI server)
↓
Backend: Flask App (business logic & API handling)
)
Mermaid Flow Diagram:
flowchart TD
A[Web] --> B[Frontend: Astro + React]
A --> C[Server]
B -->|Handles UI and interactions| C
subgraph Server
direction TB
D[Ubuntu: OS] --> E[Nginx: Static serving]
E --> F[systemd: Process management]
F --> G[Gunicorn + Gevent: WSGI server]
G --> H[Backend: Flask App: Business logic & APIs]
end
Frontend
This repository contains the frontend project: 📁 Renda Zhang WEB
Architecture Overview
BaseLayout Component Design Notes
src/layouts/BaseLayout.astro serves as the global page framework for the site, responsible for setting <head> metadata, SEO tags, and root-level slots. The navigation bar and hamburger menu now render on the server and hydrate with client:load, avoiding language flicker while preserving interactivity. The primary reasons for keeping this file as an Astro component are as follows:
- Static Content Does Not Require JavaScript: The layout structure and metadata generation are purely static content. Astro can directly output HTML without introducing the React runtime.
- Maintain Partial Hydration Benefits: Only interactive regions such as the navigation bar and hamburger menu use React, rendering static HTML first and hydrating on the client via
client:load. The rest of the layout remains zero-JS, keeping bundle size minimal. Rewriting the entire layout in React would introduce additional script and hydration overhead. - Leverage Astro Features: Astro-specific syntax such as
<slot>andis:inlineis extensively used in the layout. Migrating to React would require additional encapsulation or plugin support, increasing maintenance costs.
Consider rewriting BaseLayout.astro only if there are plans to fully migrate the site to React or if there is a need to share complex React state/context at the layout level. For now, maintaining the Astro version is more concise and efficient.
To satisfy Nginx CSP restrictions and allow static pages like 404/500 to reuse theme and language logic, the former inline initialization script has been moved to a blocking external script /js/base-layout-init.js. The file is generated from src/scripts/base-layout-init.ts and passes storage keys via data-theme-key, data-palette-key, and data-lang-key attributes so that theme mode, palette, and language are applied before the page renders.
Local Development & Preview
Install dependencies and enable pre-commit:
npm install pip install pre-commit pre-commit installStart local dev server:
npm run devBuild and preview production version:
npm run build npm run previewTo connect to a custom backend API, set the
PUBLIC_API_BASE_URLin the root directory's.env/.env.localfile:PUBLIC_API_BASE_URL=https://api.example.comSentry integration also requires:
SENTRY_DSN=<server dsn> PUBLIC_SENTRY_DSN=<browser dsn> SENTRY_PROJECT=<your project> SENTRY_AUTH_TOKEN=<auth token>When running local checks or pre-commit without Sentry, prepend:
SKIP_SENTRY=true pre-commit run --all-files SKIP_SENTRY=true npm run astro -- check --incrementalTo temporarily skip ESLint checks and speed up commits, use:
SKIP_ESLINT=true pre-commit run --all-filesEnvironment Variables Explanation
Local configurations can be set in
.envor.env.local, and read via thegetEnv()function insrc/utils/env.ts:# Public Information PUBLIC_SITE_BASE_URL = "https://www.rendazhang.com" PUBLIC_CDN_BASE="https://cdn.jsdelivr.net/gh/rendazhang/rendazhang@1.0.1/" PUBLIC_API_BASE_URL="/cloudchat" PUBLIC_SENTRY_DSN="https://e184a284f1b7342d197ee0a0151f8353@o4509770577543168.ingest.us.sentry.io/4509770780377088" PUBLIC_TAG_NAME="v1.0.1" NODE_ENV="production" PUBLIC_NODE_ENV="development" # Override to "development" for local debugging SKIP_SENTRY="true" # Skip Sentry SKIP_ESLINT="true" # Skip ESLint checks # Sensitive configurations (example values below) SENTRY_AUTH_TOKEN="sntrys_xxx" SENTRY_DSN="https://private-key@xxx.ingest.us.sentry.io/xxx" SENTRY_PROJECT="xxx" SENTRY_ORG="xxx"
After running npm run build, the dist/_astro directory will contain fingerprinted files with hash suffixes, allowing browsers to cache them long-term.
Access via http://localhost:4321.
Verify builds using npm run preview.
GitHub Actions
Pushing to master triggers GitHub Actions Auto-Deployment:
- Check out the code with
actions/checkout@v5. - Set up Node.js 24 with
actions/setup-node@v6and enable npm caching. - Run
npm ciso dependency installation is based onpackage-lock.json. - Before building, run
npm run sync,npm run lint,npm run typecheck,npm run check, andnpm run test:coverage. - Run
npm run buildto generate thedist/static files; production builds remove source maps. - Use
appleboy/scp-actionto upload the contents ofdist/to the server directory, such as/var/www/html. - Publish the release branch, recreate the version tag, create the GitHub Release, and try to purge the jsDelivr version cache.
- After deployment, Nginx serves the static site; no frontend service restart is required.
Local commits do not automatically run the full Astro check. To validate manually, run:
npm run check
Configure server IP, SSH user, and private key in Repository Secrets. Details: 📄 GitHub Actions Setup
Usage Guide
Access all modules post-deployment:
Website Features
For details on the core functionality system of the website, please refer to the following documentation link: 📄 Core Functionality System. This document provides a detailed description of the website's core functional modules, including feature design and technical implementation. It serves as an essential reference for development and maintenance.
- Theme Switching (Light / Dark)
- Language Switching (Chinese / English)
- Online Chat with AI
- Floating AI Chat Window
- Back to Top Button
- Technical Documentation Rendering Page (docs/)
- Login and Registration Form
- Logged-in User Account Information Page (Accessible from the Hamburger Menu after Login)
- Contact Form
- Content Platform Links
- Certificate Display
- Resume Download
Page Functionality
The core responsibilities of each page are as follows (all generated by .astro files):
index.astro: Homepage, also the introduction page for Zhang Renda, showcasing Zhang Renda's information, education, skills, blog, and work experience.certifications.astro: Certifications list page.deepseek_chat.astro: AI chat interface.docs.astro: Technical documentation page.profile.astro: User account information page.login.astro: Login page.register.astro: Registration page.404.astro,500.astro: Error pages.
Page Navigation
Return to Homepage All pages have "Home" button in navigation
Navigation Menu Redirection
- The navigation bar and hamburger menu output static markup on the server side and are hydrated on the client side using
client:load, ensuring interactivity while avoiding hydration errors. - The desktop header links directly to AI Chat, Certifications, and Docs. The mobile menu lists them in the same order. Account is available after sign-in.
- On the website, Docs compares how a static page opens with how an answer streams. Build, CI/CD, and maintenance information is under Full reference.
- The navigation bar and hamburger menu output static markup on the server side and are hydrated on the client side using
Login Page Access Profile icon in nav redirects to login
flowchart TD
A[Home] -->|Header or mobile menu| B[AI Chat]
A -->|Header or mobile menu| C[Certifications]
A -->|Header or mobile menu| D[Docs /docs/]
A -->|After sign-in| F[Account Profile]
A -->|Profile Icon| E[Login]
B -->|Home Button| A
C -->|Home Button| A
D -->|Home Button| A
E -->|Home Button| A
F -->|Home Button| A
style A fill:#9f9,stroke:#333
style B fill:#f9f,stroke:#333
style C fill:#ff9,stroke:#333
style D fill:#99f,stroke:#333
style E fill:#f99,stroke:#333
style F fill:#9ff,stroke:#333
Page Content
index.astro: A multi-section homepage containing modules such as "Hero", "About Me", "Education", "Blog", "Skills & Abilities", "Experience", and "Contact Me", with a default floatingChatWidgetbadge.certifications.astro: Grid-based certification cards with Credly verificationdeepseek_chat.astro: A conversational interface consisting of a chat history area and an input box, supporting streaming output and real-time rendering of AI-generated Markdown content. It provides a one-click copy feature for the original content and automatically retains the chat history upon page refresh, and loads bothgithub-code-highlight.cssandgithub-markdown-light.cssfor consistent GitHub-style code highlighting. The chat UI has been refactored into reusable components such asChatMessageListandChatInputfor better maintainability.docs.astro: Technical documentation page that loads bothgithub-code-highlight.cssandgithub-markdown-light.csstogether with highlight.js for GitHub-style Markdown layout and code highlighting.profile.astro: Account information page, displaying the information of the currently logged-in user.login.astro: Login form page.register.astro: Register form page.404.astro/500.astro: Custom error pages designed to handle Page Not Found (404) and Internal Server Error (500) scenarios. These pages provide clear error messages, user-friendly guidance, and a link to return to the homepage, enhancing the overall user experience.
Page Optimization
Adaptive Layout: Optimizes the display effect of the page on different devices, reduces unnecessary resource loading and layout calculations, and thereby improves performance. Ensures that the page displays well on various screen sizes (e.g., desktop, tablet, mobile), enhancing user experience.
Lazy Loading: All images have lazy loading enabled with a loading animation. For high-definition images, LQIP (Low-Quality Image Placeholder) lazy loading optimization is applied (e.g., the Hero section on the homepage).
Color Scheme
The site offers Ink And Vermilion, Silver And Cobalt, and Graphite And Pine, each in light and dark modes. Six sRGB reference sets map to page and interaction roles through semantic tokens. Existing OKLCH base values remain available but do not override the current palette contract. See Personal Theme Palettes for colors, states, and preference compatibility.
For detailed information, refer to the documentation: 📄 Color Scheme.
Backend
For detailed steps and configurations on backend deployment, please refer to the following project: 📁 Python Cloud Chat. This project provides a complete backend implementation and deployment guide, helping you quickly set up and run backend services.
Nginx Server
The frontend project is automatically built via GitHub Actions and pushed to the
/var/www/htmldirectory on the server, where Nginx serves the static resources.
For detailed Nginx configurations and operational instructions, please check the following repository: 📁 Nginx Conf. This repository includes commonly used Nginx configuration files and examples, making it easy for you to get started.
To fully leverage the hashed assets under
/_astro, add a long-term cache rule in Nginx:
location /_astro/ {
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
}
If you need a more robust server solution, you can refer to my cloud-native project: 📁 Renda Cloud LAB. This project provides a complete cloud-native architecture design, suitable for large-scale and high-availability scenarios.
Documentation
Git Branching & Release Workflow
The project uses a lightweight trunk workflow: documentation and small fixes may use clean
master; dependency upgrades and larger behavior changes use short-lived branches, removed after validation and deployment. Every slice has start and finish checks. No permanentdevelopbranch or mandatory PR per slice is required. Details: Git Workflow.
CI/CD Workflow
deploy.ymldefines the deployment process triggered when code is pushed or merged intomaster, including tag management and environment variable mappings. See: 📄 CI / CD Pipeline.
Operations Maintenance Guide
Frontend validation, deploy-run inspection, deploy-log noise classification, dependency audits, backend/Nginx docs-only sync rules, production read-only checks, and local roadmap maintenance commands are documented in: 📄 Operations Maintenance Guide.
Dependency Security Risk Register
Current dependency audit / Dependabot residual risk, the reason
npm audit fix --forceis disallowed, Astro 7 upgrade boundaries, and security patch escalation thresholds are documented in: 📄 Dependency Security Risk Register.
Astro 7 Upgrade Precheck
The Astro 7 Go/No-Go decision, target package set, Vite 8/Rolldown risks, Sentry source-map checks, CSP gate, Chat Widget smoke scope, and rollback plan are documented in: 📄 Astro 7 Upgrade Precheck.
Astro 6 Migration Precheck
The current baseline, target package set, Node/Vite/Sentry compatibility risks, validation checklist, and rollback plan for the Astro 6 upgrade are documented in: 📄 Astro 6 Migration Precheck.
Frontend Architecture Conventions
Current conventions for Astro pages,
BaseLayout, React Islands, hydration, service boundaries, utilities, style tokens, CSP, and iframe constraints are documented in: 📄 Frontend Architecture Conventions.
Frontend Directory Ownership Map
Directory ownership for
src/components,src/services,src/utils,src/styles,src/content,src/stores, andsrc/controllersis documented in: 📄 Frontend Directory Ownership Map.
Chat Widget Protocol
The same-origin iframe
postMessageready protocol between the floating Chat Widget and/deepseek_chat/, including origin/source checks, loading lifecycle, and refactor constraints, is documented in: 📄 Chat Widget Protocol.
Frontend Experience Platform RFC
Phase 8 planning for browser smoke coverage, hydration safety, theme mode vs palette/accent separation, palette slice order, and interaction standards is documented in: 📄 Frontend Experience Platform RFC.
Interaction Component Standards
Modal, popover/menu, toast/status, loading, disabled/empty/error state, keyboard behavior, focus management, and browser smoke gates are documented in: 📄 Interaction Component Standards.
Human Voice And Personal Expression
Phase 15 rules for bilingual voice, first-person writing, technical terminology, CTAs, evidence boundaries, visual expression, and owner input are documented in: 📄 Human Voice And Personal Expression.
Content And Credibility Positioning
Phase 10 planning for personal-brand content, credibility proof, PersonalWeb project evidence, certifications, work/education narrative, and SEO/GEO alignment is documented in: 📄 Content And Credibility Positioning.
Site Intelligence And Visitor Journey
Phase 11 visitor journey, privacy-safe anonymous events, first-party telemetry boundaries, and Chat Guide public-content scope are documented in: 📄 Site Intelligence And Visitor Journey.
Portfolio Proof And Visitor Conversion
Phase 14 planning for portfolio proof, visitor proof paths, the PersonalWeb case-study surface, homepage proof flow, Chat Guide entry points, and browser/mobile conversion QA is documented in: 📄 Portfolio Proof And Visitor Conversion.
Chat Guide Quality Architecture
Phase 12 documents the Chat Guide public knowledge boundary, answer-quality architecture, backend-owned public knowledge package, and delivery sequence: 📄 Chat Guide Quality Architecture.
SEO / GEO Maintenance
Canonical host, sitemap,
llms.txt,/docs/SSR content, and soft-404 validation rules are documented in: 📄 SEO / GEO Maintenance.
BUG Tracking
For BUGs encountered during frontend development and their solutions, please refer to the following document: 📄 Frontend BUG Tracking Database. This document provides detailed records of BUG descriptions, reproduction steps, solutions, and developer notes, helping you quickly identify and resolve issues.
Development Requirements
For project feature requirements, priorities, and development plans, please refer to the following document: 📄 Project Requirements List. This document lists all requirements for the current version, along with detailed descriptions and development statuses, making it easy for you to track project progress and plan development tasks.
User Authentication and Password Reset Specification
For details on page routing, API contracts, password policies, and security considerations related to user authentication and password reset, please refer to: 📄 Authentication Specification.
Native to Astro + React Migration
The front-end currently adopts an architecture based on Astro + React, following a layered design philosophy. It utilizes GitHub Actions for automated builds and deploys the build artifacts to a specified directory on the server's Nginx.
For detailed steps on upgrading from native frontend, please refer to the following documentation: 📄 Upgrade Plan. This document provides a comprehensive plan and implementation steps for gradually migrating from the old native frontend to a new frontend architecture based on Astro and React.
For detailed steps on setting up the development environment, please refer to the following documentation: 📄 Environment Preparation. This document provides a comprehensive guide on configuring the development environment and initializing an Astro project, ensuring you can smoothly proceed with subsequent development tasks.
Responsive Image System Maintenance
The website uses an automated pipeline to generate responsive images with built-in LQIP placeholders. For maintenance and extension instructions, see 📄 Responsive Image System Maintenance
Error Tracking
Sentry collects runtime and network errors. See 📄 Error Tracking Integration for configuration.
Utilities Reference
src/utils/env.ts, src/utils/langUtils.ts, src/utils/storage.ts, and src/utils/logger.ts provide unified access to environment variables, language parsing, multi-backend storage solutions, and an extensible logging interface.
Docs: 📄 Utilities Reference.
Comprehensive Pre-Commit Guide
For a detailed explanation of the pre-commit hooks, refer to the Comprehensive Pre-Commit Guide.
Style System Description
Introduce the project's CSS architecture, semantic token system, and build process. Demonstrate how
postcss-importinlines the core and utility styles referenced bytheme.cssduring the compilation phase to reduce runtime requests. For details, see: 📄 Style Guide.
🤝 Contribution Guide
- Fork and clone this repository.
- Enter the virtual environment:
# If the virtual environment is not yet installed, run: python -m venv venv source venv/bin/activate - Install dependencies and enable pre-commit:
pip install pre-commit pre-commit install - Before each commit, the hooks will automatically run and perform the following tasks:
- Automatically fix basic formatting issues (trailing whitespace, end-of-file newlines, etc.)
- Update the documentation table of contents and the last updated timestamp
- Synchronize the README file to the assets directory
- Validate static resource naming conventions
- Automatically generate module
index.tsfiles - Perform code formatting and static checks
All commits must pass pre-commit checks. Frontend CI currently validates and deploys after a
masterpush, not on PRs; complete local validation before integration.
🔒 Open Source License
Released under MIT License - free for use and modification. Retain original license notices when redistributing.
📬 Contact
- Contact: Renda Zhang
- 📧 Email: 952402967@qq.com
⏰ Maintainer: @RendaZhang — If this project helps you, please give it a ⭐️!