architecture-domain-analysis
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSubdomain Identification & Bounded Context Analysis
子域识别与限界上下文分析
This skill analyzes codebases to identify subdomains (Core, Supporting, Generic) and suggest bounded contexts following Domain-Driven Design Strategic Design principles.
本技能遵循Domain-Driven Design(DDD)战略设计原则,分析代码库以识别子域(Core、Supporting、Generic)并提出Bounded Context建议。
When to Use
适用场景
Apply this skill when:
- Analyzing domain boundaries in any codebase
- Identifying Core, Supporting, and Generic subdomains
- Mapping bounded contexts from problem space to solution space
- Assessing domain cohesion and detecting coupling issues
- Planning domain-driven refactoring
- Understanding business capabilities in code
在以下场景中应用本技能:
- 分析任意代码库中的领域边界
- 识别Core Domain、Supporting Subdomain和Generic Subdomain
- 将Bounded Context从问题空间映射到解决方案空间
- 评估领域内聚性并检测耦合问题
- 规划领域驱动的重构
- 理解代码中的业务能力
Core Principles
核心原则
Subdomain Classification
子域分类
Core Domain: Competitive advantage, highest business value, requires best developers
- Indicators: Complex business logic, frequent changes, domain experts needed
Supporting Subdomain: Essential but not differentiating, business-specific
- Indicators: Supports Core Domain, moderate complexity, business-specific rules
Generic Subdomain: Common functionality, could be outsourced
- Indicators: Well-understood problem, low differentiation, standard functionality
Core Domain:具备竞争优势,业务价值最高,需要最优秀的开发人员
- 识别指标:复杂的业务逻辑、频繁变更、需要领域专家参与
Supporting Subdomain:必不可少但不具备差异化,具有业务特定性
- 识别指标:支撑Core Domain、中等复杂度、包含业务特定规则
Generic Subdomain:通用功能,可外包实现
- 识别指标:问题已被充分理解、差异化低、标准化功能
Bounded Context
Bounded Context
An explicit linguistic boundary where domain terms have specific, unambiguous meanings.
- Primary nature: Linguistic boundary, not technical
- Key rule: Inside boundary, all Ubiquitous Language terms are unambiguous
- Goal: Align 1 subdomain to 1 bounded context (ideal)
一个明确的语言边界,在该边界内领域术语具有特定、无歧义的含义。
- 本质:语言边界,而非技术边界
- 核心规则:边界内部,所有Ubiquitous Language术语均无歧义
- 目标:理想状态下,1个子域对应1个Bounded Context
Analysis Process
分析流程
Phase 1: Extract Concepts
阶段1:提取概念
Scan codebase for business concepts (not infrastructure):
-
Entities (domain models with identity)
- Patterns: ,
@Entity, domain modelsclass - Focus: Business concepts, not technical classes
- Patterns:
-
Services (business operations)
- Patterns: ,
*Service,*Manager*Handler - Focus: Business logic, not technical utilities
- Patterns:
-
Use Cases (business workflows)
- Patterns: ,
*UseCase,*Command*Handler - Focus: Business processes, not CRUD
- Patterns:
-
Controllers/Resolvers (entry points)
- Patterns: ,
*Controller, API endpoints*Resolver - Focus: Business capabilities, not technical routes
- Patterns:
扫描代码库中的业务概念(非基础设施相关):
-
Entities(具有唯一标识的领域模型)
- 模式:、
@Entity、领域模型类class - 重点:业务概念,而非技术类
- 模式:
-
Services(业务操作)
- 模式:、
*Service、*Manager*Handler - 重点:业务逻辑,而非技术工具类
- 模式:
-
Use Cases(业务流程)
- 模式:、
*UseCase、*Command*Handler - 重点:业务流程,而非CRUD操作
- 模式:
-
Controllers/Resolvers(入口点)
- 模式:、
*Controller、API端点*Resolver - 重点:业务能力,而非技术路由
- 模式:
Phase 2: Group by Ubiquitous Language
阶段2:按Ubiquitous Language分组
For each concept, determine:
Primary Language Context
- What business vocabulary does this belong to?
- Examples:
- ,
Subscription,Invoice→ Billing languagePayment - ,
Movie,Video→ Content languageEpisode - ,
User→ Identity languageAuthentication
Linguistic Boundaries
- Where do term meanings change?
- Same term, different meaning = different bounded context
- Example: "Customer" in Sales vs "Customer" in Support
Concept Relationships
- Which concepts naturally belong together?
- Which share business vocabulary?
- Which reference each other?
针对每个概念,确定:
主要语言上下文
- 该概念属于哪个业务词汇体系?
- 示例:
- 、
Subscription、Invoice→ 计费领域词汇Payment - 、
Movie、Video→ 内容领域词汇Episode - 、
User→ 身份领域词汇Authentication
语言边界
- 术语含义在何处发生变化?
- 同一术语、不同含义 = 不同Bounded Context
- 示例:销售领域的"Customer"与售后领域的"Customer"
概念关联
- 哪些概念自然属于同一组?
- 哪些共享相同的业务词汇?
- 哪些存在相互引用?
Phase 3: Identify Subdomains
阶段3:识别子域
A subdomain has:
- Distinct business capability
- Independent business value
- Unique vocabulary
- Multiple related entities working together
- Cohesive set of business operations
Common Domain Patterns:
- Billing/Subscription: Payments, invoices, plans
- Content/Catalog: Media, products, inventory
- Identity/Access: Users, authentication, authorization
- Analytics: Metrics, dashboards, insights
- Notifications: Messages, alerts, communications
Classify Each Subdomain:
Use this decision tree:
Is it a competitive advantage?
YES → Core Domain
NO → Does it require business-specific knowledge?
YES → Supporting Subdomain
NO → Generic Subdomain子域具备以下特征:
- 独特的业务能力
- 独立的业务价值
- 专属词汇体系
- 多个相关实体协同工作
- 内聚的业务操作集合
常见领域模式:
- 计费/订阅:支付、发票、套餐
- 内容/目录:媒体、产品、库存
- 身份/权限:用户、认证、授权
- 分析:指标、仪表盘、洞察
- 通知:消息、告警、通讯
子域分类:
使用如下决策树:
Is it a competitive advantage?
YES → Core Domain
NO → Does it require business-specific knowledge?
YES → Supporting Subdomain
NO → Generic SubdomainPhase 4: Assess Cohesion
阶段4:评估内聚性
High Cohesion Indicators ✅
- Concepts share Ubiquitous Language
- Concepts frequently used together
- Direct business relationships
- Changes to one affect others in group
- Solve same business problem
Low Cohesion Indicators ❌
- Different business vocabularies mixed
- Concepts rarely used together
- No direct business relationship
- Changes don't affect others
- Solve different business problems
Cohesion Score Formula:
Score = (
Linguistic Cohesion (0-3) + // Shared vocabulary
Usage Cohesion (0-3) + // Used together
Data Cohesion (0-2) + // Entity relationships
Change Cohesion (0-2) // Change together
) / 10
8-10: High Cohesion ✅
5-7: Medium Cohesion ⚠️
0-4: Low Cohesion ❌高内聚性指标 ✅
- 概念共享Ubiquitous Language
- 概念频繁协同使用
- 存在直接业务关联
- 某一概念的变更会影响组内其他概念
- 解决同一业务问题
低内聚性指标 ❌
- 混合不同业务词汇体系
- 概念极少协同使用
- 无直接业务关联
- 某一概念的变更不影响组内其他概念
- 解决不同业务问题
内聚性评分公式:
Score = (
Linguistic Cohesion (0-3) + // Shared vocabulary
Usage Cohesion (0-3) + // Used together
Data Cohesion (0-2) + // Entity relationships
Change Cohesion (0-2) // Change together
) / 10
8-10: High Cohesion ✅
5-7: Medium Cohesion ⚠️
0-4: Low Cohesion ❌Phase 5: Detect Low Cohesion Issues
阶段5:检测低内聚性问题
Rule 1: Linguistic Mismatch
- Problem: Different business vocabularies mixed
- Example: (identity) +
User(billing) in same serviceSubscription - Action: Suggest separation into different bounded contexts
Rule 2: Cross-Domain Dependencies
- Problem: Tight coupling between domains
- Example: Service A directly instantiates entities from Domain B
- Action: Suggest interface-based integration
Rule 3: Mixed Responsibilities
- Problem: Single class handles multiple business concerns
- Example: Service handling both billing and content
- Action: Suggest splitting by subdomain
Rule 4: Generic in Core
- Problem: Generic functionality in core business logic
- Example: Email sending in billing service
- Action: Extract to Generic Subdomain
Rule 5: Unclear Boundaries
- Problem: Cannot determine which domain concept belongs to
- Example: Entity with relationships to multiple domains
- Action: Clarify boundaries, possibly split concept
规则1:语言不匹配
- 问题:混合不同业务词汇体系
- 示例:同一服务中包含(身份领域)和
User(计费领域)Subscription - 行动:建议拆分到不同Bounded Context
规则2:跨域依赖
- 问题:领域间存在强耦合
- 示例:服务A直接实例化领域B的实体
- 行动:建议基于接口的集成方式
规则3:职责混合
- 问题:单个类处理多个业务关注点
- 示例:同时处理计费和内容逻辑的服务
- 行动:建议按子域拆分
规则4:核心域中包含通用功能
- 问题:核心业务逻辑中包含通用功能
- 示例:计费服务中包含邮件发送逻辑
- 行动:提取到Generic Subdomain
规则5:边界模糊
- 问题:无法确定概念所属领域
- 示例:与多个领域存在关联的实体
- 行动:明确边界,可能需要拆分概念
Phase 6: Map Bounded Contexts
阶段6:映射Bounded Context
For each subdomain identified, suggest bounded context:
Bounded Context Characteristics:
- Name reflects Ubiquitous Language
- Contains complete domain model
- Has explicit integration points
- Clear linguistic boundary
Integration Patterns:
- Shared Kernel: Shared model between contexts (use sparingly)
- Customer/Supplier: Downstream depends on upstream
- Conformist: Downstream conforms to upstream
- Anti-corruption Layer: Translation layer between contexts
- Open Host Service: Published interface for integration
- Published Language: Well-documented integration protocol
针对每个识别出的子域,提出Bounded Context建议:
Bounded Context特征:
- 名称反映Ubiquitous Language
- 包含完整领域模型
- 具有明确的集成点
- 清晰的语言边界
集成模式:
- Shared Kernel:上下文间共享模型(谨慎使用)
- Customer/Supplier:下游依赖上游
- Conformist:下游遵循上游规范
- Anti-corruption Layer:上下文间的转换层
- Open Host Service:对外发布的集成接口
- Published Language:文档完善的集成协议
Output Format
输出格式
Domain Map
领域映射
For each domain/subdomain:
markdown
undefined针对每个领域/子域:
markdown
undefinedDomain: {Name}
Domain: {Name}
Type: Core Domain | Supporting Subdomain | Generic Subdomain
Ubiquitous Language: {key business terms}
Business Capability: {what business problem it solves}
Key Concepts:
- {Concept} (Entity|Service|UseCase) - {brief description}
Subdomains (if applicable):
- {Subdomain} (Core|Supporting|Generic)
- Concepts: {list}
- Cohesion: {score}/10
- Dependencies: → {other domains}
Suggested Bounded Context: {Name}Context
- Linguistic boundary: {where terms have specific meaning}
- Integration: {how it should integrate with other contexts}
Dependencies:
- → {OtherDomain} via {interface/API}
- ← {OtherDomain} via {interface/API}
Cohesion Score: {score}/10
undefinedType: Core Domain | Supporting Subdomain | Generic Subdomain
Ubiquitous Language: {key business terms}
Business Capability: {what business problem it solves}
Key Concepts:
- {Concept} (Entity|Service|UseCase) - {brief description}
Subdomains (if applicable):
- {Subdomain} (Core|Supporting|Generic)
- Concepts: {list}
- Cohesion: {score}/10
- Dependencies: → {other domains}
Suggested Bounded Context: {Name}Context
- Linguistic boundary: {where terms have specific meaning}
- Integration: {how it should integrate with other contexts}
Dependencies:
- → {OtherDomain} via {interface/API}
- ← {OtherDomain} via {interface/API}
Cohesion Score: {score}/10
undefinedCohesion Matrix
内聚性矩阵
markdown
undefinedmarkdown
undefinedCross-Domain Cohesion
Cross-Domain Cohesion
| Domain A | Domain B | Cohesion | Issue | Recommendation |
|---|---|---|---|---|
| Billing | Identity | 2/10 | ❌ Direct coupling | Use interface |
| Content | Billing | 6/10 | ⚠️ Usage tracking | Event-based integration |
undefined| Domain A | Domain B | Cohesion | Issue | Recommendation |
|---|---|---|---|---|
| Billing | Identity | 2/10 | ❌ Direct coupling | Use interface |
| Content | Billing | 6/10 | ⚠️ Usage tracking | Event-based integration |
undefinedLow Cohesion Report
低内聚性报告
markdown
undefinedmarkdown
undefinedIssues Detected
Issues Detected
Priority: High
Priority: High
Issue: {description}
- Location: {file/class/method}
- Problem: {what's wrong}
- Concepts: {involved concepts}
- Cohesion: {score}/10
- Recommendation: {suggested fix}
Issue: {description}
- Location: {file/class/method}
- Problem: {what's wrong}
- Concepts: {involved concepts}
- Cohesion: {score}/10
- Recommendation: {suggested fix}
Priority: Medium
Priority: Medium
{similar format}
undefined{similar format}
undefinedBounded Context Map
Bounded Context映射
markdown
undefinedmarkdown
undefinedSuggested Bounded Contexts
Suggested Bounded Contexts
{ContextName}Context
{ContextName}Context
Contains Subdomains:
- {Subdomain1} (Core)
- {Subdomain2} (Supporting)
Ubiquitous Language:
- Term: Definition in this context
Integration Requirements:
- Consumes from: {OtherContext} via {pattern}
- Publishes to: {OtherContext} via {pattern}
Implementation Notes:
- Separate persistence
- Independent deployment
- Explicit API boundaries
undefinedContains Subdomains:
- {Subdomain1} (Core)
- {Subdomain2} (Supporting)
Ubiquitous Language:
- Term: Definition in this context
Integration Requirements:
- Consumes from: {OtherContext} via {pattern}
- Publishes to: {OtherContext} via {pattern}
Implementation Notes:
- Separate persistence
- Independent deployment
- Explicit API boundaries
undefinedBest Practices
最佳实践
Do's ✅
建议✅
- Focus on business language, not code structure
- Let Ubiquitous Language guide boundaries
- Measure cohesion objectively
- Identify clear integration points
- Classify every subdomain (Core/Supporting/Generic)
- Look for linguistic boundaries first
- 聚焦业务语言,而非代码结构
- 以Ubiquitous Language为指导划分边界
- 客观衡量内聚性
- 明确集成点
- 为每个子域分类(Core/Supporting/Generic)
- 优先识别语言边界
Don'ts ❌
禁忌❌
- Don't group by technical layers
- Don't force single global model
- Don't ignore linguistic differences
- Don't couple domains directly
- Don't create contexts by architecture
- Don't eliminate all dependencies (some are necessary)
- 不要按技术层分组
- 不要强制使用单一全局模型
- 不要忽略语言差异
- 不要直接耦合领域
- 不要按架构划分上下文
- 不要消除所有依赖(部分依赖是必要的)
Analysis Checklist
分析检查清单
For Each Concept:
- What business language does it belong to?
- What domain/subdomain is it part of?
- Is it Core, Supporting, or Generic?
- What other concepts does it relate to?
- Are dependencies within same domain?
- Any linguistic mismatches?
For Each Domain:
- What is the Ubiquitous Language?
- What are the key concepts?
- What are the subdomains?
- Which is the Core Domain?
- What are cross-domain dependencies?
- Is internal cohesion high?
- Are boundaries clear?
For Cohesion Analysis:
- Calculate cohesion scores
- Identify low cohesion areas
- Map cross-domain dependencies
- Flag linguistic mismatches
- Note tight coupling
- Suggest boundary clarifications
针对每个概念:
- 它属于哪个业务语言体系?
- 它属于哪个领域/子域?
- 它是Core、Supporting还是Generic类型?
- 它与哪些其他概念相关联?
- 依赖关系是否在同一领域内?
- 存在语言不匹配问题吗?
针对每个领域:
- 其Ubiquitous Language是什么?
- 核心概念有哪些?
- 包含哪些子域?
- 哪个是Core Domain?
- 存在哪些跨域依赖?
- 内部内聚性是否较高?
- 边界是否清晰?
针对内聚性分析:
- 计算内聚性评分
- 识别低内聚性区域
- 映射跨域依赖
- 标记语言不匹配问题
- 记录强耦合情况
- 提出边界明确化建议
Quick Reference
快速参考
Subdomain Decision Tree
子域决策树
Analyze business capability
└─ Is it competitive advantage?
├─ YES → Core Domain
└─ NO → Is it business-specific?
├─ YES → Supporting Subdomain
└─ NO → Generic SubdomainAnalyze business capability
└─ Is it competitive advantage?
├─ YES → Core Domain
└─ NO → Is it business-specific?
├─ YES → Supporting Subdomain
└─ NO → Generic SubdomainCohesion Quick Check
内聚性快速检查
Same vocabulary? → High linguistic cohesion
Used together? → High usage cohesion
Direct relationships? → High data cohesion
Change together? → High change cohesion
All high → Strong subdomain candidate
Mix of high/low → Review boundaries
All low → Likely wrong groupingSame vocabulary? → High linguistic cohesion
Used together? → High usage cohesion
Direct relationships? → High data cohesion
Change together? → High change cohesion
All high → Strong subdomain candidate
Mix of high/low → Review boundaries
All low → Likely wrong groupingBounded Context Signals
Bounded Context信号
Clear boundary signs:
✅ Distinct Ubiquitous Language
✅ Concepts have unambiguous meaning
✅ Different meanings across contexts
✅ Clear integration points
Unclear boundary signs:
❌ Same terms with same meanings everywhere
❌ Concepts used identically across system
❌ No clear linguistic differences
❌ Tight coupling everywhereClear boundary signs:
✅ Distinct Ubiquitous Language
✅ Concepts have unambiguous meaning
✅ Different meanings across contexts
✅ Clear integration points
Unclear boundary signs:
❌ Same terms with same meanings everywhere
❌ Concepts used identically across system
❌ No clear linguistic differences
❌ Tight coupling everywhereAnti-Patterns to Avoid
需避免的反模式
Big Ball of Mud
- Everything connected to everything
- No clear boundaries
- Mixed vocabularies
- Prevention: Explicit bounded contexts
All-Inclusive Model
- Single model for entire business
- Impossible global definitions
- Creates conflicts
- Prevention: Embrace multiple contexts
Mixed Linguistic Concepts
- Different vocabularies in same context
- Example: User/Permission with Forum/Post
- Prevention: Keep linguistic associations
Big Ball of Mud
- 所有组件相互关联
- 无清晰边界
- 混合多种词汇体系
- 预防方式:明确Bounded Context
All-Inclusive Model
- 单一模型覆盖全部业务
- 无法实现全局统一定义
- 引发冲突
- 预防方式:采用多上下文模式
Mixed Linguistic Concepts
- 同一上下文中混合不同词汇体系
- 示例:User/Permission与Forum/Post共存
- 预防方式:保持语言关联一致性
Notes
注意事项
- This is strategic analysis, not tactical implementation
- Focus on WHAT domains exist, not HOW to implement
- Some cross-domain dependencies are normal
- Low cohesion doesn't always mean "bad," it means "needs attention"
- Generic Subdomains naturally have lower cohesion
- Always validate with domain experts when possible
- 这是战略层面的分析,而非战术层面的实现
- 聚焦于“存在哪些领域”,而非“如何实现”
- 部分跨域依赖是正常的
- 低内聚性不总是意味着“错误”,而是“需要关注”
- Generic Subdomain的内聚性自然较低
- 尽可能与领域专家验证分析结果
Validation Criteria
验证标准
Good domain identification has:
- ✅ Clear boundaries with distinct Ubiquitous Language
- ✅ High internal cohesion within domains
- ✅ Explicit cross-domain dependencies
- ✅ Business alignment with capabilities
- ✅ Actionable recommendations for issues
优秀的领域识别应具备:
- ✅ 边界清晰,具有独特的Ubiquitous Language
- ✅ 领域内部内聚性高
- ✅ 跨域依赖明确
- ✅ 与业务能力对齐
- ✅ 针对问题的可落地建议