Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
davidyichengwei avatar

Bp Component Design

  • 1 installs
  • 158 repo stars
  • Updated March 25, 2026
  • davidyichengwei/agentic-engineering-framework

Provides component-level design principles covering class/module design, interface design, data models, concurrency, and error handling for system design and code review.

About

A reference of SOLID principles, design patterns, interface and data-model design, concurrency models, and error handling used during the component-design phase of a spec. A developer uses it when detailing component design or evaluating component quality in code review.

  • SOLID checkpoints, design patterns, and anti-pattern table
  • Interface versioning, concurrency models, and error-classification guidance

Bp Component Design by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #984 of 1,352 Code Review & Quality skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/davidyichengwei/agentic-engineering-framework --skill bp-component-design

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars158
Last updatedMarch 25, 2026
Repositorydavidyichengwei/agentic-engineering-framework

What it does

Provides component-level design principles covering class/module design, interface design, data models, concurrency, and error handling for system design and code review.

Files

SKILL.mdMarkdownGitHub ↗

组件设计

使用场景workflow-system-design skill 在讨论 spec.md 4.2 组件设计 时加载本 skill。

第一性原理

组件设计的本质:把架构方案转化为可实现的代码结构,定义清晰的职责边界和交互契约。

---

4.2.1 核心类/模块设计

SOLID 原则

原则含义检查点
Single Responsibility类只做一件事这个类能用一句话描述吗?
Open/Closed对扩展开放,对修改关闭新增功能是否需要改现有代码?
Liskov Substitution子类可替换父类子类是否违反父类契约?
Interface Segregation接口精简专一调用方是否被迫依赖不需要的方法?
Dependency Inversion依赖抽象而非具体高层模块是否直接依赖低层实现?

设计原则

原则说明
组合优于继承继承紧耦合,组合松耦合易替换
面向接口编程依赖抽象接口,而非具体实现
最小知识原则避免链式调用暴露内部结构

常用设计模式

类型模式适用场景
创建型Factory封装对象创建逻辑
创建型Builder分步构建复杂对象
结构型Adapter接口转换
结构型Decorator动态添加职责
行为型Strategy可替换算法
行为型Template Method定义算法骨架,子类实现细节
行为型Iterator数据流处理、管道模式

Checklist

  • [ ] 类职责是否单一清晰?
  • [ ] 继承层次是否合理(不超过 2-3 层)?
  • [ ] 依赖是否指向抽象而非具体实现?
  • [ ] 模块边界是否明确?

---

4.2.2 接口设计

接口设计关注对外暴露的 public API,内部接口在 4.2.1 中定义。

设计原则

原则说明
最小化只暴露必要的接口,隐藏实现细节
一致性命名、参数顺序、错误处理风格统一
向后兼容接口变更不破坏现有调用方
自描述接口签名本身能表达意图

接口定义要素

// 示例:接口定义应包含
class StorageEngine {
public:
    // 1. 方法签名:清晰的命名和参数
    // 2. 参数约束:哪些可为空?取值范围?
    // 3. 返回值:成功/失败如何表示?
    // 4. 错误码:可能返回哪些错误?
    // 5. 线程安全:是否可并发调用?
    
    /**
     * @brief 写入 KV 对
     * @param key 键,不能为空
     * @param value 值
     * @return Status::OK 成功
     *         Status::KeyTooLong key 超过 64KB
     *         Status::IOError 写入失败
     * @thread_safety 线程安全
     */
    virtual Status Put(const Slice& key, const Slice& value) = 0;
};

版本兼容策略

变更类型兼容性处理方式
新增方法向后兼容直接添加
新增可选参数向后兼容提供默认值
删除方法不兼容先废弃,下个大版本删除
修改参数类型不兼容新增方法,废弃旧方法

Checklist

  • [ ] 接口是否最小化(不暴露不必要的方法)?
  • [ ] 参数和返回值是否清晰定义?
  • [ ] 错误码是否完整列出?
  • [ ] 线程安全性是否说明?
  • [ ] 是否考虑了向后兼容?

---

4.2.3 数据模型

何时需要:涉及数据存储、Schema 变更、新增数据结构时。

设计要素

要素需要明确
Schema字段定义、类型、约束
索引查询模式决定索引设计
编码格式序列化方式(protobuf/flatbuffers/自定义)
存储位置存哪里?生命周期?

Schema 演进

策略说明
向前兼容新代码能读旧数据
向后兼容旧代码能读新数据(需谨慎设计)
迁移计划如何从旧 Schema 迁移到新 Schema?

Checklist

  • [ ] Schema 字段是否完整定义?
  • [ ] 索引是否满足查询需求?
  • [ ] 是否考虑了 Schema 演进?
  • [ ] 迁移/回滚方案是否明确?

---

4.2.4 并发模型

何时需要:涉及多线程、异步操作、共享状态时。

设计要素

要素需要明确
线程模型哪些线程?职责是什么?
共享状态哪些数据被多线程访问?
同步机制用什么锁?锁的粒度?
异步边界哪里是同步/异步的边界?

常见模式

模式适用场景
单线程 + 事件循环I/O 密集、低延迟
线程池 + 任务队列CPU 密集、可并行
Actor 模型状态隔离、消息传递
读写锁读多写少

Checklist

  • [ ] 线程模型是否清晰?
  • [ ] 共享状态是否明确,保护机制是否合理?
  • [ ] 是否有死锁风险?
  • [ ] 锁粒度是否合适(不过粗也不过细)?

---

4.2.5 错误处理

何时需要:涉及外部依赖、I/O 操作、可能失败的场景时。

设计要素

要素需要明确
失败模式可能发生哪些错误?
错误表示错误码 / 异常 / Status 对象?
重试策略哪些错误可重试?退避策略?
恢复机制失败后如何恢复到一致状态?

错误分类

类型示例处理方式
可重试网络超时、临时不可用指数退避重试
不可重试参数错误、权限不足直接返回错误
致命错误数据损坏、不变量被破坏记录日志 + panic/abort

重试策略

// 指数退避 + 抖动
int delay_ms = min(base_delay * (1 << retry_count), max_delay);
delay_ms += random(0, delay_ms * 0.1);  // 10% jitter

Checklist

  • [ ] 所有可能的失败模式是否列出?
  • [ ] 错误表示方式是否统一?
  • [ ] 可重试 vs 不可重试是否区分?
  • [ ] 失败后的清理/恢复逻辑是否考虑?

---

反模式

反模式问题改进
God Class类承担过多职责拆分为多个小类
Feature Envy方法大量访问其他类数据移动到数据所在类
过度设计不需要的抽象层简单优先,按需抽象
忽略错误吞掉错误不处理明确处理或向上传播
锁粒度过粗整个操作加大锁缩小临界区

---

与其他 Skill 协同

场景加载 Skill
涉及分布式场景(网络、一致性、故障)bp-distributed-systems
涉及性能优化bp-performance-optimization

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.