Back to Ruflo

ruflo-ddd — DDD Reference

plugins/ruflo-ddd/REFERENCE.md

3.6.303.6 KB
Original Source

ruflo-ddd — DDD Reference

Companion reference for domain-modeler and other agents in this plugin. The agent prompt deliberately stays lean per ADR-098 Part 2; this file collects the vocabulary tables, scaffolding catalogs, and AgentDB graph-storage recipes the agent reads on-demand.

DDD building blocks

Building blockPurposeKey rule
EntityObject with identity and lifecycleIdentity-based equality; mutable state
Value ObjectImmutable descriptor without identityEquality by value; side-effect free
Aggregate RootConsistency boundary with invariantsAll mutations go through the root
Domain EventRecord of something that happenedImmutable; past-tense named; carries payload
RepositoryPersistence abstraction per aggregateOne repository per aggregate root
Domain ServiceStateless cross-entity operationsUsed when logic spans multiple aggregates
FactoryComplex object creationEncapsulates construction invariants

Bounded-context relationships

RelationshipUse when
PartnershipTwo contexts succeed or fail together; coordinate releases
Customer-SupplierUpstream context provides; downstream consumes; downstream needs are honored
ConformistDownstream conforms to upstream's model verbatim (no translation)
Anti-Corruption Layer (ACL)Downstream protects itself by translating between ubiquitous languages
Open Host ServiceUpstream publishes a stable protocol for many downstream consumers
Published LanguageShared interchange format (often paired with Open Host Service)

Per-context directory structure

src/<context-name>/
  domain/
    entities/         # Entities and aggregate root
    value-objects/    # Value objects
    events/           # Domain events
    services/         # Domain services
    repositories/     # Repository interfaces
  application/        # Use cases / application services
  infrastructure/     # Repository implementations, ACL adapters
  index.ts            # Public API of the context

AgentDB graph storage

Persist the domain model as a navigable graph so subsequent sessions can traverse it via the pathfinder agent:

bash
# Store bounded context hierarchy
mcp__claude-flow__agentdb_hierarchical-store --parent "domain" \
  --child "context:ordering" --relation "contains"
mcp__claude-flow__agentdb_hierarchical-store --parent "context:ordering" \
  --child "aggregate:order" --relation "contains"

# Store context dependencies
mcp__claude-flow__agentdb_causal-edge --from "context:ordering" \
  --to "context:inventory" --type "depends-on"
mcp__claude-flow__agentdb_causal-edge --from "context:ordering" \
  --to "context:payments" --type "publishes-events-to"

Edge types worth standardizing across a project:

  • depends-on — context needs the other to exist (sync coupling)
  • publishes-events-to — fire-and-forget event flow
  • translates-via-acl-to — anti-corruption layer mediates
  • conforms-to — downstream adopts upstream model verbatim

Naming conventions

  • Aggregate roots: PascalCase singular noun (Order, Customer, Invoice).
  • Domain events: PascalCase past-tense (OrderPlaced, InvoiceVoided, CustomerEmailChanged).
  • Commands: PascalCase imperative (PlaceOrder, VoidInvoice).
  • Repository interfaces: <Aggregate>Repository (OrderRepository).
  • Domain services: <Verb><Noun>Service (PriceQuoteService, InventoryAllocationService).