AGENT SKILL

mh-cto-sdlc-domain-model

暂无简介

License 许可
MIT
最近更新
2026-05-13
Stars
★ 2
Forks
0

02 资源文件 2

03 SKILL.md 正文

Phase 1 — Domain Model

You are building the shared language and structure of the problem space.

The domain model is NOT the database schema (that belongs to Phase 4). It is the vocabulary and the rules — the named concepts, their boundaries, their relationships, and the invariants that govern them — that everyone involved in this project must use consistently.

A domain model built here means Phase 2 PRDs, Phase 3 UX, and Phase 4 architecture all speak the same language. Skipping this or doing it loosely is how terminology drift produces contradictory requirements six weeks later.

Load ddd-reference.md before beginning. It contains quick-reference definitions for all DDD patterns used in this skill.

Before You Begin

Load user research synthesis, persona sketches, and project context from persistent_facts. The behavioral patterns and persona workflows from user research are the raw material — they reveal what the domain actually consists of.

Step 1 — Entities vs. Value Objects

Work through the user research output. Ask: "What are the things that exist in this domain?"

For each candidate concept, decide: Entity or Value Object?

Entity — has identity; you can distinguish one instance from another. Has a lifecycle (created → modified → archived). Identity persists even when attributes change. Examples: User, Order, Project, Invoice, Campaign.

Value Object — defined entirely by its attributes. No meaningful identity. Immutable and replaceable — two instances with the same attributes are interchangeable. Examples: Money (amount + currency), Address, DateRange, EmailAddress, Color.

Why it matters: Entities need IDs, lifecycle tracking, and repositories. Value Objects need none of this — they are cloned, not updated. Treating a Value Object as an Entity adds accidental complexity.

For each candidate entity:

  • Does it have identity — can you distinguish one from another beyond its attributes?
  • Does it have a lifecycle — does it get created, modified, completed, archived?
  • Is this a domain concept or an implementation artifact? (Only domain concepts here)
  • Is this project-specific, or a general concept? (Only project-specific here)

Extract the core concepts. Aim for 5–12 Entities. Value Objects are discovered alongside them.

Step 2 — Aggregate Design

Group related Entities and Value Objects into Aggregates. An Aggregate is a cluster of objects that must change together to keep the domain consistent.

Rules for Aggregates:

  1. One Aggregate Root per Aggregate. The root is the single entry point. Nothing outside the aggregate holds a direct reference to internal entities — only to the root.

  2. Cross-aggregate references use IDs only. An Order references a Customer by customerId, not by holding a Customer object. This prevents cascading changes across boundaries.

  3. The Aggregate Root enforces invariants. All business rules that span multiple entities inside the aggregate are enforced by the root — not by individual entities.

  4. Keep Aggregates small. A well-designed aggregate is 1–3 entities. If an aggregate has 7 entities inside it, decompose it. Large aggregates are a design smell.

For each identified aggregate:

  • Name the Aggregate Root (the entity that represents the aggregate externally)
  • Name the internal entities (only accessible through the root)
  • Name the value objects the aggregate contains
  • State the invariant the root enforces (the business rule that spans the aggregate)

Signal that your aggregate boundaries are wrong:

  • You need to load the whole aggregate to do a simple read
  • Two aggregates always change in the same transaction
  • Internal entity IDs are referenced directly from outside

Step 3 — Relationship Mapping

For each pair of related Entities (at the aggregate root level), define the relationship explicitly:

  • Cardinality: one-to-one / one-to-many / many-to-many
  • Direction: which entity "owns" or "contains" the other?
  • Reference type: same aggregate (direct reference) or cross-aggregate (ID reference)?
  • Lifecycle coupling: when one is deleted or archived, what happens to the other?

Write relationships as declarative statements: "An Order belongs to exactly one Customer (by customerId)." "A Customer has zero or many Orders." "An Invoice is produced by exactly one Order."

Surface ambiguous relationships explicitly — these are design decisions, not facts.

Step 4 — Bounded Context Identification

A Bounded Context is the boundary within which a particular model applies. The same word can mean entirely different things in different bounded contexts. "Product" in a catalog context is a different object from "Product" in an order fulfillment context — same word, different model, different rules.

Ask: "Are there places in this system where the same word means different things to different teams, departments, or workflows?"

Signals that a Bounded Context boundary exists:

  • Different teams own different parts of the domain
  • The same term gets "qualified" in conversation ("the billing customer vs. the marketing customer")
  • A change in one area rarely touches the other
  • Two areas have their own separate data lifecycles
  • One area doesn't care about most of what the other tracks

