generic-feature-developer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Generic Feature Developer

通用功能开发指南

Guide feature development across any tech stack.
指导任意技术栈下的功能开发工作。

When to Use This Skill

何时使用本Skill

Use for:
  • Adding new features to existing codebase
  • Modifying or extending current systems
  • Planning architectural changes
  • Choosing between implementation approaches
  • Designing data flow for new functionality
Don't use when:
  • Pure UI/styling work → use
    generic-design-system
  • UX design decisions → use
    generic-ux-designer
  • Code review → use
    generic-code-reviewer
适用场景:
  • 为现有代码库新增功能
  • 修改或扩展现有系统
  • 规划架构变更
  • 选择实现方案
  • 为新功能设计数据流
不适用场景:
  • 纯UI/样式工作 → 使用
    generic-design-system
  • UX设计决策 → 使用
    generic-ux-designer
  • 代码评审 → 使用
    generic-code-reviewer

Development Workflow

开发工作流

  1. Understand - Read CLAUDE.md, identify affected files, list constraints
  2. Plan - Choose patterns, design data flow, identify edge cases
  3. Implement - Small testable changes, commit frequently
  4. Test & Document - Write tests, update docs, performance check
  1. 理解需求 - 阅读CLAUDE.md,识别受影响文件,列出约束条件
  2. 规划设计 - 选择架构模式,设计数据流,识别边缘情况
  3. 开发实现 - 拆分可测试的小改动,频繁提交代码
  4. 测试与文档 - 编写测试用例,更新文档,检查性能

Architecture by Project Type

按项目类型划分的架构

Static Sites

静态站点

project/
├── index.html
├── css/           # variables.css, style.css
├── js/            # main.js, utils.js
└── assets/
Patterns: CSS variables, ES modules, event delegation
project/
├── index.html
├── css/           # variables.css, style.css
├── js/            # main.js, utils.js
└── assets/
适用模式: CSS变量、ES模块、事件委托

React/Next.js

React/Next.js

src/
├── components/    # ui/, features/, layout/
├── hooks/
├── stores/
├── services/
└── types/
Patterns: Container/Presentational, custom hooks, Zustand/React Query
src/
├── components/    # ui/, features/, layout/
├── hooks/
├── stores/
├── services/
└── types/
适用模式: 容器/展示组件、自定义hooks、Zustand/React Query

NestJS Backend

NestJS Backend

src/
├── modules/[feature]/
│   ├── feature.module.ts
│   ├── feature.controller.ts
│   ├── feature.service.ts
│   └── dto/
└── common/        # guards, decorators
Patterns: Module organization, DTOs, Guards, Prisma
src/
├── modules/[feature]/
│   ├── feature.module.ts
│   ├── feature.controller.ts
│   ├── feature.service.ts
│   └── dto/
└── common/        # guards, decorators
适用模式: 模块化组织、DTO、Guards、Prisma

Feature Decision Framework

功能决策框架

Scope Assessment (First)

范围评估(首要步骤)

ScopeAction
Single componentImplement directly
Cross-cutting concernDesign interface first
New subsystemCreate architecture doc, get approval
范围行动方案
单一组件直接实现
跨领域关注点先设计接口
新子系统编写架构文档并获得审批

Build vs Integrate

自研 vs 集成第三方库

FactorBuild CustomUse Library
Core to productYes
Commodity featureYes
Tight integration neededYes
Time-criticalYes
Long-term ownershipYes
考量因素自研实现使用第三方库
产品核心功能
通用功能
需要深度集成
时间紧迫
长期维护需求

State Management Selection

状态管理方案选择

ScopeSolution
Component-localuseState/useReducer
Feature-wideContext or Zustand slice
App-wideZustand/Redux store
Server stateReact Query/SWR
Form stateReact Hook Form
范围解决方案
组件内部状态useState/useReducer
功能级状态Context或Zustand切片
应用级状态Zustand/Redux Store
服务端状态React Query/SWR
表单状态React Hook Form

API Design Checklist

API设计检查清单

  • RESTful or GraphQL decision documented
  • Authentication method chosen
  • Error response format standardized
  • Pagination strategy defined
  • Rate limiting considered
  • 已记录RESTful或GraphQL的决策
  • 已选择认证方式
  • 已标准化错误响应格式
  • 已定义分页策略
  • 已考虑限流机制

Common Features

常见功能实现步骤

Adding UI Component

新增UI组件

  1. Create component → 2. Export → 3. Add tests → 4. Document
  1. 创建组件 → 2. 导出组件 → 3. 添加测试 → 4. 编写文档

Adding API Endpoint

新增API接口

  1. Define route → 2. Add validation → 3. Implement service → 4. Test
  1. 定义路由 → 2. 添加验证 → 3. 实现服务逻辑 → 4. 测试

Adding State Management

新增状态管理

  1. Define shape → 2. Create store → 3. Add actions → 4. Connect components
  1. 定义状态结构 → 2. 创建Store → 3. 添加操作方法 → 4. 关联组件

