Agent Skillsevrendom/rudel › code-architecture

code-architecture

GitHub

规范代码架构,指导函数排序、服务化重构及模块提取。主张优先使用带依赖注入的函数而非类,避免代理膨胀,明确类与函数的适用场景及共享服务抽取时机,以提升可测试性与树摇效果。

.claude/skills/code-architecture/SKILL.md evrendom/rudel

触发场景

组织代码结构 重构类或服务 设计服务层 将代码提取或移动到文件

安装

npx skills add evrendom/rudel --skill code-architecture -g -y
更多选项

非标准路径

npx skills add https://github.com/evrendom/rudel/tree/main/.claude/skills/code-architecture -g -y

不安装直接使用

npx skills use evrendom/rudel@code-architecture

指定 Agent (Claude Code)

npx skills add evrendom/rudel --skill code-architecture -a claude-code -g -y

安装 repo 全部 skill

npx skills add evrendom/rudel --all -g -y

预览 repo 内 skill

npx skills add evrendom/rudel --list

SKILL.md

Frontmatter
{
    "name": "code-architecture",
    "description": "Code architecture patterns. Use when organizing code, refactoring classes, designing service structure, or extracting\/moving code to new files. Enforces function ordering, service functions over classes, dependency injection.",
    "allowed-tools": [
        "Read",
        "Edit",
        "Grep",
        "Glob"
    ]
}

Code Architecture Standards

CRITICAL: Always apply these patterns when:

  • Creating a new file that will contain multiple functions
  • Extracting code from one file to another
  • Refactoring or reorganizing existing code structure

Function Order (Clean Code)

Organize from high-level to detail:

// 1. Constants, types, schemas at top
const CONFIG = { ... } as const
type Options = { ... }

// 2. Main/entry point functions
async function main() {
  await initialize()
  await processData()
}

// 3. Supporting functions
async function initialize() { ... }
async function processData() { ... }

// 4. Utilities at bottom
function formatDate(date: Date) { ... }

Avoid Bloat Proxy Functions

// ❌ Bad - Pure bloat
class MyWorkflow {
  async getCursorStats() {
    return await cursorService.getCursorStats({ DB: this.env.DB })
  }
}

// ✅ Good - Import and use directly
import { getCursorStats } from './cursor-service'
const stats = await getCursorStats(env)

Prefer Service Functions Over Classes

// ❌ Bad - Unnecessary class wrapper
export class CursorService {
  constructor(private db: D1Database) {}
  async getCursor(shopDomain: string) { ... }
}

// ✅ Good - Individual functions with DI
export async function getCursor(
  shopDomain: string,
  env: { DB: D1Database }
) {
  return await env.DB.prepare('...').bind(shopDomain).first()
}

Benefits

  • Tree-shakable: Only import what you need
  • Testable: Easy to mock dependencies
  • Explicit dependencies
  • No instantiation overhead
  • Functional style

When to Use Classes vs Functions

  • Classes: Complex stateful objects, entities with behavior, inheritance
  • Functions: Simple services, utilities, data transformation, API calls

When to Extract Shared Services

When a new endpoint needs the same orchestration as existing code (queue handlers, cron jobs, other endpoints):

Extract a shared function when:

  • The code is exactly the same (not just similar)
  • Changes should always propagate to both call sites
  • It represents the same semantic operation (e.g., "run an uptime check", "process a payment")

Don't force abstractions when:

  • Code paths are similar but could legitimately diverge
  • The operations might need independent evolution
  • Forcing alignment would create awkward conditional logic
// ❌ Bad - Duplicated orchestration
// In queue handler
const result = await executeCheck(monitor);
await writeResult(result);
await processAlert(result);

// In new endpoint (duplicated!)
const result = await executeCheck(monitor);
await writeResult(result);
await processAlert(result);

// ✅ Good - Shared service function
export async function runUptimeCheck(
  monitor: Monitor,
  env: { DB: D1Database }
): Promise<CheckResult> {
  const result = await executeCheck(monitor);
  await writeResult(result, env);
  await processAlert(result, env);
  return result;
}

// Both queue handler and endpoint call the service
await runUptimeCheck(monitor, env);

Dependency Injection Pattern

Always use last parameter as env object:

export async function myFunction(
  param1: string,
  param2: number,
  env: { DB: D1Database; KV: KVNamespace }
) {
  // Function implementation
}

版本历史

  • 781a16e 当前 2026-07-24 11:32

同 Skill 集合

.claude/skills/api-testing/SKILL.md
.claude/skills/clickhouse-architecture-advisor/SKILL.md
.claude/skills/clickhouse-best-practices/SKILL.md
.claude/skills/clickhouse-js-node-coding/SKILL.md
.claude/skills/clickhouse-query/SKILL.md
.claude/skills/environment-variables/SKILL.md
.claude/skills/library-docs/SKILL.md
.claude/skills/pr-creation/SKILL.md
.claude/skills/testing-bun/SKILL.md
.claude/skills/typescript-standards/SKILL.md
.claude/skills/clickhouse-js-node-troubleshooting/SKILL.md

元信息

文件数
0
版本
59fc2ed
Hash
5c474d0e
收录时间
2026-07-24 11:32

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-07 22:57
浙ICP备14020137号-1 $访客地图$