For each Bounded Context identified:

  • Give it a name (noun phrase describing the domain within the boundary)
  • Name the Aggregate Roots that live inside it
  • Name the team or role responsible for it
  • Identify which terms are shared with other contexts (and which are context-specific)

If this is a small early-stage product: You may have one Bounded Context, or two at most. That is correct for this stage. Do not invent boundaries that don't exist yet. Name the one Bounded Context and proceed. Premature context splitting is over-engineering.

Step 5 — Context Map

If more than one Bounded Context was identified, map the relationships between them.

For each pair of Bounded Contexts that share data or communicate:

Relationship pattern When to use
Shared Kernel Two contexts share a small subset of the model. Changes to the shared part require both teams to agree. Use sparingly.
Customer-Supplier Upstream context produces; downstream context consumes. Upstream has power. Downstream requests changes.
Anti-Corruption Layer (ACL) Downstream translates the upstream model into its own model at the boundary. Protects the downstream from upstream changes. Use when the upstream model is messy or doesn't fit your domain.
Open Host Service Upstream context exposes a stable, versioned API (a "published language") that multiple downstream contexts consume.
Conformist Downstream accepts and uses the upstream model as-is. Use only when the upstream is stable and its model is acceptable.

For each context relationship:

  • Name the two contexts
  • Name the pattern
  • Identify who owns the translation/API layer
  • State what data crosses the boundary

This becomes the integration design map in Phase 4 (integration-design).

Step 6 — Strategic Classification

Classify each Bounded Context as one of three strategic types:

Core Domain — the differentiating part of your business. This is why your product exists. Competitors cannot easily replicate this. Invest heavily here — best engineers, most deliberate design, deepest testing.

Supporting Subdomain — necessary to run the business but not differentiating. Useful, but a competitor could build the same thing. Custom-build only if existing solutions don't fit. Apply good-enough engineering.

Generic Subdomain — commodity functionality available in off-the-shelf solutions. Authentication, billing infrastructure, email delivery. Do not custom-build — buy, use a SaaS, or use an open source library. Building generics is one of the most common forms of waste in product development.

For each Bounded Context, state its classification and the reasoning: "The Order Fulfillment context is Core Domain because our differentiation is the real-time order routing algorithm — this is what customers pay for." "The Authentication context is Generic Subdomain — we will use Auth0."

Step 7 — Invariants and Business Rules

For each Aggregate and cross-context boundary, surface the rules that must always be true:

  • "An Order cannot be submitted without at least one LineItem."
  • "An Invoice amount must equal the sum of its LineItems."
  • "A User cannot be deleted if they have active Orders."

Ask: "What can NEVER be true in your domain? What would be data corruption?" Negative constraints are often clearer than positive rules.

These become acceptance criteria in Phase 2 and test cases in Phase 5.

Step 8 — Domain Events

Name the significant state transitions — things that happen that other parts of the system (or other Bounded Contexts) care about.

Format: {Entity}{PastTensedAction} (e.g., OrderPlaced, InvoiceSent, UserDeactivated)

For each domain event:

  • Which Bounded Context does it originate in?
  • Which other Bounded Contexts consume it?
  • Is it consumed within the same aggregate, across aggregates, or across context boundaries?

Cross-context domain events become the integration contracts in Phase 4. Surface them now so Phase 4 doesn't invent them ad hoc.

Step 9 — Update Project Context

Update mh-project-context.md at the project root with all validated domain terms. Follow the CONTEXT-FORMAT schema from project-context-format.md:

For each Entity and Aggregate Root: add a Language entry with definition and Avoid alternatives. For each Bounded Context: add a context entry naming the boundary and its scope. Flag any terms that were used ambiguously in Flagged Ambiguities.

Every term that appears in Phase 2 PRDs must exist in this file. If Phase 2 introduces a term that isn't here, the domain model is incomplete — return here to add it.

Red Flags — STOP and Revisit

  • An Entity has no lifecycle (it never changes state) — likely a Value Object
  • An Aggregate Root has 6+ entities inside it — split the aggregate
  • Two aggregates always change together in the same transaction — they may be one aggregate
  • A "core" entity appears in every Bounded Context — it's a Shared Kernel or you have one context
  • A term means different things in different conversations but no context boundary was drawn
  • Every context is "Core Domain" — reclassify honestly; generics should be bought, not built
  • The domain model reads like a database schema — you've modeled persistence, not the domain

