🎁 Get the FREE AI Skills Starter Guide β€” Subscribe β†’
BytesAgainBytesAgain
πŸ¦€ ClawHub

Domain Logic Pattern Selector

by @quochungto

Choose domain logic pattern for enterprise application subsystems: Transaction Script vs Domain Model vs Table Module, and decide Service Layer thickness. Us...

⚑ When to Use
TriggerAction
Typical triggers: greenfield module design, Transaction Script code growing unmanageable, a team debate about "should we use DDD?", evaluating whether to add a service layer, diagnosing anemic domain model or script sprawl in legacy code.
Prerequisites: none. Works from a verbal description of the subsystem; codebase access improves diagnosis.
πŸ’‘ Examples

Scenario A β€” Revenue Recognition Engine (Complex Rules β†’ Domain Model)

Trigger: A team building a SaaS billing system. Revenue recognition rules vary by product type: word processors recognize 100% immediately; spreadsheets spread recognition over three dates; databases over two; and the CFO adds new product categories quarterly.

Process:

  • Classify: High complexity β€” rules vary by product, change frequently, involve calculations and date logic.
  • Route: Domain Model (complexity high β†’ Domain Model regardless of team experience).
  • Service Layer: Operation Script β€” use case requires updating the database and notifying contract administrators atomically.
  • Anti-pattern check: Risk of anemic domain model if the recognition strategy is placed in the service layer. Guard: RevenueRecognition objects should carry the isRecognizableBy(date) method; strategy subclasses should carry calculateRevenueRecognitions(). The service layer only coordinates the transaction and sends notifications.
  • Output: Domain Model with Contract, Product, RevenueRecognition, and a strategy hierarchy (CompleteRecognitionStrategy, ThreeWayRecognitionStrategy). RecognitionService is an Operation Script service layer that delegates domain logic to domain objects and handles email/integration notifications.


    Scenario B β€” Simple Order Management (.NET CRUD β†’ Table Module)

    Trigger: A .NET team building internal order management. Rules are mostly: validate fields, calculate totals, apply standard discounts. All UI is data-grid based. ADO.NET DataSets flow through every layer.

    Process:

  • Classify: Low-to-moderate complexity. No complex invariants, no algorithmic variation.
  • Route: Table Module. .NET RecordSet tooling is present; the calculation logic fits naturally in table-oriented classes.
  • Service Layer: None needed β€” single client (a Windows Forms UI), single transactional resource.
  • Anti-pattern check: Watch for stored-procedure logic drift. Keep discount calculation in the Order Table Module, not in a SQL stored procedure.
  • Output: Contract Table Module, Product Table Module, RevenueRecognition Table Module operating on a shared DataSet. No domain object identity β€” every operation takes a primary key parameter.


    Scenario C β€” Legacy Transaction Scripts Hitting Complexity Wall β†’ Refactor to Domain Model

    Trigger: A Java team's billing service has grown to a 2,000-line BillingService class. Discount logic is copy-pasted across five methods. Adding a new rule requires touching seven places.

    Process:

  • Classify: Transaction Script sprawl β€” the complexity has exceeded the pattern's capacity.
  • Route: Refactor toward Domain Model. Direction: up, not down.
  • Service Layer: Keep BillingService as an Operation Script service layer; move business rules onto Contract, LineItem, and Discount domain objects.
  • Migration path: Extract duplicate validation into domain object methods first; introduce Data Mapper to decouple persistence; migrate rule-specific conditional branches into strategy classes.
  • Anti-pattern check: Do not introduce an anemic domain model by moving methods from BillingService to new classes that only hold data. Behavior must move too.
  • Output: Decision record documenting the refactor direction, a domain object skeleton (Contract, LineItem, Discount), BillingService reduced to coordinating transactions and notifications, and a Data Mapper recommendation for persistence.

    View on ClawHub
    TERMINAL
    clawhub install bookforge-domain-logic-pattern-selector

    πŸ§ͺ Use this skill with your agent

    Most visitors already have an agent. Pick your environment, install or copy the workflow, then run the smoke-test prompt above.

    πŸ” Can't find the right skill?

    Search 60,000+ AI agent skills β€” free, no login needed.

    Search Skills β†’