solid-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSOLID Ruby - Modular Architecture
SOLID Ruby - 模块化架构
Agent Workflow (MANDATORY)
Agent工作流(强制要求)
Before ANY implementation, use to spawn 3 agents:
TeamCreate- fuse-ai-pilot:explore-codebase - Analyze existing architecture
- fuse-ai-pilot:research-expert - Verify Ruby/Rails docs via Context7
- fuse-ai-pilot:sniper - Post-implementation validation
在进行任何实现之前,使用生成3个Agent:
TeamCreate- fuse-ai-pilot:explore-codebase - 分析现有架构
- fuse-ai-pilot:research-expert - 通过Context7验证Ruby/Rails文档
- fuse-ai-pilot:sniper - 实现后验证
DRY - Reuse Before Creating (MANDATORY)
DRY - 复用优先(强制要求)
Before writing ANY new code:
- Grep the codebase for similar modules, services, or logic
- Check shared locations: ,
app/modules/core/services/app/modules/core/contracts/ - If similar code exists -> extend/reuse instead of duplicate
- If code will be used by 2+ features -> create it in
app/modules/core/
在编写任何新代码之前:
- 在代码库中搜索类似的模块、服务或逻辑
- 检查共享位置:、
app/modules/core/services/app/modules/core/contracts/ - 如果存在类似代码 -> 扩展/复用而非重复编写
- 如果代码将被2个及以上功能使用 -> 在中创建
app/modules/core/
Architecture (Modules MANDATORY)
架构(必须使用模块)
| Layer | Location | Max Lines |
|---|---|---|
| Controllers | | 50 |
| Services | | 100 |
| Repositories | | 100 |
| Contracts | | 30 |
| Models | | 50 |
| Shared | | - |
NEVER use flat structure - always
app/app/modules/[feature]/| 层级 | 存放位置 | 最大行数 |
|---|---|---|
| Controllers | | 50 |
| Services | | 100 |
| Repositories | | 100 |
| Contracts | | 30 |
| Models | | 50 |
| 共享代码 | | - |
严禁使用扁平化的结构 - 必须使用
app/app/modules/[feature]/Critical Rules (MANDATORY)
核心规则(强制要求)
| Rule | Value |
|---|---|
| File limit | 100 lines (split at 90) |
| Controllers | < 50 lines, delegate to services |
| Contracts | |
| YARD doc | Every public method documented |
| Frozen string | |
| Concerns | Use for shared behavior (like interfaces) |
| 规则 | 要求 |
|---|---|
| 文件行数限制 | 100行(90行时拆分) |
| Controllers | <50行,委托给服务处理 |
| Contracts | 仅存放在 |
| YARD文档 | 每个公共方法都需编写文档 |
| 冻结字符串 | 每个文件中添加 |
| Concerns | 用于实现共享行为(如接口) |
Reference Guide
参考指南
Concepts
核心概念
| Topic | Reference | When to consult |
|---|---|---|
| SOLID Overview | solid-principles.md | Quick reference |
| SRP | single-responsibility.md | Fat classes |
| OCP | open-closed.md | Adding strategies |
| LSP | liskov-substitution.md | Contracts |
| ISP | interface-segregation.md | Fat modules |
| DIP | dependency-inversion.md | Injection |
| Architecture | architecture-patterns.md | Modular Rails |
| 主题 | 参考文档 | 查阅时机 |
|---|---|---|
| SOLID概述 | solid-principles.md | 快速参考 |
| SRP(单一职责原则) | single-responsibility.md | 处理臃肿类时 |
| OCP(开闭原则) | open-closed.md | 添加策略时 |
| LSP(里氏替换原则) | liskov-substitution.md | 处理契约时 |
| ISP(接口隔离原则) | interface-segregation.md | 处理臃肿模块时 |
| DIP(依赖倒置原则) | dependency-inversion.md | 处理依赖注入时 |
| 架构 | architecture-patterns.md | 模块化Rails开发时 |
Templates
模板
| Template | When to use |
|---|---|
| module.md | Feature module structure |
| service.md | Business logic service |
| contract.md | Duck typing contracts |
| model.md | Active Record model |
| error.md | Custom exceptions |
| test.md | RSpec tests |
| 模板 | 使用场景 |
|---|---|
| module.md | 功能模块结构 |
| service.md | 业务逻辑服务 |
| contract.md | 鸭子类型契约 |
| model.md | Active Record模型 |
| error.md | 自定义异常 |
| test.md | RSpec测试 |
Forbidden
禁止操作
| Anti-Pattern | Fix |
|---|---|
| Files > 100 lines | Split at 90 |
| Business logic in models | Extract to service |
| Fat controllers | Delegate to services |
Flat | Use |
| God classes | Split by responsibility |
| 反模式 | 修复方案 |
|---|---|
| 文件行数>100 | 在90行时拆分 |
| 模型中包含业务逻辑 | 提取到服务中 |
| 臃肿控制器 | 委托给服务处理 |
扁平化 | 使用 |
| 上帝类 | 按职责拆分 |