Create a new domain bounded context with aggregates, commands, events, and handlers

MITAuto-check passedDevelopment

Install Domain

skills CLI
$ npx skills add RailsEventStore/ecommerce --skill domain -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install RailsEventStore/ecommerce domain --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/RailsEventStore/ecommerce.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/domain .claude/skills/domain && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
domain
GitHub stars
507
Token cost
~2.6k tokens
SKILL.md length
697 words
Files
1
Skills in repo
8
Repo updated
First seen
Licence
MIT

At a glance

Create a new domain bounded context with aggregates, commands, events, and handlers

  • Works in 10 steps: Gather requirements → Scaffold the domain directory → Create boilerplate files → …
  • Tasks that involve Domain-driven design
  • SKILL.md covers When to use, Reference, Step-by-step process and Aggregate design principles, plus 1 more section
  • Calls make and bundle; reaches rubygems.org

What it does

Domain is an agent skill from RailsEventStore/ecommerce. Create a new domain bounded context with aggregates, commands, events, and handlers

Its SKILL.md is about 2.6k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Domain-driven design. The repository describes itself as: Application with CQRS and Event Sourcing built on Rails and Rails Event Store. The licence is MIT.

When your agent uses it

  • Tasks that involve Domain-driven design

Example prompts

  • “/domain”

Workflow steps

10 steps, taken from the step headings in SKILL.md.

  1. Gather requirements
  2. Scaffold the domain directory
  3. Create boilerplate files
  4. Write tests first (TDD)
  5. Create commands
  6. Create events
  7. Create aggregate root
  8. Create command handlers
  9. Create module entry point with Configuration
  10. Run verification

What it can do on your machine

Read from SKILL.md and the folder at commit 42c6c23. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • make
    • bundle

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • rubygems.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Domain loads about 2.6k tokens when it runs. Until then it costs about 23 tokens; SKILL.md has 697 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~23
When it runs · the whole SKILL.md, loaded when a task matches
~2.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from RailsEventStore/ecommerce at commit 42c6c23, republished under its MIT licence (© RailsEventStore). 697 words, ~2,601 tokens.

