agentleFS
Hive-AcademyHive-Academy/ptah-extension/.claude/skills/ddd-architecture/SKILL.md

ddd-architecture

Skill29 starsChanged 2 months agoMITView on GitHub

Domain-Driven Design for complex business domains. Use when deciding whether DDD is warranted, defining bounded contexts, aggregates, entities and value objects, applying CQRS or domain events, or organizing a domain layer.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If this skill is invoked from saas-workspace-initializer Step a2, the Round 1 discovery answers (jobs-to-be-done, candidate domains, MVP …

    line 14
  2. Very specific:

    Read references/entities-aggregates.md for the full pattern — the Entity and EntityId base classes, the invariant guards, and the …

    line 98
  3. Very specific:

    Read references/value-objects.md for the ValueObject base class and further worked examples (Email, Address, DateRange, Percentage).

    line 121
  4. Distinctive:

    Before implementing DDD, assess with user:

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Domain-Driven Design Architecture

Strategic and tactical DDD patterns for NestJS + Angular applications.

When to Engage User

DDD is highly context-dependent. ALWAYS discuss with user before implementing.

If this skill is invoked from saas-workspace-initializer Step a2, the Round 1 discovery answers (jobs-to-be-done, candidate domains, MVP scope) are already available — use them and do not re-ask the equivalent questions below. Ask only what those answers leave open.

Discovery Questions

  1. Domain Complexity
    • "What are your core business entities and their relationships?"
    • "Which operations are most critical to get right?"
    • "Are there complex business rules or validations?"
  2. Bounded Contexts
    • "Are there distinct business areas that use different terminology?"
    • "Which teams will own which parts of the system?"
    • "Do you have existing systems that define boundaries?"
  3. Scale & Performance
    • "Which read operations are most frequent?"
    • "Are there operations that need eventual consistency?"
    • "Do you need audit trails for business operations?"

DDD Building Blocks

ConceptPurposeExample
EntityIdentity + lifecycleUser, Order, Product
Value ObjectAttributes, no identityMoney, Address, Email
AggregateConsistency boundaryOrder + OrderItems
Domain EventRecord what happenedOrderPlaced, UserRegistered
RepositoryPersistence abstractionOrderRepository
Domain ServiceCross-aggregate logicPaymentProcessor

Project Structure

libs/
├── [domain]/
│   ├── domain/                 # Core domain logic
│   │   └── src/lib/
│   │       ├── entities/       # Entities and aggregates
│   │       ├── value-objects/  # Value objects
│   │       ├── events/         # Domain events
│   │       ├── services/       # Domain services
│   │       └── repositories/   # Repository interfaces
│   │
│   ├── application/            # Use cases / application services
│   │   └── src/lib/
│   │       ├── commands/       # Command handlers
│   │       ├── queries/        # Query handlers
│   │       └── services/       # Application services
│   │
│   ├── infrastructure/         # Technical implementations
│   │   └── src/lib/
│   │       ├── persistence/    # Repository implementations
│   │       ├── messaging/      # Event publishing
│   │       └── external/       # External service adapters
│   │
│   └── feature/                # Controllers / presenters
│       └── src/lib/
│           └── controllers/

Entity Pattern

An entity has identity, a private constructor reached through factories, and business methods that guard their own invariants. It extends a shared Entity base that supplies identity equality and the domain-event buffer:

export class Order extends Entity<OrderId> {
  private constructor(
    id: OrderId,
    private _customerId: CustomerId,
  ) {
    super(id);
  }

  static create(customerId: CustomerId): Order; // new, raises OrderCreated
  static reconstitute(data: OrderData): Order; // rehydrate, raises nothing

  addItem(productId: ProductId, qty: number, unitPrice: Money): void;
  place(): void; // rejects an empty order
  get total(): Money; // derived, never stored
}

Read references/entities-aggregates.md for the full pattern — the Entity and EntityId base classes, the invariant guards, and the aggregate-root rules. Do not hand-roll a base class from this sketch; the reference version is the one to copy.

Value Object Pattern

A value object has no identity — two instances with equal contents are equal. It is immutable, validates in its constructor, and returns new instances from every operation. It extends a shared ValueObject base that supplies structural equality:

export class Money extends ValueObject<{ amount: number; currency: string }> {
  static of(amount: number, currency?: string): Money; // throws if negative
  static zero(currency?: string): Money;

  add(other: Money): Money; // all three reject a currency mismatch
  subtract(other: Money): Money;
  multiply(factor: number): Money;
}

Read references/value-objects.md for the ValueObject base class and further worked examples (Email, Address, DateRange, Percentage).

Decision Matrix: When to Use DDD

ScenarioRecommendation
Simple CRUDSkip DDD, use basic services
Medium complexityUse tactical patterns (entities, value objects)
Complex domainFull DDD with bounded contexts
Multiple teamsBounded contexts essential
High consistency needsAggregates + domain events

Complexity Assessment

Before implementing DDD, assess with user:

□ Do entities have complex lifecycles? (draft → approved → fulfilled)
□ Are there business rules that span multiple entities?
□ Do different parts of the system use different terminology?
□ Is there a need for audit trails or event sourcing?
□ Will multiple teams work on different parts?

Score:

  • 0-1: Simple services sufficient
  • 2-3: Tactical DDD patterns
  • 4-5: Full strategic DDD

References

Load for detailed implementation:

  • entities-aggregates.md - Entity and aggregate patterns
  • value-objects.md - Value object implementations
  • cqrs-pattern.md - Command/Query separation
  • domain-events.md - Event-driven patterns
  • repository-pattern.md - Persistence abstraction

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.