Jelajahi Sumber

docs: 添加 README.md 和 CLAUDE.md,精简 docker-compose.yml 仅保留前端服务,修复 lint-staged prettier 命令路径问题

kinglee 2 minggu lalu
induk
melakukan
e05b438b5c
3 mengubah file dengan 260 tambahan dan 41 penghapusan
  1. 149 0
      CLAUDE.md
  2. 110 25
      README.md
  3. 1 16
      docker-compose.yml

+ 149 - 0
CLAUDE.md

@@ -0,0 +1,149 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## Project Overview
+
+**GPUStack UI** — Dashboard/management UI for [GPUStack](https://github.com/gpustack/gpustack), a GPU model serving and management platform. Features include model deployment, playground (chat/embedding/rerank/image/speech), resource management, cluster management, benchmark, and access control.
+
+## Tech Stack
+
+- **Framework**: UmiJS Max 4.x (`@umijs/max`) — enterprise React framework with built-in routing, state, request, access, locale, and layout plugins
+- **UI Library**: Ant Design 6.x (`antd`) + Pro Components (`@ant-design/pro-components`)
+- **Core UI package**: `@gpustack/core-ui` — shared internal UI components
+- **State Management**: Jotai (atomic state via `src/atoms/`)
+- **HTTP Client**: Axios via Umi request layer
+- **Build Tool**: Webpack (via Umi)
+- **Language**: TypeScript
+- **Package Manager**: pnpm
+- **Styling**: Less + CSS modules + styled-components + antd-style
+
+## Key Commands
+
+```bash
+# Install dependencies
+pnpm install
+
+# Start dev server (http://localhost:9000)
+npm run dev          # or: pnpm dev
+
+# Production build
+npm run build
+
+# Preview build output
+npm run preview
+
+# Format code
+npm run format
+
+# Check locale files
+npm run check:locales
+```
+
+Environment variables:
+
+- `PROXY_HOST` — API proxy target for dev server
+- `ENABLE_ENTERPRISE` — enable enterprise features
+- `ENABLE_PLAYGROUND` — enable playground section (default: true)
+- `APP_TITLE` — custom app title
+
+## Project Structure
+
+```
+config/                 # Umi build configuration
+  config.ts             # Main config (proxy, build, plugins, routes)
+  routes.ts             # Route definitions (main entry for navigation structure)
+  routes.extensions.ts  # Build-time route extensions
+  proxy.ts              # Dev proxy configuration
+  plugins.ts            # Webpack plugins (compression, monaco)
+  keep-alive.ts         # Route keep-alive configuration
+  mfsu.extensions.ts    # MFSU exclusions
+src/
+  app.tsx               # App entry: getInitialState, request config, plugin initialization
+  access.ts             # Role-based access control (canSeeAdmin, canSeeOrgAdmin, etc.)
+  request-config.tsx    # Axios interceptors, error handling, 401 redirect
+  global.tsx            # Global setup (dayjs plugins)
+  global.less           # Global styles
+  atoms/                # Jotai atomic state (user, settings, models, clusters, etc.)
+  config/               # Runtime config (settings, theme, hotkeys, breakpoints)
+  layouts/              # Custom layout system (sidebar, menu, logo, error boundary)
+  pages/                # Page components (feature-based subdirectories)
+    _components/        # Shared page-level components
+    dashboard/          # Dashboard
+    playground/         # Chat, embedding, rerank, images, speech
+    llmodels/           # Model catalog, user models, deployments
+    model-routes/       # Model routing
+    usage/              # Usage statistics
+    maas-provider/      # Model providers
+    benchmark/          # Benchmark tests
+    gpu-service/        # GPU service (instances, templates, storage, public keys)
+    resources/          # Workers, GPUs, backends, modelfiles
+    cluster-management/ # Clusters, credentials
+    users/              # User management
+    api-keys/           # API key management
+    login/              # Login page
+    profile/            # User profile
+  components/           # Global shared components
+  plugins/              # Plugin system (manager, enterprise-ready, locale merger)
+  services/             # API service layer (minimal, most API calls are inline)
+  locales/              # i18n locale files
+  assets/               # Images, logos, provider logos
+  request.extensions.ts # Build-time request interceptor hooks (empty by default)
+  access.extensions.ts  # Build-time access extension hooks (empty by default)
+```
+
+## Architecture Patterns
+
+### Routing
+
+- Hash-based routing (`history.type: 'hash'`)
+- Routes defined in `config/routes.ts` with icon, access control, and keep-alive support
+- Route extensions applied via `config/routes.extensions.ts` for build-time plugin injection
+
+### Authentication & Access Control
+
+- Umi `access` plugin with predicate-based role checks
+- Key predicates: `canSeeAdmin`, `canSeeOrgAdmin`, `canManageCurrentOrg`, `canSeeUser`, `canDelete`, `canLogin`
+- 401 responses trigger logout → redirect to `/login`
+- First-login flow redirects admin to `/resources/workers`
+
+### State Management
+
+- **Jotai atoms** in `src/atoms/` for global state (user info, settings, pagination, route cache, etc.)
+- **Umi `initialState`** for currentUser and fetchUserInfo
+- Persistent storage via `setAtomStorage` / `clearAtomStorage` utilities
+
+### HTTP Requests
+
+- Base URL: `/v2` (GPUSTACK_API_BASE_URL)
+- OpenAI-compatible APIs: `/v1`
+- Special paths (`/auth`, `/v1`, `/version`, `/proxy`, `/update`) bypass the API base URL
+- Request/response interceptors in `src/request-config.tsx`
+- Extension point: `src/request.extensions.ts` (empty by default, populated by build-time tooling)
+
+### Plugin System
+
+- `GPUStackPluginManager` in `src/plugins/manager.ts`
+- Plugins register with `onAppInit` and `onAppReady` lifecycle hooks
+- Enterprise plugin loaded via `src/plugins/enterprise-ready.ts`
+- Build-time extensions populate `*.extensions.ts` files
+
+### Layout
+
+- Custom layout in `src/layouts/` with sidebar, menu, logo, right panel
+- Error boundary and exception pages
+- Render links and extra render hooks for plugin injection
+
+### Internationalization
+
+- Umi locale plugin with `en-US` default
+- Ant Design locale auto-synced
+- Locale files in `src/locales/`
+
+## Important Notes
+
+- The `.extensions.ts` files (`routes.extensions.ts`, `request.extensions.ts`, `access.extensions.ts`, etc.) are **generated at build time** by external tooling — do not edit them directly
+- Monaco Editor is integrated via `@monaco-editor/react` and `monaco-editor-webpack-plugin`
+- XTerm.js used for terminal/console output
+- Markdown rendering with `react-markdown` + GFM + KaTeX math support
+- The project uses hash routing, so all routes have `#/` prefix in the browser

+ 110 - 25
README.md

@@ -1,55 +1,140 @@
 # GPUStack UI
 
-UI for [GPUStack](https://github.com/gpustack/gpustack).
+GPUStack 平台的前端管理界面,提供 GPU 模型部署与管理、Playground 调试、资源监控、集群管理等一站式能力。
 
-## Installation
+## 技术栈
 
-1. [Nodejs](https://nodejs.org/en) 16.0+(with NPM)
+- **框架**: [UmiJS Max 4.x](https://umijs.org/)
+- **UI**: [Ant Design 6.x](https://ant.design/) + Pro Components
+- **状态管理**: [Jotai](https://jotai.org/)
+- **语言**: TypeScript
+- **包管理**: pnpm
 
-If you're on Mac
+## 快速开始
 
-```
-brew install node
-```
+### 环境要求
 
-2. [pnpm](https://pnpm.io/installation#using-npm)
+- Node.js 18+
+- pnpm 9.3+
 
+### 安装依赖
+
+```bash
+pnpm install
 ```
-npm install -g pnpm
+
+### 开发调试
+
+```bash
+npm run dev
+# 默认访问 http://localhost:9000
 ```
 
-3. Setup
+如需代理到指定后端,设置环境变量:
 
+```bash
+PROXY_HOST=http://your-backend-host:port npm run dev
 ```
-git clone https://github.com/gpustack/gpustack-ui/
+
+### 生产构建
+
+```bash
+npm run build
 ```
 
-4. Install dependencies
+构建产物输出至 `dist/` 目录。
 
+### 预览构建产物
+
+```bash
+npm run preview
 ```
-cd gpustack-ui
-pnpm install
+
+### 代码格式化
+
+```bash
+npm run format
 ```
 
-## Usage
+## Docker 部署
 
-1. Run development server (at http://localhost:9000)
+项目提供 Dockerfile 和 docker-compose.yml,支持一键容器化部署。
 
+### 构建镜像
+
+```bash
+docker compose up -d --build
 ```
-npm run dev
-```
 
-2. build release
+构建后的镜像名为 `maas-base-ui:latest`。
+
+### 指定端口与环境变量
+
+创建 `.env.prod` 文件并自定义配置:
 
+```env
+UI_PORT=8080
+APP_TITLE=成都网讯MaaS底座
+ENABLE_PLAYGROUND=false
 ```
-npm run build
+
+运行:
+
+```bash
+docker compose --env-file .env.prod up -d --build
 ```
 
-## Bugs & Issues
+### Nginx 代理规则
 
-- Please submit [bugs and issues](https://github.com/gpustack/gpustack/issues) with a label `ui`
+容器内 Nginx 默认将 `/v1`、`/v2`、`/auth`、`/version`、`/proxy`、`/update`、`/cli`、`/grafana` 等路径代理到后端 `backend:80`,部署时确保 backend 服务与前端容器在同一 Docker 网络中。
 
-## Links
+## 项目结构
+
+```
+config/                 # Umi 构建配置(路由、代理、插件等)
+src/
+  app.tsx               # 应用入口:初始化、请求配置、插件加载
+  access.ts             # 权限控制逻辑
+  request-config.tsx    # 请求拦截器与错误处理
+  atoms/                # Jotai 原子状态
+  config/               # 运行时配置(主题、设置、快捷键等)
+  layouts/              # 自定义布局(侧边栏、菜单、Logo)
+  pages/                # 页面组件(按功能划分)
+    dashboard/          # 仪表盘
+    playground/         # Playground(聊天、Embedding、Rerank、图像、语音)
+    llmodels/           # 模型目录、用户模型、部署管理
+    resources/          # Worker、GPU、后端、模型文件
+    cluster-management/ # 集群与凭据管理
+    users/              # 用户管理
+    api-keys/           # API 密钥管理
+    benchmark/          # 基准测试
+    gpu-service/        # GPU 服务(实例、模板、存储、SSH 密钥)
+  components/           # 全局共享组件
+  plugins/              # 插件系统(生命周期、企业版扩展)
+  locales/              # 国际化语言包
+  assets/               # 图片资源
+  services/             # API 服务层
+Dockerfile              # 多阶段构建(Node 18 构建 + Nginx 部署)
+docker-compose.yml      # 容器编排配置
+nginx.conf              # Nginx 反向代理配置
+```
 
-- Official website: https://gpustack.ai/
-- Documents: https://docs.gpustack.ai/latest/overview/
+## 环境变量
+
+| 变量名              | 说明                        | 默认值           |
+| ------------------- | --------------------------- | ---------------- |
+| `APP_TITLE`         | 应用标题(左上角显示)      | 成都网讯MaaS底座 |
+| `ENABLE_PLAYGROUND` | 是否启用 Playground 菜单    | true             |
+| `PROXY_HOST`        | 开发环境后端代理地址        | -                |
+| `UI_PORT`           | Docker 部署时的容器映射端口 | 8080             |
+
+## 其他命令
+
+| 命令                    | 说明            |
+| ----------------------- | --------------- |
+| `npm run dev`           | 启动开发服务器  |
+| `npm run build`         | 生产构建        |
+| `npm run preview`       | 预览构建产物    |
+| `npm run format`        | 格式化代码      |
+| `npm run check:locales` | 检查语言文件    |
+| `npm run setup`         | 初始化 Umi 项目 |

+ 1 - 16
docker-compose.yml

@@ -6,22 +6,7 @@ services:
       args:
         APP_TITLE: ${APP_TITLE:-成都网讯MaaS底座}
         ENABLE_PLAYGROUND: ${ENABLE_PLAYGROUND:-true}
-    image: maas-base-ui:latest
+    image: maas-base-uilatest
     ports:
       - "${UI_PORT:-8080}:80"
     restart: unless-stopped
-    depends_on:
-      - backend
-
-  backend:
-    image: gpustack/gpustack:latest
-    ports:
-      - "80:80"
-      - "30080:30080"
-      - "10161:10161"
-    volumes:
-      - gpustack-data:/var/lib/gpustack
-    restart: unless-stopped
-
-volumes:
-  gpustack-data: