# ljx338/ai-site-copilot architecture

> Architecture diagram of the GitHub repository ljx338/ai-site-copilot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ljx338/ai-site-copilot
- Repository: https://github.com/ljx338/ai-site-copilot

## Overview

这是一个 AI 建站 Copilot：用户在工作台描述需求，系统识别意图并编排规划、代码生成或修改、项目检查与预览验证，最后展示成功构建的网站。配套能力包括资料解析、图片获取、视觉审查和运行遥测。下图区分工作流编排、项目工作区、预览服务和生成站点运行时；连线依据 README 或提供的源码索引与摘录，未展示实现细节的能力只按文档说明连接。

Main entry points: [`lib/agent-workflow.ts`](https://github.com/ljx338/ai-site-copilot/blob/main/lib/agent-workflow.ts) (意图与 Agent 编排), [`app/api/agent/stream/route.ts`](https://github.com/ljx338/ai-site-copilot/blob/main/app/api/agent/stream/route.ts) (工作流流式 API), [`lib/project-workspace.ts`](https://github.com/ljx338/ai-site-copilot/blob/main/lib/project-workspace.ts) (项目工作区与检查), [`lib/materials.ts`](https://github.com/ljx338/ai-site-copilot/blob/main/lib/materials.ts) (资料解析与索引)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["工作台与 API"]
  node_workbench["Copilot 工作台<br/>[page.tsx]"]
  node_stream_api["工作流流式 API<br/>[route.ts]"]
  node_agent_api["工具调用 Agent API<br/>[route.ts]"]
  node_copilot_api["模型对话 API<br/>[route.ts]"]
  node_preview_api["预览读取 API<br/>[route.ts]"]
end

subgraph group_workflow["建站工作流"]
  node_workflow["意图与 Agent 编排<br/>[agent-workflow.ts]"]
  node_intent["Jev 意图识别<br/>[intent-jev.ts]"]
end

subgraph group_project["项目与预览"]
  node_workspace["项目工作区与检查"]
  node_template["项目模板定义"]
  node_preview_client["预览服务客户端<br/>[preview-client.ts]"]
  node_preview_server["构建与浏览器预览<br/>[preview-server.mjs]"]
end

subgraph group_site["生成站点"]
  node_generated_app["生成站点路由应用<br/>[App.tsx]"]
  node_site_router["站点哈希路由<br/>[router.tsx]"]
  node_site_blocks["页面区块库"]
end

subgraph group_support["扩展能力"]
  node_materials_api["资料 API<br/>[route.ts]"]
  node_materials["资料解析与索引<br/>[materials.ts]"]
  node_materials_brief["资料简报<br/>[materials-brief.ts]"]
  node_telemetry["运行遥测与报告<br/>[telemetry.ts]"]
end

node_user(("网站需求用户"))
node_model(("DeepSeek 模型服务"))
node_jev_service(("TypeSafe Jev 服务"))
node_preview(("生成网站预览"))

node_user -->|"描述需求"| node_workbench
node_workbench -->|"提交并流式接收"| node_stream_api
node_stream_api -->|"编排阶段"| node_workflow
node_stream_api -->|"读取项目文件"| node_workspace
node_stream_api -->|"请求页面检查"| node_preview_client
node_stream_api -->|"处理资料状态"| node_materials
node_stream_api -->|"记录运行阶段"| node_telemetry
node_workflow -->|"识别意图"| node_intent
node_workflow -->|"分析与改写项目"| node_workspace
node_workflow -->|"获取视觉截图"| node_preview_client
node_workflow -->|"读取资料简报"| node_materials_brief
node_workflow -->|"记录工作流阶段"| node_telemetry
node_workflow -->|"调用模型"| node_model
node_intent -->|"优先判断意图"| node_jev_service
node_intent -->|"失败时回退判断"| node_model
node_agent_api -->|"执行文件工具"| node_workspace
node_copilot_api -->|"适配聊天请求"| node_model
node_workspace -->|"初始化项目模板"| node_template
node_preview_client -->|"同步工作区快照"| node_workspace
node_preview_client -->|"请求构建与检查"| node_preview_server
node_preview_server -->|"构建并提供预览"| node_preview
node_preview_api -->|"读取预览项目"| node_workspace
node_workbench -->|"展示网站预览"| node_preview_api
node_template -->|"提供站点骨架"| node_generated_app
node_generated_app -->|"读取当前路由"| node_site_router
node_generated_app -.->|"组合页面区块"| node_site_blocks
node_materials_api -->|"调用资料处理"| node_materials
node_materials -->|"生成资料简报"| node_materials_brief
node_materials -->|"触发页面资料采集"| node_preview_client
node_materials -->|"记录处理事件"| node_telemetry

click node_workbench "https://github.com/ljx338/ai-site-copilot/blob/main/app/page.tsx"
click node_stream_api "https://github.com/ljx338/ai-site-copilot/blob/main/app/api/agent/stream/route.ts"
click node_agent_api "https://github.com/ljx338/ai-site-copilot/blob/main/app/api/agent/route.ts"
click node_copilot_api "https://github.com/ljx338/ai-site-copilot/blob/main/app/api/copilot/route.ts"
click node_preview_api "https://github.com/ljx338/ai-site-copilot/blob/main/app/api/preview/route.ts"
click node_workflow "https://github.com/ljx338/ai-site-copilot/blob/main/lib/agent-workflow.ts"
click node_intent "https://github.com/ljx338/ai-site-copilot/blob/main/lib/intent-jev.ts"
click node_workspace "https://github.com/ljx338/ai-site-copilot/blob/main/lib/project-workspace.ts"
click node_template "https://github.com/ljx338/ai-site-copilot/blob/main/lib/project-template.ts"
click node_preview_client "https://github.com/ljx338/ai-site-copilot/blob/main/lib/preview-client.ts"
click node_preview_server "https://github.com/ljx338/ai-site-copilot/blob/main/scripts/preview-server.mjs"
click node_generated_app "https://github.com/ljx338/ai-site-copilot/blob/main/templates/site-project/src/app/App.tsx"
click node_site_router "https://github.com/ljx338/ai-site-copilot/blob/main/templates/site-project/src/app/router.tsx"
click node_site_blocks "https://github.com/ljx338/ai-site-copilot/tree/main/templates/site-project/src/components/blocks"
click node_materials_api "https://github.com/ljx338/ai-site-copilot/blob/main/app/api/materials/route.ts"
click node_materials "https://github.com/ljx338/ai-site-copilot/blob/main/lib/materials.ts"
click node_materials_brief "https://github.com/ljx338/ai-site-copilot/blob/main/lib/materials-brief.ts"
click node_telemetry "https://github.com/ljx338/ai-site-copilot/blob/main/lib/telemetry.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_workbench,node_stream_api,node_agent_api,node_copilot_api,node_preview_api toneBlue
class node_workflow,node_intent toneAmber
class node_workspace,node_template,node_preview_client,node_preview_server toneMint
class node_generated_app,node_site_router,node_site_blocks toneRose
class node_materials_api,node_materials,node_materials_brief,node_telemetry,node_user,node_model,node_jev_service,node_preview toneIndigo
```

## Components

### 工作台与 API

- [Copilot 工作台](https://github.com/ljx338/ai-site-copilot/blob/main/app/page.tsx): `app/page.tsx`
- [工作流流式 API](https://github.com/ljx338/ai-site-copilot/blob/main/app/api/agent/stream/route.ts): `app/api/agent/stream/route.ts`
- [工具调用 Agent API](https://github.com/ljx338/ai-site-copilot/blob/main/app/api/agent/route.ts): `app/api/agent/route.ts`
- [模型对话 API](https://github.com/ljx338/ai-site-copilot/blob/main/app/api/copilot/route.ts): `app/api/copilot/route.ts`
- [预览读取 API](https://github.com/ljx338/ai-site-copilot/blob/main/app/api/preview/route.ts): `app/api/preview/route.ts`

### 建站工作流

- [意图与 Agent 编排](https://github.com/ljx338/ai-site-copilot/blob/main/lib/agent-workflow.ts): `lib/agent-workflow.ts`
- [Jev 意图识别](https://github.com/ljx338/ai-site-copilot/blob/main/lib/intent-jev.ts): `lib/intent-jev.ts`

### 项目与预览

- [项目工作区与检查](https://github.com/ljx338/ai-site-copilot/blob/main/lib/project-workspace.ts): `lib/project-workspace.ts`
- [项目模板定义](https://github.com/ljx338/ai-site-copilot/blob/main/lib/project-template.ts): `lib/project-template.ts`
- [预览服务客户端](https://github.com/ljx338/ai-site-copilot/blob/main/lib/preview-client.ts): `lib/preview-client.ts`
- [构建与浏览器预览](https://github.com/ljx338/ai-site-copilot/blob/main/scripts/preview-server.mjs): `scripts/preview-server.mjs`

### 生成站点

- [生成站点路由应用](https://github.com/ljx338/ai-site-copilot/blob/main/templates/site-project/src/app/App.tsx): `templates/site-project/src/app/App.tsx`
- [站点哈希路由](https://github.com/ljx338/ai-site-copilot/blob/main/templates/site-project/src/app/router.tsx): `templates/site-project/src/app/router.tsx`
- [页面区块库](https://github.com/ljx338/ai-site-copilot/tree/main/templates/site-project/src/components/blocks): `templates/site-project/src/components/blocks`

### 扩展能力

- [资料 API](https://github.com/ljx338/ai-site-copilot/blob/main/app/api/materials/route.ts): `app/api/materials/route.ts`
- [资料解析与索引](https://github.com/ljx338/ai-site-copilot/blob/main/lib/materials.ts): `lib/materials.ts`
- [资料简报](https://github.com/ljx338/ai-site-copilot/blob/main/lib/materials-brief.ts): `lib/materials-brief.ts`
- [运行遥测与报告](https://github.com/ljx338/ai-site-copilot/blob/main/lib/telemetry.ts): `lib/telemetry.ts`

### Other components

- **网站需求用户**
- **DeepSeek 模型服务**
- **TypeSafe Jev 服务**
- **生成网站预览**

## Connections

- 网站需求用户 → Copilot 工作台: 描述需求 (evidence: `README.md`)
- Copilot 工作台 → 工作流流式 API: 提交并流式接收 (evidence: `README.md`)
- 工作流流式 API → 意图与 Agent 编排: 编排阶段 (evidence: `app/api/agent/stream/route.ts`)
- 工作流流式 API → 项目工作区与检查: 读取项目文件 (evidence: `app/api/agent/stream/route.ts`)
- 工作流流式 API → 预览服务客户端: 请求页面检查 (evidence: `app/api/agent/stream/route.ts`)
- 工作流流式 API → 资料解析与索引: 处理资料状态 (evidence: `app/api/agent/stream/route.ts`)
- 工作流流式 API → 运行遥测与报告: 记录运行阶段 (evidence: `app/api/agent/stream/route.ts`)
- 意图与 Agent 编排 → Jev 意图识别: 识别意图 (evidence: `lib/agent-workflow.ts`)
- 意图与 Agent 编排 → 项目工作区与检查: 分析与改写项目 (evidence: `lib/agent-workflow.ts`)
- 意图与 Agent 编排 → 预览服务客户端: 获取视觉截图 (evidence: `lib/agent-workflow.ts`)
- 意图与 Agent 编排 → 资料简报: 读取资料简报 (evidence: `lib/agent-workflow.ts`)
- 意图与 Agent 编排 → 运行遥测与报告: 记录工作流阶段 (evidence: `lib/agent-workflow.ts`)
- 意图与 Agent 编排 → DeepSeek 模型服务: 调用模型 (evidence: `README.md`)
- Jev 意图识别 → TypeSafe Jev 服务: 优先判断意图 (evidence: `README.md`)
- Jev 意图识别 → DeepSeek 模型服务: 失败时回退判断 (evidence: `README.md`)
- 工具调用 Agent API → 项目工作区与检查: 执行文件工具 (evidence: `app/api/agent/route.ts`)
- 模型对话 API → DeepSeek 模型服务: 适配聊天请求 (evidence: `README.md`)
- 项目工作区与检查 → 项目模板定义: 初始化项目模板 (evidence: `lib/project-workspace.ts`)
- 预览服务客户端 → 项目工作区与检查: 同步工作区快照 (evidence: `lib/preview-client.ts`)
- 预览服务客户端 → 构建与浏览器预览: 请求构建与检查 (evidence: `lib/preview-client.ts`)
- 构建与浏览器预览 → 生成网站预览: 构建并提供预览 (evidence: `README.md`)
- 预览读取 API → 项目工作区与检查: 读取预览项目 (evidence: `app/api/preview/route.ts`)
- Copilot 工作台 → 预览读取 API: 展示网站预览 (evidence: `README.md`)
- 项目模板定义 → 生成站点路由应用: 提供站点骨架 (evidence: `README.md`)
- 生成站点路由应用 → 站点哈希路由: 读取当前路由 (evidence: `templates/site-project/src/app/App.tsx`)
- 生成站点路由应用 → 页面区块库: 组合页面区块 (evidence: `README.md`)
- 资料 API → 资料解析与索引: 调用资料处理 (evidence: `app/api/materials/route.ts`)
- 资料解析与索引 → 资料简报: 生成资料简报 (evidence: `lib/materials.ts`)
- 资料解析与索引 → 预览服务客户端: 触发页面资料采集 (evidence: `lib/materials.ts`)
- 资料解析与索引 → 运行遥测与报告: 记录处理事件 (evidence: `lib/materials.ts`)
