/frontend:frontend-architecturefrom frontend
前端架構決策——分層合規、元件選型、依賴方向檢查、大型元件重構、狀態管理與資料取得原則、效能策略。附 Vue 3 附錄。Use when making frontend architecture decisions, checking layer violations, or planning refactoring;觸發:「前端架構」「分層違規」「元件該放哪層」「重構這個大元件」「architecture review」「狀態放哪」。
Ships in frontend. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
前端專案的架構決策:分層合規、元件選型、狀態與資料取得、重構策略與效能把關。
先看專案的 package.json dependencies(vue、react、svelte、@angular/core 等)與目錄結構,對照下表載入附錄,並在回報第一行寫「附錄:<檔名>」。
| 偵測到 | 附錄 |
|---|---|
dependencies 有 vue | ${CLAUDE_PLUGIN_ROOT}/references/stacks/vue.md |
react、svelte、@angular/core | 目前沒有附錄,走下方退路 |
沒有對應附錄:照本 skill 的通用方法,加上專案既有程式的寫法(先找 2–3 個同類檔當樣板;有裝 workspace 就照 workspace:convention-first(可選,沒裝就自己 grep 既有實作當樣板))。做完問使用者要不要把這次的寫法整理成新附錄 references/stacks/<stack>.md,回報寫「附錄:無(照既有程式)」。
Presentation → Application → Domain → Infrastructure
違規偵測(路徑依專案調整):
grep -rn "from '.*infrastructure'" <presentation-root>
grep -rn "from '.*api'" <presentation-root>
修正方向:把 presentation 裡直接呼叫 API 的程式,換成 Application 層暴露的 mutation/query/service,元件只拿結果與狀態。範例見附錄。
| 狀態類型 | 放哪 | 原則 |
|---|---|---|
| 伺服器資料(API 回應) | 資料取得層(query cache) | 不複製進全域 store;快取、重試、失效交給 cache 層 |
| 跨頁面共用的 client 狀態 | 全域 store | 只放真正跨頁共用的;有明確所有者 |
| 單一元件/單一頁面狀態 | 元件本地 | 預設選項;不要因為「可能會共用」就上提 |
| URL 可還原的狀態(篩選、分頁) | router query/params | 可分享、可重新整理還原 |
優先序:共享元件庫(若有)> App 本地元件 > UI framework 內建 > 自刻。能用 UI framework 內建就不要自刻。
建立任何新元件前先查:
grep -rn "ComponentName" packages/*/src/ui/ # 共享元件庫(若有)
grep -rn "ComponentName" src/presentation/ # App 本地元件
元件 >300 行、或有 3+ 種違規類型時:
component-logic)(高影響)原則:先修簡單的,讓真正的需求浮現。
所有顏色使用語意化 design token,禁止硬寫 hex 或在元件內依 dark mode 旗標決定樣式。light/dark 差異收斂到 CSS 變數,元件只引用語意 token;主題模式用專案的 theme composable/store/hook 管理,不在元件內散寫判斷。違規偵測指令見附錄。
| 面向 | 目標 |
|---|---|
| 元件復用率 | >80% 走既有元件庫 |
| 分層違規 | 零 |
| 型別覆蓋 | 100% strict |
| i18n 覆蓋 | 100% 可翻譯 |
| 主題合規 | 100% 語意化 token |
| 互動延遲 | <100ms |
| 清單 >50 筆 | 啟用虛擬捲動 |
需要獨立審查或補測試時,叫 lifecycle:reviewer/lifecycle:tester(可選);沒裝就用 general-purpose subagent,附上角色說明(審查:分層、型別、i18n、主題;測試:元件與邏輯單元測試)。派工 prompt 要帶上 §0 載入的附錄絕對路徑(${CLAUDE_PLUGIN_ROOT} 展開後),agent 才讀得到;general-purpose 退路也一樣。
component-logic:業務邏輯抽出元件i18n:翻譯 key 組織與違規偵測runtime-debug:執行中前端的除錯What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub kerryhuang/plugharbor --plugin frontend4 skills in this plugin
/component-logic把業務邏輯從前端元件抽成可復用單元的做法——單一職責、reactive 輸入、side effect 隔離、清楚介面型別。附 Vue 3 composable 寫法附錄。Use when extracting business logic over 50 lines or creating reusable component logic;觸發:「抽 composable」「抽 hook」「這段邏輯太長要拆」「可復用邏輯」「component logic」。/i18n前端 i18n 違規偵測與翻譯 key 組織——系統性掃出硬寫字串、依 feature 而非元件組織 key、處理 template literal 的部分硬寫。附 Vue 3 附錄。Use when refactoring pages, creating new features, or fixing i18n violations;觸發:「i18n 違規」「這頁還有硬寫中文」「翻譯 key 怎麼組織」「補 i18n」「國際化」。/runtime-debug用瀏覽器 DevTools(chrome-devtools MCP)除錯執行中的前端——console error 分流、API request 檢查、前端 state 檢視、realtime 連線、視覺回歸、表單互動、router。附 Vue 3 附錄(Vue DevTools、Pinia、TanStack Query 檢視)。Use when debugging the running frontend via browser DevTools;觸發:「除錯執行中的前端」「頁面壞了幫我看」「看 console error」「檢查 API 請求」「inspect state」。Other plugins' skills for the same job