$npx -y skills add virgo777/buddyme --skill project-guidelines-example基于真实生产应用程序的项目特定技能(Skill)模板示例。
| 1 | # 项目指南技能(Skill)示例 |
| 2 | |
| 3 | 这是一个项目特定技能(Skill)的示例。请将其作为你自己项目的模板。 |
| 4 | |
| 5 | 基于真实生产应用程序:[Zenith](https://zenith.chat) - AI 驱动的客户挖掘平台。 |
| 6 | |
| 7 | ## 何时使用 |
| 8 | |
| 9 | 在处理其设计的特定项目时参考此技能。项目技能包含: |
| 10 | - 架构概览 |
| 11 | - 文件结构 |
| 12 | - 代码模式 |
| 13 | - 测试要求 |
| 14 | - 部署工作流 |
| 15 | |
| 16 | --- |
| 17 | |
| 18 | ## 架构概览 |
| 19 | |
| 20 | **技术栈:** |
| 21 | - **前端(Frontend)**: Next.js 15 (App Router), TypeScript, React |
| 22 | - **后端(Backend)**: FastAPI (Python), Pydantic 模型 |
| 23 | - **数据库(Database)**: Supabase (PostgreSQL) |
| 24 | - **AI**: 支持工具调用(tool calling)和结构化输出(structured output)的 Claude API |
| 25 | - **部署(Deployment)**: Google Cloud Run |
| 26 | - **测试(Testing)**: Playwright (E2E), pytest (后端), React Testing Library |
| 27 | |
| 28 | **服务:** |
| 29 | ``` |
| 30 | ┌─────────────────────────────────────────────────────────────┐ |
| 31 | │ 前端(Frontend) │ |
| 32 | │ Next.js 15 + TypeScript + TailwindCSS │ |
| 33 | │ 部署于(Deployed): Vercel / Cloud Run │ |
| 34 | └─────────────────────────────────────────────────────────────┘ |
| 35 | │ |
| 36 | ▼ |
| 37 | ┌─────────────────────────────────────────────────────────────┐ |
| 38 | │ 后端(Backend) │ |
| 39 | │ FastAPI + Python 3.11 + Pydantic │ |
| 40 | │ 部署于(Deployed): Cloud Run │ |
| 41 | └─────────────────────────────────────────────────────────────┘ |
| 42 | │ |
| 43 | ┌───────────────┼───────────────┐ |
| 44 | ▼ ▼ ▼ |
| 45 | ┌──────────┐ ┌──────────┐ ┌──────────┐ |
| 46 | │ Supabase │ │ Claude │ │ Redis │ |
| 47 | │ 数据库 │ │ API │ │ 缓存 │ |
| 48 | └──────────┘ └──────────┘ └──────────┘ |
| 49 | ``` |
| 50 | |
| 51 | --- |
| 52 | |
| 53 | ## 文件结构 |
| 54 | |
| 55 | ``` |
| 56 | project/ |
| 57 | ├── frontend/ |
| 58 | │ └── src/ |
| 59 | │ ├── app/ # Next.js App Router 页面 |
| 60 | │ │ ├── api/ # API 路由 |
| 61 | │ │ ├── (auth)/ # 身份验证保护的路由 |
| 62 | │ │ └── workspace/ # 主应用程序工作区 |
| 63 | │ ├── components/ # React 组件 |
| 64 | │ │ ├── ui/ # 基础 UI 组件 |
| 65 | │ │ ├── forms/ # 表单组件 |
| 66 | │ │ └── layouts/ # 布局组件 |
| 67 | │ ├── hooks/ # 自定义 React Hooks |
| 68 | │ ├── lib/ # 实用工具 |
| 69 | │ ├── types/ # TypeScript 定义 |
| 70 | │ └── config/ # 配置 |
| 71 | │ |
| 72 | ├── backend/ |
| 73 | │ ├── routers/ # FastAPI 路由处理器 |
| 74 | │ ├── models.py # Pydantic 模型 |
| 75 | │ ├── main.py # FastAPI 应用程序入口 |
| 76 | │ ├── auth_system.py # 身份验证 |
| 77 | │ ├── database.py # 数据库操作 |
| 78 | │ ├── services/ # 业务逻辑 |
| 79 | │ └── tests/ # pytest 测试 |
| 80 | │ |
| 81 | ├── deploy/ # 部署配置 |
| 82 | ├── docs/ # 文档 |
| 83 | └── scripts/ # 实用脚本 |
| 84 | ``` |
| 85 | |
| 86 | --- |
| 87 | |
| 88 | ## 代码模式 |
| 89 | |
| 90 | ### API 响应格式 (FastAPI) |
| 91 | |
| 92 | ```python |
| 93 | from pydantic import BaseModel |
| 94 | from typing import Generic, TypeVar, Optional |
| 95 | |
| 96 | T = TypeVar('T') |
| 97 | |
| 98 | class ApiResponse(BaseModel, Generic[T]): |
| 99 | success: bool |
| 100 | data: Optional[T] = None |
| 101 | error: Optional[str] = None |
| 102 | |
| 103 | @classmethod |
| 104 | def ok(cls, data: T) -> "ApiResponse[T]": |
| 105 | return cls(success=True, data=data) |
| 106 | |
| 107 | @classmethod |
| 108 | def fail(cls, error: str) -> "ApiResponse[T]": |
| 109 | return cls(success=False, error=error) |
| 110 | ``` |
| 111 | |
| 112 | ### 前端 API 调用 (TypeScript) |
| 113 | |
| 114 | ```typescript |
| 115 | interface ApiResponse<T> { |
| 116 | success: boolean |
| 117 | data?: T |
| 118 | error?: string |
| 119 | } |
| 120 | |
| 121 | async function fetchApi<T>( |
| 122 | endpoint: string, |
| 123 | options?: RequestInit |
| 124 | ): Promise<ApiResponse<T>> { |
| 125 | try { |
| 126 | const response = await fetch(`/api${endpoint}`, { |
| 127 | ...options, |
| 128 | headers: { |
| 129 | 'Content-Type': 'application/json', |
| 130 | ...options?.headers, |
| 131 | }, |
| 132 | }) |
| 133 | |
| 134 | if (!response.ok) { |
| 135 | return { success: false, error: `HTTP ${response.status}` } |
| 136 | } |
| 137 | |
| 138 | return await response.json() |
| 139 | } catch (error) { |
| 140 | return { success: false, error: String(error) } |
| 141 | } |
| 142 | } |
| 143 | ``` |
| 144 | |
| 145 | ### Claude AI 集成 (结构化输出) |
| 146 | |
| 147 | ```python |
| 148 | from anthropic import Anthropic |
| 149 | from pydantic import BaseModel |
| 150 | |
| 151 | class AnalysisResult(BaseModel): |
| 152 | summary: str |
| 153 | key_points: list[str] |
| 154 | confidence: float |
| 155 | |
| 156 | async def analyze_with_claude(content: str) -> AnalysisResult: |
| 157 | client = Anthropic() |
| 158 | |
| 159 | response = client.messages.create( |
| 160 | model="claude-sonnet-4-5-20250514", |
| 161 | max_tokens=1024, |
| 162 | messages=[{"role": "user", "content": content}], |
| 163 | tools=[{ |
| 164 | "name": "provide_analysis", |
| 165 | "description": "Provide structured analysis", |
| 166 | "input_schema": AnalysisResult.model_json_schema() |
| 167 | }], |
| 168 | tool_choice={"type": "tool", "name": "provide_analysis"} |
| 169 | ) |
| 170 | |
| 171 | # 提取工具使用(tool_use)结果 |
| 172 | tool_use = next( |
| 173 | block for block in response.content |
| 174 | if block.type == "tool_use" |
| 175 | ) |
| 176 | |
| 177 | return AnalysisResult(**tool_use.input) |
| 178 | ``` |
| 179 | |
| 180 | ### 自定义 Hooks (React) |
| 181 | |
| 182 | ```typescript |
| 183 | import { useState, useCallback } from 'react' |
| 184 | |
| 185 | interface UseApiState<T> { |
| 186 | data: T | null |
| 187 | loading: boolean |
| 188 | error: string | null |
| 189 | } |
| 190 | |
| 191 | export function useApi<T>( |
| 192 | fetchFn: () => Promise<ApiResponse<T>> |
| 193 | ) { |
| 194 | const [state, setState] = useState<UseApiState<T>>({ |
| 195 | data: null, |
| 196 | loading: false, |
| 197 | error: |