This bridges domain-driven design concepts to Rust's type system and ownership model. It walks you through the entity versus value object decision, shows you how to map DDD patterns like aggregates and repositories to Rust structs and traits, and pushes you to think about invariants before writing code. The tables are dense but useful: they map domain concepts to ownership implications, which is exactly the friction point when doing DDD in Rust. Use this when you're modeling business logic and need to decide whether something should be Clone, owned, or wrapped in a newtype. The "trace up to domain constraints, trace down to implementation" structure keeps you from either over-engineering or writing anemic domain models.

skills.sh installs
3.5K
GitHub stars
1.6K
last updated
Aug 21, 2026

Install

$ npx -y skills add actionbook/rust-skills --skill m09-domain --agent claude-code

Installs into .claude/skills of the current project.

Files

Domain Modeling

Layer 2: Design Choices

Core Question

What is this concept's role in the domain?

Before modeling in code, understand:

  • Is it an Entity (identity matters) or Value Object (interchangeable)?
  • What invariants must be maintained?
  • Where are the aggregate boundaries?

Domain Concept → Rust Pattern

Domain ConceptRust PatternOwnership Implication
Entitystruct + IdOwned, unique identity
Value Objectstruct + Clone/CopyShareable, immutable
Aggregate Rootstruct owns childrenClear ownership tree
RepositorytraitAbstracts persistence
Domain EventenumCaptures state changes
Serviceimpl block / free fnStateless operations

Thinking Prompt

Before creating a domain type:

  1. What's the concept's identity?

    • Needs unique identity → Entity (Id field)
    • Interchangeable by value → Value Object (Clone/Copy)
  2. What invariants must hold?

    • Always valid → private fields + validated constructor
    • Transition rules → type state pattern

Sponsors

Details

Repository
github.com/actionbook/rust-skills
Categories
Rust, Design & UI/UX
First seen
May 16, 2026

More from actionbook/rust-skills

All 38

Recommended

More Rust
1actionbook avatarm13-domain-erroractionbook/rust-skillsUse when designing domain error handling. Keywords: domain error, error categorization, recovery strategy, retry, fallback, domain error hierarchy, user-facing 3.5Kskills.sh installs
2actionbook avatarmeta-cognition-parallelactionbook/rust-skillsEXPERIMENTAL: Three-layer parallel meta-cognition analysis. Triggers on: /meta-parallel, 三层分析, parallel analysis, 并行元认知3.2Kskills.sh installs
3actionbook avatardomain-cloud-nativeactionbook/rust-skillsUse when building cloud-native apps. Keywords: kubernetes, k8s, docker, container, grpc, tonic, microservice, service mesh, observability, tracing, metrics, hea3Kskills.sh installs
4zhanghandong avatarm12-lifecyclezhanghandong/rust-skillsm12 lifecycle764skills.sh installs
5zhanghandong avatarm14-mental-modelzhanghandong/rust-skillsm14 mental model751skills.sh installs
6zhanghandong avatarm09-domainzhanghandong/rust-skillsm09 domain750skills.sh installs