skills/rust-project-structure/SKILL.md
Rust 專案目錄結構。用於 workspace 組織、crate 拆分、模組層級、binary/library 分離、設定與測試擺放。
npx skillsauth add vincent119/ai-rules-kit rust-project-structureInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
my-app/
├── Cargo.toml
├── src/
│ ├── main.rs # 進入點,僅負責啟動與組裝
│ ├── lib.rs # 公開 API,re-export 模組
│ ├── config.rs # 設定載入與驗證
│ ├── error.rs # 統一錯誤型別
│ ├── routes/ # HTTP handler(依資源分檔)
│ │ ├── mod.rs
│ │ ├── users.rs
│ │ └── health.rs
│ ├── services/ # 業務邏輯
│ │ ├── mod.rs
│ │ └── user_service.rs
│ ├── repositories/ # 資料存取層
│ │ ├── mod.rs
│ │ └── user_repo.rs
│ ├── models/ # 領域模型與 DTO
│ │ ├── mod.rs
│ │ └── user.rs
│ └── middleware/ # 中介層(auth、logging、tracing)
│ ├── mod.rs
│ └── auth.rs
├── tests/ # 整合測試
│ └── api_tests.rs
├── migrations/ # 資料庫 migration
├── config/ # 環境設定檔
│ ├── default.toml
│ └── production.toml
└── benches/ # Benchmark
└── throughput.rs
大型專案拆分為多個 crate,各自單一職責:
my-platform/
├── Cargo.toml # [workspace] 定義
├── crates/
│ ├── api/ # HTTP API binary
│ │ ├── Cargo.toml
│ │ └── src/
│ │ ├── main.rs
│ │ └── routes/
│ ├── core/ # 領域邏輯 library(無 I/O 依賴)
│ │ ├── Cargo.toml
│ │ └── src/
│ │ ├── lib.rs
│ │ ├── models/
│ │ ├── services/
│ │ └── error.rs
│ ├── db/ # 資料庫存取層
│ │ ├── Cargo.toml
│ │ └── src/
│ │ ├── lib.rs
│ │ └── repositories/
│ ├── common/ # 共用工具(tracing、config、types)
│ │ ├── Cargo.toml
│ │ └── src/
│ │ └── lib.rs
│ └── cli/ # CLI 工具 binary
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
├── tests/ # 跨 crate 整合測試
├── config/
└── migrations/
Workspace Cargo.toml:
[workspace]
resolver = "2"
members = ["crates/*"]
[workspace.dependencies]
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
anyhow = "1"
tracing = "0.1"
my-lib/
├── Cargo.toml
├── src/
│ ├── lib.rs # 公開 API,#[doc(inline)] re-export
│ ├── builder.rs
│ ├── error.rs
│ └── internal/ # pub(crate) 內部模組
│ ├── mod.rs
│ └── parser.rs
├── tests/ # 整合測試(以使用者角度測試公開 API)
│ ├── basic_usage.rs
│ └── edge_cases.rs
├── examples/ # 使用範例(cargo run --example)
│ └── basic.rs
└── benches/
└── parse_bench.rs
// src/lib.rs - 頂層 re-export
pub mod models;
pub mod services;
pub mod error;
pub use error::AppError;
pub use models::User;
// src/models/mod.rs - 模組內 re-export
mod user;
mod order;
pub use user::{User, UserId};
pub use order::{Order, OrderStatus};
main.rs 只做啟動與組裝;業務邏輯放 lib.rs 或子模組routes/、services/、repositories/、models/tests/;單元測試放同檔 #[cfg(test)] mod tests[workspace.dependencies]pub(crate);僅公開必要 APIconfig/;migration 放 migrations/examples/;benchmark 放 benches/tools
基於 SLA/SLO 量化評估事故影響的計算模型與業務影響矩陣。適用於「SLA 影響」、「SLO 違反」、「影響評估」、「營收損失估算」、「Error Budget」、「可用性計算」、「事故成本評估」等量化事故業務影響的任務。強化 impact-assessor 的評估能力。注意:事故原因分析與改善規劃不在此技能範圍內。
research
根因分析(RCA)方法論詳細指南。提供 5 Whys、Fishbone 圖、Fault Tree Analysis、變更分析等結構化 RCA 技術,以及認知偏誤防範清單。適用於「根因分析」、「RCA」、「5 Whys」、「魚骨圖」、「Fault Tree」、「原因分析方法論」、「變更分析」等事故原因分析任務。強化 root-cause-investigator 的分析能力。注意:時間軸重建與改善規劃不在此技能範圍內。
testing
事故事後分析(Postmortem)完整流程。協調 7 個執行階段:資訊收集 → 時間軸重建 → 根因分析 → 影響評估 → 改善規劃 → 報告審查 → 整合報告,最終產出完整的 Postmortem 報告。適用於「寫事故報告」、「post-incident 分析」、「RCA 報告」、「事故時間軸整理」、「建立改善措施」等請求。注意:即時 Incident Response(on-call)、監控系統設定、告警配置不在此技能範圍內。
content-media
投影片版面模式庫。提供 20 種投影片類型的最佳版面配置、格線系統、色彩與字型設計 Token。適用於「投影片版面」、「Slide Layout」、「設計系統」、「格線」、「字型」、「色彩規範」等投影片視覺設計任務。強化 visual-designer 的設計能力。注意:PPT/Keynote 檔案直接輸出不在此技能範圍內。