Database Changes

数据库变更

  1. Design schema → 2. Create migration → 3. Update models → 4. Add service
  1. 设计Schema → 2. 创建迁移脚本 → 3. 更新模型 → 4. 新增服务层

Data Flow Patterns

数据流模式

Frontend Data Flow

前端数据流

User Action → Event Handler → State Update → Re-render → UI Feedback
  • Optimistic updates: Update UI immediately, rollback on error
  • Pessimistic updates: Wait for server confirmation
  • Decision: Optimistic for low-risk (likes), pessimistic for high-risk (payments)
用户操作 → 事件处理器 → 状态更新 → 重新渲染 → UI反馈
  • 乐观更新: 立即更新UI,出错时回滚
  • 悲观更新: 等待服务端确认后再更新
  • 决策依据: 低风险操作(如点赞)用乐观更新,高风险操作(如支付)用悲观更新

API Request Flow

API请求流程

Request → Auth Check → Validation → Business Logic → Database → Response
  • Early exit on validation failure
  • Transaction boundaries around multi-step operations
  • Consistent error response format
请求 → 权限校验 → 数据验证 → 业务逻辑 → 数据库操作 → 响应
  • 验证失败时提前终止流程
  • 多步骤操作使用事务边界
  • 保持统一的错误响应格式

Event-Driven Patterns

事件驱动模式

Event TypeApproach
User eventsImmediate feedback
Server eventsWebSocket/SSE for real-time
Background tasksQueue for long operations
事件类型处理方式
用户事件即时反馈
服务端事件使用WebSocket/SSE实现实时推送
后台任务用队列处理长耗时操作

Error Handling Strategy

错误处理策略

Error TypeFrontendBackend
ValidationInline field errors400 + field errors
AuthRedirect to login401/403
Not FoundEmpty state or redirect404
Server ErrorGeneric message + retry500 + log
NetworkOffline indicator + queueN/A
错误类型前端处理方式后端处理方式
验证错误字段内联错误提示400 + 字段错误信息
权限错误重定向至登录页401/403
资源不存在空状态展示或重定向404
服务端错误通用提示+重试按钮500 + 日志记录
网络错误离线状态提示+请求队列N/A

Frontend Pattern

前端实现模式

typescript
try {
  await apiCall();
} catch (error) {
  if (error instanceof ValidationError) showFieldErrors(error.fields);
  else showGenericError();
}
typescript
try {
  await apiCall();
} catch (error) {
  if (error instanceof ValidationError) showFieldErrors(error.fields);
  else showGenericError();
}

Backend Pattern

后端实现模式

typescript
if (err instanceof ValidationError)
  return res.status(400).json({ errors: err.errors });
if (err instanceof AuthError)
  return res.status(401).json({ message: "Unauthorized" });
typescript
if (err instanceof ValidationError)
  return res.status(400).json({ errors: err.errors });
if (err instanceof AuthError)
  return res.status(401).json({ message: "Unauthorized" });

Testing Strategy

测试策略

LayerTypeTools
UIComponentTesting Library
LogicUnitJest, Vitest
APIIntegrationSupertest
E2EEnd-to-endPlaywright
层级测试类型工具
UI层组件测试Testing Library
逻辑层单元测试Jest, Vitest
API层集成测试Supertest
端到端端到端测试Playwright

Performance

性能优化建议

Frontend: Code splitting, lazy loading, memoization, debounce Backend: DB indexing, caching, connection pooling, background jobs
前端: 代码分割、懒加载、记忆化、防抖 后端: 数据库索引、缓存、连接池、后台任务

Feature Implementation Checklist

功能完成检查清单

Before marking feature complete:
  • Works for happy path
  • Error states handled
  • Loading states implemented
  • Edge cases tested
  • TypeScript types complete
  • Tests written
  • Documentation updated
标记功能完成前需确认:
  • 正常流程功能可用
  • 错误状态已处理
  • 加载状态已实现
  • 边缘情况已测试
  • TypeScript类型定义完整
  • 已编写测试用例
  • 文档已更新

See Also

相关链接

  • Code Review Standards - Quality checks
  • Design Patterns - UI patterns
  • generic-design-system
    - For styling and visual consistency
  • generic-ux-designer
    - For UX flow decisions
  • Project
    CLAUDE.md
    - Workflow rules
READ shared standards when:
  • Complex feature design → CODE_REVIEW_STANDARDS.md (architecture section)
  • UI component patterns → DESIGN_PATTERNS.md (component section)
  • 代码评审标准 - 质量检查规范
  • 设计模式 - UI设计模式
  • generic-design-system
    - 用于样式与视觉一致性
  • generic-ux-designer
    - 用于UX流程决策
  • 项目
    CLAUDE.md
    - 工作流规则
何时查阅共享标准:
  • 复杂功能设计 → CODE_REVIEW_STANDARDS.md(架构章节)
  • UI组件模式 → DESIGN_PATTERNS.md(组件章节)