Receber por email
← Voltar para o catálogo

tactical-ddd

Design, refactor, analyze, and review code by applying the principles and patterns of tactical domain-driven design. Triggers on: domain modeling, aggregate design, 'entity', 'value object', 'repository', 'bounded context', 'domain event', 'domain service', code touching domain/ directories, rich domain model discussions.

10estrelas
Atualizado há 4 meses

Ver no GitHub ↗ Licença: MIT

Como adicionar

/plugin marketplace add NoesisVision/nasde-toolkit

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/tactical-ddd-mpt3kcyi/svg)](https://www.skillteca.com.br/skills/tactical-ddd-mpt3kcyi)

Skills relacionadas

Ver todas de Desenvolvimento →

Alerta por categoria

Receba novas skills de Desenvolvimento toda segunda

1 email curto, só com as skills novas de Desenvolvimento. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

<!-- Source: ntcoding/claude-skillz, snapshot 2026-03-20 --> <!-- REPO-TUNED VARIANT (DDD-starter): C# examples reference this repo's own value objects (Money, PercentageDiscount, the Discount discriminated union, Sources/Sales/... paths). This is the deliberate "skill adapted to your repo" arm — NOT the pristine public skill. Recovered verbatim from the run artifacts that produced the weather-tuned = 90 result. --> <!-- Examples rewritten from TypeScript to C# / .NET (idiomatic for DDD-starter-dotnet codebase) -->

Tactical DDD

Design, refactor, analyze, and review code by applying the principles and patterns of tactical domain-driven design.

Principles

  1. Isolate domain logic
  2. Use rich domain language
  3. Orchestrate with use cases
  4. Avoid anemic domain model
  5. Separate generic concepts
  6. Make the implicit explicit... like your life depends on it
  7. Design aggregates around invariants
  8. Extract immutable value objects liberally
  9. Repositories are for loading and saving full aggregates

1. Isolate domain logic

What: Domain logic is not mixed with technical code like HTTP and database transactions.

Why: Easier to understand the most important part of the code, easier to validate with domain experts, easier to test and evolve, easier to plan and implement new features.

Test: Could a domain expert read the code? Can the code be unit tested without mocks or spinning up databases?

// ❌ WRONG - domain polluted with infrastructure
public class Delivery
{
    public async Task Dispatch()
    {
        _logger.LogInformation("Dispatching delivery {Id}", _id);   // Infrastructure!
        await _db.BeginTransactionAsync();                          // Infrastructure!
        if (_status != DeliveryStatus.Ready) throw new InvalidOperationException("Not ready");
        _status = DeliveryStatus.Dispatched;
        await _db.SaveAsync(this);                                  // Infrastructure!
        await _db.CommitAsync();                                    // Infrastructure!
        await _pushNotification.NotifyDriver();                     // Infrastructure!
    }
}

// ✅ RIGHT - isolated domain logic
public class Delivery
{
    public void Dispatch()
    {
        if (_status != DeliveryStatus.Ready)
            throw new DeliveryNotReadyError(_id);
        _status = DeliveryStatus.Dispatched;
        _dispatchedAt = DateTime.UtcNow;
    }
}

2. Use rich domain language

What: Names in code match exactly what domain experts say. No programmer jargon. No generic names.

Why: Translation between code-speak and business-speak causes bugs. When a domain expert says "assess a claim" and the code says "ProcessEntity", someone will misunderstand something.

Test: Would a domain expert recognize this name? If you'd need to translate it for them, it's wrong.

Common generic terms to watch for:

  • Manager, Handler, Processor, Helper, Util
  • Data, Info, Item (when domain terms exist)
  • Process, Handle, Execute (what does it actually DO?)
// ❌ WRONG - programmer jargon
public class ClaimHandler
{
    public ProcessingResult ProcessClaimData(ClaimDto claimData)
        => _claimProcessor.Handle(claimData);
}

// ✅ RIGHT - domain language
[DddDomainService]
public class ClaimAssessor
{
    public AssessmentDecision AssessClaim(InsuranceClaim claim)
    {
        if (claim.ExceedsCoverageLimit())
            return AssessmentDecision.Deny(DenialReason.ExceedsCoverage);
        return AssessmentDecision.Approve();
    }
}

3. Orchestrate with use cases

What: A use case is a user goal—something a user would recognize as an action they can perform in your application.

Why: Use cases define the entry points to your domain. They answer "what can a user do?" If something isn't a user goal, it's supporting machinery that belongs elsewhere.

Test (the menu test): If you described your application's features to a user like a menu, would this be on it?

DELIVERY APP MENU:
├── Request Delivery     ← Use case: user goal
├── Track Delivery       ← Use case: user goal
├── Cancel Delivery      ← Use case: user goal
├── Calculate ETA        ← NOT a use case: internal machinery
└── Check Delivery Radius ← NOT a use case: domain rule
// ❌ WRONG - not a user goal, this is internal machinery
// UseCases/CalculateEta.cs
public async Task<Duration> CalculateEta(DeliveryId deliveryId)
{
    var delivery = await _deliveryRepository.Load(deliveryId);
    var driver = await _driverRepository.Load(delivery.DriverId);
    return _routeService.EstimateArrival(driver.Location, delivery.Destination);
}

// ✅ RIGHT - actual user goal (appears in menu)
// UseCases/CancelDelivery.cs
public async Task CancelDelivery(DeliveryId deliveryId, CancellationReason reason)
{
    var delivery = await _deliveryRepository.Load(deliveryId);
    delivery.Cancel(reason);
    await _deliveryRepository.Save(delivery);
}

4. Avoid anemic domain model

What: Domain logic lives in domain objects, not in use cases. Use cases orchestrate; domain objects decide.

Why: When business rules leak into use cases, they scatter across the codebase, duplicate, and diverge. The domain becomes a dumb data carrier.

Test: Is your use case making business decisions, or just coordinating? If the use case contains if/else business logic, you likely have an anemic model.

// ❌ WRONG - business logic in use case (anemic domain)
public async Task ConfirmDropoff(DeliveryId deliveryId, ProofPhoto photo)
{
    var delivery = await _deliveryRepository.Load(deliveryId);

    // Business rules leaked into use case!
    if (delivery.Status != DeliveryStatus.InTransit)
        throw new InvalidOperationException("Delivery not in transit");
    if (photo is null && delivery.RequiresSignature)
        throw new InvalidOperationException("Proof of delivery required");

    delivery.Status = DeliveryStatus.Delivered;
    delivery.ProofPhoto = photo;
    delivery.DeliveredAt = DateTime.UtcNow;
    await _deliveryRepository.Save(delivery);
}

// ✅ RIGHT - use case orchestrates, domain decides
public async Task ConfirmDropoff(DeliveryId deliveryId, ProofPhoto photo)
{
    var delivery = await _deliveryRepository.Load(deliveryId);

    delivery.ConfirmDropoff(photo);  // Domain enforces the rules

    await _deliveryRepository.Save(delivery);
}

Signs of anemic model:

  • Use cases full of if/else business logic
  • Domain objects are just data with { get; set; } properties
  • Business rules duplicated across multiple use cases
  • Validation logic outside the object being validated
  • A domain object exposes IsX() + DoX() ("ask, don't tell") instead of a single decision method that both checks and acts

5. Separate generic concepts

What: Generic capabilities that aren't specific to your domain live separately from domain-specific logic.

Why: A retry mechanism, a caching layer, a validation framework—these aren't YOUR domain. Mixing them with domain logic obscures what's actually specific to your business.

Test: Would this code exist in a completely different business domain? If yes, it's generic. If it's specific to YOUR business rules, it's domain.

// ❌ WRONG - generic retry logic mixed with domain
// Sales.DeepModel/Delivery/DriverLocator.cs
[DddDomainService]
public class DriverLocator
{
    // Generic retry logic does not belong in domain!
    private async Task<T> WithRetry<T>(Func<Task<T>> fn, int attempts)
    {
        for (var i = 0; i < attempts; i++)
        {
            try { return await fn(); }
            catch { if (i == attempts - 1) throw; }
        }
        throw new InvalidOperationException("Retry failed");
    }

    public Task<Driver> FindAvailableDriver(Zone zone)
        => WithRetry(() => SearchDriversInZone(zone), 3);

    private Task<Driver> SearchDrive
Compartilhar X LinkedIn