Domain layer rules — zero external dependencies, entities, aggregate roots, value objects, domain events, and repository interfaces. Apply whenever writing or editing code in a Domain project.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Domain Layer Rules?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/makigjuro-domain-layer-rules)
---
name: domain-layer-rules
description: Domain layer rules — zero external dependencies, entities, aggregate roots, value objects, domain events, and repository interfaces. Apply whenever writing or editing code in a Domain project.
user-invocable: false
paths:
- "src/**/Domain/**/*.cs"
---
# Domain Layer Rules
## Zero External Dependencies
- No references to Infrastructure, Host, EF Core, ASP.NET, or any framework
- Only pure C# and domain abstractions -- the Domain csproj has no package or project references
- `Result`/`Error` are NOT in Domain; they live in the shared infrastructure project (`Shared.Infrastructure/Results/`) and are used by Application handlers
## Entities
- Inherit from `Entity<TId>` where `TId` is a strongly-typed value object
- Identity equality based on ID only
- Protected parameterless constructor for EF Core deserialization
- Private or protected constructor taking `TId id` that calls `base(id)`; create instances through static factory methods
## Aggregate Roots
- Inherit from `AggregateRoot<TId>` which extends `Entity<TId>`
- Use static factory methods for creation: `public static Order Create(TenantId tenantId, string description, ...)`
- Factories guard invariants with `ArgumentException`/`ArgumentNullException.ThrowIf...` (programmer errors only); user-input validation belongs in FluentValidation validators in Application
- Raise domain events inside factory methods and state-changing methods: `RaiseDomainEvent(new OrderCreatedEvent(...))`
- Only aggregate roots are directly persisted via repositories
## Value Objects
- Inherit from abstract `ValueObject`
- Implement `GetEqualityComponents()` returning `IEnumerable<object?>`
- Immutable: use `init` properties or readonly fields
- Examples: `OrderId`, `TenantId`, `Money`, `Address`
## Domain Events
- Inherit from `DomainEvent` abstract base class
- Named in past tense: `OrderCreatedEvent`, `PaymentProcessedEvent`
- Raised via `RaiseDomainEvent()` inside aggregate root methods
- Contain only the data needed by consumers (IDs, timestamps, key values)
## Repository Interfaces
- Defined in Domain as ports: `IOrderRepository`, `ICustomerRepository`
- Separate command repos (mutations) from query repos (reads) for CQRS
- Async signatures with CancellationToken