Output Artifact

Save to _mh-output/cto/sdlc/domain-model/{date}_{run}_domain-model.md:

# Domain Model

**Version:** 2.0
**Date:** {date}
**Context:** {project name}

## Bounded Contexts

| Context           | Type                        | Aggregate Roots | Owner       | Strategic classification  |
| ----------------- | --------------------------- | --------------- | ----------- | ------------------------- |
| **{ContextName}** | Core / Supporting / Generic | {root names}    | {team/role} | {rationale, one sentence} |

## Context Map

| Context A  | Relationship pattern                           | Context B  | Translation owner   | Data crossing boundary |
| ---------- | ---------------------------------------------- | ---------- | ------------------- | ---------------------- |
| {ContextA} | Customer-Supplier / ACL / Shared Kernel / etc. | {ContextB} | {who owns the seam} | {what crosses}         |

## Aggregates

| Aggregate Root | Internal Entities  | Value Objects | Invariant enforced           |
| -------------- | ------------------ | ------------- | ---------------------------- |
| **{Root}**     | {entity1, entity2} | {vo1, vo2}    | {the rule the root enforces} |

## Entities vs. Value Objects

| Concept    | Type                  | Definition     | Lifecycle states                                  |
| ---------- | --------------------- | -------------- | ------------------------------------------------- |
| **{Name}** | Entity / Value Object | {one sentence} | {for entities: created → active → archived, etc.} |

## Relationships

{Written as declarative statements, one per line}

- A **{Entity}** belongs to exactly one **{Entity}** (by {entityId})
- A **{Entity}** has zero or many **{Entity}**

## Invariants

| #   | Rule                  | Aggregate / Context | Consequence of violation |
| --- | --------------------- | ------------------- | ------------------------ |
| 1   | {must always be true} | {where it lives}    | {what breaks}            |

## Domain Events

| Event              | Origin context | Consumer contexts    | Crosses context boundary? |
| ------------------ | -------------- | -------------------- | ------------------------- |
| **{EntityAction}** | {context}      | {context1, context2} | Yes / No                  |

## Flagged Ambiguities

| Term   | Was confused with | Resolution                        |
| ------ | ----------------- | --------------------------------- |
| {term} | {other term}      | {clear distinction, one sentence} |

## mh-project-context.md Update Summary

{List the terms added or updated in the context file this session}

Completion

"Domain model complete. [N] bounded contexts, [N] aggregates, [N] entities, [N] value objects, [N] invariants, [N] domain events.

Strategic classification: [N] Core Domain, [N] Supporting, [N] Generic Subdomain.

mh-project-context.md updated with [N] new or revised terms.

Next: /mh-cto-sdlc-journey-map — map the current-state user journey through this domain."

04 同仓库更多 Skills

Imad-Oute
Imad-Oute/MicroHard

mh-vo-vault-brief

Weekly vault intelligence report — health score, pipeline status, OS alignment, and top issues. Use when the user says vault brief, weekly vault report, vault intelligence, run the vault brief, or weekly review brief.

★ 2
Imad-Oute
Imad-Oute/MicroHard

mh-vo-output-bridge

Scan _mh-output/ for new artifacts and create or update corresponding vault entries. Use when the user says run the bridge, sync outputs to vault, output bridge, create vault entries, sync mh-output to vault, or bridge outputs.

★ 2
Imad-Oute
Imad-Oute/MicroHard

mh-vo-moc-builder

Create or update Maps of Content for vault sections and ensure every note is reachable from a MOC. Use when the user says build MOCs, update MOCs, rebuild maps of content, MOC builder, create maps of content, or update the MOCs.

★ 2
Imad-Oute
Imad-Oute/MicroHard

mh-vo-link-architect

Identify missing vault connections and generate precise link recommendations. Use when the user says recommend links, find missing connections, link architect, what should be connected, or identify missing links.

★ 2
Imad-Oute
Imad-Oute/MicroHard

mh-vo-base-builder

Generate Obsidian Bases (.base files) for live database views of vault data. Use when the user says build base views, create base files, generate bases, build live views, or create database views.

★ 2
Imad-Oute
Imad-Oute/MicroHard

mh-vo-taxonomy-enforcer

Audit vault tags and frontmatter, find drift, and apply corrections. Use when the user says fix the taxonomy, enforce tags, fix frontmatter, clean up tags, taxonomy enforcer, or fix tags.

★ 2