feature-arch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFeature-Based Architecture Best Practices
基于功能的架构最佳实践
Comprehensive architecture guide for organizing React applications by features, enabling scalable development with independent teams. Contains 42 rules across 8 categories, prioritized by impact from critical (directory structure, imports) to incremental (naming conventions).
这是一份用于按功能组织React应用的全面架构指南,支持独立团队进行可扩展开发。包含8个类别共42条规则,按影响程度从关键(目录结构、导入)到增量(命名规范)排序。
When to Apply
适用场景
Reference these guidelines when:
- Creating new features or modules
- Organizing project directory structure
- Setting up import rules and boundaries
- Implementing data fetching patterns
- Composing components from multiple features
- Reviewing code for architecture violations
在以下场景中参考本指南:
- 创建新功能或模块
- 整理项目目录结构
- 设置导入规则与边界
- 实现数据获取模式
- 组合来自多个功能的组件
- 评审代码以检查架构违规情况
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Directory Structure | CRITICAL | |
| 2 | Import & Dependencies | CRITICAL | |
| 3 | Module Boundaries | HIGH | |
| 4 | Data Fetching | HIGH | |
| 5 | Component Organization | MEDIUM-HIGH | |
| 6 | State Management | MEDIUM | |
| 7 | Testing Strategy | MEDIUM | |
| 8 | Naming Conventions | LOW | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 目录结构 | 关键 | |
| 2 | 导入与依赖 | 关键 | |
| 3 | 模块边界 | 高 | |
| 4 | 数据获取 | 高 | |
| 5 | 组件组织 | 中高 | |
| 6 | 状态管理 | 中 | |
| 7 | 测试策略 | 中 | |
| 8 | 命名规范 | 低 | |
Quick Reference
快速参考
1. Directory Structure (CRITICAL)
1. 目录结构(关键)
- - Organize by feature, not technical type
struct-feature-folders - - Make features self-contained
struct-feature-self-contained - - Use shared layer for truly generic code only
struct-shared-layer - - Keep directory hierarchy flat
struct-flat-hierarchy - - Include only necessary segments
struct-optional-segments - - Separate app layer from features
struct-app-layer
- - 按功能而非技术类型组织代码
struct-feature-folders - - 确保功能具备自包含性
struct-feature-self-contained - - 仅将真正通用的代码放入共享层
struct-shared-layer - - 保持目录层级扁平化
struct-flat-hierarchy - - 仅保留必要的目录段
struct-optional-segments - - 将应用层与功能层分离
struct-app-layer
2. Import & Dependencies (CRITICAL)
2. 导入与依赖(关键)
- - Enforce unidirectional import flow
import-unidirectional-flow - - Prohibit cross-feature imports
import-no-cross-feature - - Export through public API only
import-public-api - - Avoid deep barrel file re-exports
import-avoid-barrel-files - - Use consistent path aliases
import-path-aliases - - Use type-only imports for types
import-type-only
- - 强制单向导入流程
import-unidirectional-flow - - 禁止跨功能导入
import-no-cross-feature - - 仅通过公共API导出
import-public-api - - 避免深层桶文件重导出
import-avoid-barrel-files - - 使用一致的路径别名
import-path-aliases - - 对类型使用仅类型导入
import-type-only
3. Module Boundaries (HIGH)
3. 模块边界(高)
- - Enforce feature isolation
bound-feature-isolation - - Define explicit interface contracts
bound-interface-contracts - - Scope routing to feature concerns
bound-feature-scoped-routing - - Minimize shared state between features
bound-minimize-shared-state - - Use events for cross-feature communication
bound-event-based-communication - - Keep features appropriately sized
bound-feature-size
- - 强制功能隔离
bound-feature-isolation - - 定义明确的接口契约
bound-interface-contracts - - 将路由限定在功能范围内
bound-feature-scoped-routing - - 尽量减少功能间的共享状态
bound-minimize-shared-state - - 使用事件进行跨功能通信
bound-event-based-communication - - 保持功能的合理规模
bound-feature-size
4. Data Fetching (HIGH)
4. 数据获取(高)
- - Keep query functions single-purpose
fquery-single-responsibility - - Colocate data fetching with features
fquery-colocate-with-feature - - Fetch independent data in parallel
fquery-parallel-fetching - - Avoid N+1 query patterns
fquery-avoid-n-plus-one - - Use feature-scoped query keys
fquery-feature-scoped-keys - - Fetch at server component level
fquery-server-component-fetching
- - 确保查询函数单一职责
fquery-single-responsibility - - 将数据获取与功能代码放在一起
fquery-colocate-with-feature - - 并行获取独立数据
fquery-parallel-fetching - - 避免N+1查询模式
fquery-avoid-n-plus-one - - 使用功能限定的查询键
fquery-feature-scoped-keys - - 在服务器组件层进行数据获取
fquery-server-component-fetching
5. Component Organization (MEDIUM-HIGH)
5. 组件组织(中高)
- - Apply single responsibility to components
fcomp-single-responsibility - - Prefer composition over prop drilling
fcomp-composition-over-props - - Separate container and presentational concerns
fcomp-container-presentational - - Use props as feature boundaries
fcomp-props-as-data-boundary - - Colocate styles with components
fcomp-colocate-styles - - Use feature-level error boundaries
fcomp-error-boundaries
- - 对组件应用单一职责原则
fcomp-single-responsibility - - 优先使用组合而非属性透传
fcomp-composition-over-props - - 分离容器组件与展示组件关注点
fcomp-container-presentational - - 将属性作为功能边界
fcomp-props-as-data-boundary - - 将样式与组件放在一起
fcomp-colocate-styles - - 使用功能级别的错误边界
fcomp-error-boundaries
6. State Management (MEDIUM)
6. 状态管理(中)
- - Scope state stores to features
fstate-feature-scoped-stores - - Separate server state from client state
fstate-server-state-separation - - Lift state only as high as necessary
fstate-lift-minimally - - Use context sparingly for feature state
fstate-context-sparingly - - Reset feature state on unmount
fstate-reset-on-unmount
- - 将状态存储限定在功能范围内
fstate-feature-scoped-stores - - 分离服务器状态与客户端状态
fstate-server-state-separation - - 仅在必要时提升状态
fstate-lift-minimally - - 谨慎使用Context管理功能状态
fstate-context-sparingly - - 卸载时重置功能状态
fstate-reset-on-unmount
7. Testing Strategy (MEDIUM)
7. 测试策略(中)
- - Colocate tests with features
test-colocate-with-feature - - Test features in isolation
test-feature-isolation - - Create feature-specific test utilities
test-shared-utilities - - Write integration tests at app layer
test-integration-at-app-layer
- - 将测试与功能代码放在一起
test-colocate-with-feature - - 对功能进行独立测试
test-feature-isolation - - 创建功能专用的测试工具
test-shared-utilities - - 在应用层编写集成测试
test-integration-at-app-layer
8. Naming Conventions (LOW)
8. 命名规范(低)
- - Use domain-driven feature names
name-feature-naming - - Use consistent file naming conventions
name-file-conventions - - Use descriptive export names
name-descriptive-exports
- - 使用领域驱动的功能名称
name-feature-naming - - 使用一致的文件命名规范
name-file-conventions - - 使用具有描述性的导出名称
name-descriptive-exports
How to Use
使用方法
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
- Individual rules:
references/{prefix}-{slug}.md
阅读单个参考文件以获取详细说明和代码示例:
- 章节定义 - 类别结构与影响级别说明
- 规则模板 - 添加新规则的模板
- 单个规则文件:
references/{prefix}-{slug}.md
Related Skills
相关技能
- For feature planning, see skill
feature-spec - For data fetching, see skill
tanstack-query - For React component patterns, see skill
react-19
- 如需功能规划,请参考技能
feature-spec - 如需数据获取相关内容,请参考技能
tanstack-query - 如需React组件模式,请参考技能
react-19
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded:
AGENTS.md包含所有规则扩展说明的完整指南:
AGENTS.md