Download SKILL.mdSave it as .claude/skills/domain/SKILL.md (or your agent's skills folder).
name
domain
description
Create a new domain bounded context with aggregates, commands, events, and handlers

Domain Builder

When to use

Use this skill when asked to create a new domain module (bounded context) in the domains/ directory, or to add new aggregates/commands/events to an existing domain.

Reference

Two patterns exist in the codebase:

  • Simple (todo): Everything in a single file lib/{domain}/todo.rb
  • Structured (crm, ordering, etc.): Separate files for commands, events, aggregates, and handlers

Use the structured pattern for any non-trivial domain. The simple pattern is only for demos.

Step-by-step process

1. Gather requirements

Before writing any code, clarify:

  • The domain name (snake_case, e.g. project_management, ticketing)
  • The aggregates — what are the core entities? (e.g. Customer, Deal, Contact)
  • For each aggregate: what commands can be issued and what events do they produce?
  • What business rules does the aggregate enforce? (invariants, state guards)
2. Scaffold the domain directory

Create the directory structure:

domains/{domain_name}/
├── Gemfile
├── Makefile
├── .mutant.yml
├── lib/
│   ├── {domain_name}.rb              # Module entry point + Configuration
│   └── {domain_name}/
│       ├── commands/
│       │   └── {command_name}.rb      # One file per command
│       ├── events/
│       │   └── {event_name}.rb        # One file per event
│       ├── {aggregate_name}.rb        # Aggregate root
│       └── {aggregate_name}_service.rb # Command handlers
└── test/
    ├── test_helper.rb
    └── {test_name}_test.rb            # One file per test concern
3. Create boilerplate files

Gemfile:

ruby
source "https://rubygems.org"

eval_gemfile "../../infra/Gemfile.test"
gem "infra", path: "../../infra"

Makefile:

makefile
install:
	@bundle install

test:
	@bundle exec ruby -e "require \"rake/rake_test_loader\"" test/*_test.rb

mutate:
	@RAILS_ENV=test bundle exec mutant run

.PHONY: install test mutate

.mutant.yml:

yaml
requires:
  - ./test/test_helper
integration: minitest
usage: opensource
coverage_criteria:
  process_abort: true
matcher:
  subjects:
    - {DomainModule}*
  ignore:
    - {DomainModule}::Configuration#call
4. Write tests first (TDD)

Create test/test_helper.rb:

ruby
require "minitest/autorun"
require "mutant/minitest/coverage"

require_relative "../lib/{domain_name}"

module DomainModule
  class Test < Infra::InMemoryTest
    def before_setup
      super
      Configuration.new.call(event_store, command_bus)
    end

    private

    def some_helper(id, attribute)
      run_command(SomeCommand.new(entity_id: id, attribute: attribute))
    end
  end
end

Create test files — one per logical concern (e.g. test/registration_test.rb, test/assignment_test.rb):

ruby
require_relative "test_helper"

module DomainModule
  class SomeTest < Test
    cover "DomainModule*"

    def test_entity_can_be_created
      id = SecureRandom.uuid
      create_entity(id, "some value")

      expected_event = EntityCreated.new(data: { entity_id: id, attribute: "some value" })
      assert_events("DomainModule::Entity$#{id}", expected_event) do
        create_entity(id, "some value")
      end
    end

    def test_cannot_create_same_entity_twice
      id = SecureRandom.uuid
      create_entity(id, "value")

      assert_raises(Entity::AlreadyExists) do
        create_entity(id, "value")
      end
    end

    private

    def create_entity(id, value)
      run_command(CreateEntity.new(entity_id: id, attribute: value))
    end
  end
end

Test conventions:

  • Use cover "DomainModule*" for mutation testing
  • Use run_command(...) to dispatch commands (provided by Infra::InMemoryTest)
  • Use assert_events(stream, expected_event) { block } to verify events
  • Use assert_raises(ErrorClass) { block } for invariant violations
  • Extract command-calling helpers as private methods
  • Test both happy paths and invariant violations (double-creation, invalid state transitions)
5. Create commands

One file per command in lib/{domain_name}/commands/:

ruby
module DomainModule
  class CreateEntity < Infra::Command
    attribute :entity_id, Infra::Types::UUID
    attribute :name, Infra::Types::String
    alias aggregate_id entity_id
  end
end

Command conventions:

  • Inherit from Infra::Command
  • Use Infra::Types::UUID for UUIDs, Infra::Types::String for strings
  • Add alias aggregate_id {entity_id_field} so the handler can use command.aggregate_id
6. Create events

One file per event in lib/{domain_name}/events/:

ruby
module DomainModule
  class EntityCreated < Infra::Event
    attribute :entity_id, Infra::Types::UUID
    attribute :name, Infra::Types::String
  end
end

Event conventions:

  • Inherit from Infra::Event
  • Events are named in past tense (Created, Updated, Assigned, Promoted)
  • Include the aggregate ID and any relevant data
7. Create aggregate root
ruby
module DomainModule
  class Entity
    include AggregateRoot

    AlreadyExists = Class.new(StandardError)
    NotFound = Class.new(StandardError)

    def initialize(id)
      @id = id
    end

    def create(name)
      raise AlreadyExists if @created
      apply EntityCreated.new(data: { entity_id: @id, name: name })
    end

    def update_name(name)
      raise NotFound unless @created
      apply EntityNameUpdated.new(data: { entity_id: @id, name: name })
    end

    private

    on EntityCreated do |event|
      @created = true
    end

    on EntityNameUpdated do |event|
    end
  end
end

Aggregate conventions:

  • include AggregateRoot
  • State tracked via instance variables (@created, @completed, etc.)
  • Business rules enforced via raise before apply
  • on EventClass do |event| blocks update internal state
  • Events that don't change state still need empty on blocks
  • Custom error classes as Class.new(StandardError)
8. Create command handlers

One handler class per command, grouped in a service file:

ruby
module DomainModule
  class OnCreateEntity
    def initialize(event_store)
      @repository = Infra::AggregateRootRepository.new(event_store)
    end

    def call(command)
      @repository.with_aggregate(Entity, command.aggregate_id) do |entity|
        entity.create(command.name)
      end
    end
  end

  class OnUpdateEntityName
    def initialize(event_store)
      @repository = Infra::AggregateRootRepository.new(event_store)
    end

    def call(command)
      @repository.with_aggregate(Entity, command.aggregate_id) do |entity|
        entity.update_name(command.name)
      end
    end
  end
end

Handler conventions:

  • Each handler wraps @repository.with_aggregate(AggregateClass, id) { |agg| ... }
  • Handler names describe the action: OnRegistration, OnSetCustomer, OnPromoteCustomerToVip
  • All in one _service.rb file per aggregate, or separate files for clarity
9. Create module entry point with Configuration

Create lib/{domain_name}.rb:

ruby
require "infra"
require_relative "{domain_name}/commands/create_entity"
require_relative "{domain_name}/commands/update_entity_name"
require_relative "{domain_name}/events/entity_created"
require_relative "{domain_name}/events/entity_name_updated"
require_relative "{domain_name}/entity_service"
require_relative "{domain_name}/entity"

module DomainModule
  class Configuration
    def call(event_store, command_bus)
      command_bus.register(CreateEntity, OnCreateEntity.new(event_store))
      command_bus.register(UpdateEntityName, OnUpdateEntityName.new(event_store))
    end
  end
end

Configuration conventions:

  • require "infra" first, then all domain files
  • Each command registered with its handler
  • Handlers receive event_store in constructor
10. Run verification
bash
cd domains/{domain_name}
bundle install
make test          # All tests pass
make mutate        # 100% mutation score

Then from the project root:

bash
make test          # Ensure nothing is broken globally
Show full SKILL.md (305 more words)Show less

Aggregate design principles

Keep aggregates as small as possible. An aggregate is often a small state machine with two or three states. Adding new methods to an existing aggregate is a smell — it signals a cohesion problem. Before adding a method, ask: "Is this really the same concept, or is it a new aggregate?"

Associations between entities are often aggregates on their own. For example, "Contact assigned to Company" is not a method on Contact — it's a separate ContactCompanyAssignment aggregate with its own lifecycle. The Contact aggregate handles contact registration and attributes. The assignment is a different concern.

Passing strings or "data" into aggregate methods is a smell. Aggregate methods should ideally receive only IDs (UUIDs). If you're passing names, descriptions, or other data, consider whether the aggregate is doing too much. Small smells are acceptable — the goal is to avoid ActiveRecord-like bloat where aggregates accumulate dozens of setter methods.

Don't validate other aggregates from command handlers. Avoid patterns like @event_store.read.stream("Crm::Entity$#{id}").last or raise NotFound in command handlers. This couples the handler to stream naming conventions and makes it responsible for validating external state. Instead, trust the caller (controllers provide valid IDs from read model dropdowns) or model the relationship as its own aggregate that can enforce its own invariants.

Signs an aggregate is too big:

  • More than 4-5 command methods
  • Instance variables tracking unrelated concerns (e.g., @name, @email, @company_id)
  • Command handlers needing to check other aggregate streams
  • The on blocks are growing in number

Key conventions

  • Commands are imperative: RegisterCustomer, AddTodo, AssignDeal
  • Events are past tense: CustomerRegistered, TodoAdded, DealAssigned
  • Aggregates enforce business rules (invariants) before applying events
  • UUIDs for all entity IDs
  • Infra::Types::UUID and Infra::Types::String for typed attributes
  • Test-first TDD, 100% mutation score
  • Each domain is fully independent — no cross-domain imports
  • Domains only communicate via events (consumed by read models and process managers in apps)

© RailsEventStore, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/domain of RailsEventStore/ecommerce.

Open the folder on GitHubat commit 42c6c23

Compare with similar skills

Domain next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Domain compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Domain this skillRailsEventStore/ecommerce507—~2.6kAutomated safety check: PassMIT
Scaffoldcodewithmukesh/dotnet-claude-kit755—~1.7kAutomated safety check: PassMIT
Moai Workflow Testingmodu-ai/moai-adk1.2k—~2.7kAutomated safety check: PassApache-2.0
Domain Modelingfossasia/eventyay-interpretation1.6k31 repos~821Automated safety check: PassApache-2.0
Architecture Governancezai-org/ZCode7.6k—~1.2kAutomated safety check: PassApache-2.0
Evolutionary Modular Architecturetech-leads-club/agent-skills7k—~3.7kAutomated safety check: PassCC-BY-4.0

Similar skills

  • Scaffold

    codewithmukesh/dotnet-claude-kit

    Architecture-aware feature scaffolding for .NET 10 projects.

    755 GitHub stars~1.7k tokensUpdated 2 mo ago
    DevelopmentAuto-check passed
  • Moai Workflow Testing

    modu-ai/moai-adk

    A skill your agent uses when writing tests, measuring coverage, or running characterization, performance, or PR-review QA.

    1.2k GitHub stars~2.7k tokensUpdated today
    DevelopmentAuto-check passed
  • Domain Modeling

    fossasia/eventyay-interpretation

    Build and sharpen a project's domain model. An agent skill from fossasia/eventyay-interpretation.

    1.6k GitHub starsUsed in 31 repos~821 tokens
    DevelopmentAuto-check passed
  • Apply the repository's architecture policy to code changes by generating a bounded context package, checking module and layer boundaries, and reporting baseline-aware violations.

    7.6k GitHub stars~1.2k tokensUpdated 10 days ago
    DevelopmentAuto-check passed
  • Evolutionary Modular Architecture

    tech-leads-club/agent-skills

    Guides design of modular-monolith platforms with DDD, flat-by-aggregate modules, anti-corruption layers, outbox events and resilience, plus an architecture document with SVG diagrams.

    7k GitHub stars~3.7k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Domain Modeling

    brim-borium/spotify_sdk

    Build and sharpen a project's domain model. An agent skill from brim-borium/spotify_sdk.

    166 GitHub starsUsed in 5 repos~806 tokens
    DevelopmentAuto-check passed

More from RailsEventStore/ecommerce

All 8 skills in this repo
  • Commit

    RailsEventStore/ecommerce

    Create atomic git commits following project conventions. An agent skill from RailsEventStore/ecommerce.

    507 GitHub stars~767 tokensUpdated 18 days ago
    Auto-check passed
  • Controller

    RailsEventStore/ecommerce

    Create a controller with commands, read model queries, routes, and integration tests

    507 GitHub stars~1.9k tokensUpdated 18 days ago
    Auto-check passed
  • New App

    RailsEventStore/ecommerce

    Scaffold a new Rails app with event sourcing, following project conventions (todomvc as reference)

    507 GitHub stars~3.1k tokensUpdated 18 days ago
    Auto-check passed
  • New Feature

    RailsEventStore/ecommerce

    Plan a new feature end-to-end — impact analysis across all layers, start-from-the-middle slicing into deployable steps, then delegating to /domain, /read-model, /controller skills

    507 GitHub stars~1.6k tokensUpdated 18 days ago
    Auto-check passed
  • Read Model

    RailsEventStore/ecommerce

    Build a new read model following project conventions (event handlers, tests, migration, configuration)

    507 GitHub stars~3k tokensUpdated 18 days ago
    Auto-check passed
  • Upgrade Rails

    RailsEventStore/ecommerce

    Upgrade Rails framework to a newer version following the smooth upgrade methodology

    507 GitHub stars~976 tokensUpdated 18 days ago
    Auto-check passed

Questions about Domain

What does Domain do?

Create a new domain bounded context with aggregates, commands, events, and handlers. Domain is an agent skill from RailsEventStore/ecommerce.

When should I use Domain?

Domain fits situations like: tasks that involve Domain-driven design.

How do I install Domain in Claude Code?

Run `npx skills add RailsEventStore/ecommerce --skill domain -a claude-code`. Or copy the skill folder (.claude/skills/domain in RailsEventStore/ecommerce) into .claude/skills/domain in your project. Claude Code loads it when a task matches its description.

How do I install Domain in Codex?

Run `npx skills add RailsEventStore/ecommerce --skill domain -a codex`. Or copy the skill folder (.claude/skills/domain in RailsEventStore/ecommerce) into .agents/skills/domain in your project. Codex loads it when a task matches its description.

Can I use Domain in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add RailsEventStore/ecommerce --skill domain -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/domain, .gemini/skills/domain, .github/skills/domain and .opencode/skills/domain in your project.

What does Domain need to run?

Going by SKILL.md and its folder, Domain needs the command-line tools its instructions call (make and bundle).

Does Domain access the network?

SKILL.md names 1 domain. In commands or code: rubygems.org; the agent is likely to contact it when it follows the instructions. This is read from the text; nothing was executed.

Is Domain safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Domain use?

Domain is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Domain use?

About 2.6k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Domain?

Skills that share tags, products or a category with Domain: Scaffold (codewithmukesh/dotnet-claude-kit, 755 stars), Moai Workflow Testing (modu-ai/moai-adk, 1.2k stars), Domain Modeling (fossasia/eventyay-interpretation, 1.6k stars) and Architecture Governance (zai-org/ZCode, 7.6k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Domain?

RailsEventStore (a GitHub organization) maintains it in RailsEventStore/ecommerce, which has 507 GitHub stars. The repository holds 8 skills in this directory. The repository was last updated on September 21, 2026.

Source: RailsEventStore/ecommerce on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.