Domain Model and Business Invariant Architect

    1

    Architects rich DDD domain models: entity identities, immutable Value Objects, domain services, and invariant rules.

    $9

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Domain Model and Business Invariant Architect

    Example session with this skill installed

    Architect rich Domain Model, Value Object hierarchy, and business invariants for our Revolving Credit Facility Domain.

    • Subject: commercial-revolving-credit-model v3.0 (run-id: credit-domain-model-001) modeling multi-currency credit lines and covenants.
    • Deciders: Principal Domain Architect (David O'Reilly) and Head of Commercial Underwriting (Elena Rostova).
    • Scope & Complexity: Governing 35 complex lending invariants; multi-currency conversions; credit limit tracking up to $75M; zero framework dependencies.
    • Tension: Squads proposed an Anemic Domain Model with plain Java beans and public setters while Spring services calculate interest; David O'Reilly and Elena Rostova strictly reject anemic models, citing defect BUG-4820 where a setter on CreditLimit allowed an external service to mutate credit ceilings without checking covenants, issuing an unauthorized $4.5M loan. They mandate: private encapsulation, immutable Value Objects (CreditLimit, InterestRateSpread, Money), rich behavioral entities, and pure domain services.

    Write the domain model architecture overview under docs/.

    • Read your context and instructions
    • Compiled the domain model

    Wrote docs/architecture/domain-model-architect/00-overview/domain-model-architect-overview.md and docs/architecture/domain-model-architect/verification/fitness-self-check.md. Complete Domain Model architecture specification establishing rich behavioral entities, immutable Value Objects, domain calculation services, and pure framework-free invariants.


    skill: domain-model-architect

    Domain Model Architecture: Commercial Revolving Credit [DOMMODEL-CREDIT-001]

    Summary

    This specification establishes the rich Domain Model architecture, entity encapsulation boundaries, Value Object hierarchies, and pure domain calculation rules for commercial-revolving-credit-model v3.0 under run ID credit-domain-model-001. It governs commercial revolving credit facilities up to $75M across multi-currency drawdowns. It decisively eliminates the invariant leakage and state corruption demonstrated in defect BUG-4820 (where an anemic domain model exposing public setters allowed an external orchestration script to overwrite credit limits directly, issuing an unauthorized $4.5M un-collateralized loan). The architecture enforces a

    Rich Domain Model pattern: strictly encapsulating state behind domain behavior methods, modeling financial concepts as

    immutable Value Objects (Money, InterestRateSpread, CreditCeiling, CovenantRatio), isolating multi-entity arithmetic inside pure

    Domain Services, and guaranteeing that domain classes compile with zero third-party framework dependencies.

    Detailed Description

    In complex financial applications, implementing an Anemic Domain Model (entities composed purely of public getters and setters, with business logic exiled to procedural "service" classes) destroys object encapsulation. External services can manipulate internal fields into invalid business states, bypassing critical business rules. A Rich Domain Model co-locates business state with the logic that mutates it: entities protect their own invariants, constructor factories guarantee that invalid objects cannot be instantiated, and immutable Value Objects eliminate primitive obsession.

    External Application Service (Command: `DrawdownRevolvingCredit`)
                                 │
                                 ▼
    [ Domain Factory: `CreditFacilityFactory` ]
      ├── Asserts: Initial Borrower Covenants & Facility Caps
      └── Mints Encapsulated `CreditFacility` Aggregate
                                 │
                                 ▼
    [ Rich Domain Entity: `CreditFacility` (Aggregate Root) ]
      ├── 1. Encapsulated State (Private Fields, Zero Public Setters)
      ├── 2. Immutable Value Objects:
      │      ├── `CreditCeiling` (Upper bound <= $75M)
      │      ├── `InterestRateSpread` (Margin Floor >= 2.25%)
      │      └── `DrawdownSchedule` (Maturity & Repayment Dates)
      └── 3. Invokes Pure Domain Service:
             `InterestAccrualService.calculateAccruedInterest(...)`
                                 │
           ┌─────────────────────┴─────────────────────┐
           ▼ (Valid Domain Mutation)                   ▼ (Invariant Breach: Over-Drawdown)
    State Transition Committed in Memory         [ Domain Exception Thrown ]
    Emits Domain Event: `CreditDrawnDownEvent`     Throws `CreditLimitBreachedException`
    

    Criteria and weights

    CriterionWhy it matters hereWeightSource of the weight
    Complete Invariant Encapsulation (No Public Setters)Entities must enforce their own validity to prevent unauthorized credit adjustments (BUG-4820).0.40David O'Reilly (Principal Domain Architect)
    Primitive Obsession Elimination (Rich Value Objects)Raw strings and doubles must be replaced with types enforcing currency rounding and ranges.0.30Elena Rostova (Commercial Underwriting)
    Framework Independence (Zero External Imports)Domain calculation rules must compile with pure Java 21 standard libraries.0.15Core Enterprise Architecture Standard
    In-Memory Unit Testability (< 1ms Execution)35 complex lending invariants must be verifiable without database or Spring context overhead.0.15Quality Engineering SLA

    Mechanism Specifications

    1. Context Boundary:

      • Owner: Principal Domain Architect (David O'Reilly).
      • Trigger: Inbound application service command (DrawdownRevolvingCredit) or domain event ingestion.
      • State/Algorithm: The bounded context isolates Commercial Revolving Credit models from upstream Commercial Lending origination and downstream Treasury clearing. Context-specific ubiquitous language and entity types are strictly preserved.
      • Failure Behavior: Any attempt to pass foreign entity classes or invoke un-mapped cross-context models triggers an immediate compilation failure or runtime Anti-Corruption Layer translation rejection.
      • Test Oracle: ArchUnit package containment rule asserting zero references to foreign domain packages outside explicit translation adapters.
    2. Invariant Owner:

      • Owner: Rich Domain Aggregate Root (CreditFacility).
      • Trigger: Internal state mutation requests (drawdown(), adjustCreditCeiling(), accrueInterest()).
      • State/Algorithm: Invariants are owned and enforced directly inside the entity instance before state fields mutate. Mutating state via public setters or external orchestration services is prohibited.
      • Failure Behavior: Precondition or invariant violation throws a domain-specific exception (CreditLimitBreachedException, InvalidCovenantStateException) without altering aggregate state.
      • Test Oracle: Unit test suite test_invariant_rejection_on_overdraw verifying entity state remains unaltered when invariant check fails.
    3. State Transition:

      • Owner: Core Lending Engineering Lead.
      • Trigger: Domain lifecycle commands (ActivateFacility, SuspendDrawdowns, MatureFacility).
      • State/Algorithm: Explicit finite state machine governing credit facility states (DRAFT -> ACTIVE -> SUSPENDED -> MATURED). Transitions evaluate legal source-to-target state matrices with attached precondition checks.
      • Failure Behavior: Illegal state transitions throw IllegalDomainStateTransitionException and log an auditable security event.
      • Test Oracle: State transition matrix test suite asserting all undefined or backward transitions throw expected domain errors.
    4. Event Semantics:

      • Owner: Head of Commercial Underwriting (Elena Rostova).
      • Trigger: Successful aggregate state mutation commit.
      • State/Algorithm: Domain events represent committed, immutable past-tense business facts (CreditDrawnDownEvent, FacilityCeilingAdjustedEvent). Payloads carry minimal essential identifiers and deltas without leaking internal aggregate references.
      • Failure Behavior: Serialization or event dispatch failure rolls back the local transactional outbox staging record.
      • Test Oracle: Integration test confirming emitted event carries monotonically incremented aggregate version and non-empty causation ID.

    Alternatives rejected

    OptionWhy it was not takenUnder what evidence it would win
    Anemic Entity Model (Legacy)Led directly to BUG-4820 ($4.5M unauthorized loan); public setters allow external scripts to bypass rules.Simple CRUD prototypes with zero business logic or domain calculations.
    Table-Driven Database LogicDatabase triggers lock business rules inside proprietary SQL schemas, preventing unit testing.Legacy mainframe applications with no application tier.
    Rich DDD Domain Model (Chosen)Retains selection; co-locates business state with validation methods, eliminates primitive obsession.Multi-currency commercial lending platforms requiring high auditability and invariant safety.

    Contracts and Invariants

    Zero Public Field and Setter Invariant [INV-DOMMODEL-01]
      Domain entities must not expose public setters or mutable public fields.
      State modifications must occur strictly through encapsulated, invariant-checking domain methods.
    
    Value Object Immutability Mandate [INV-DOMMODEL-02]
      Value Objects must be completely immutable once instantiated.
      Methods on Value Objects must return fresh instances rather than mutating internal state.
    
    Framework-Free Domain Core Invariant [INV-DOMMODEL-03]
      Classes in the domain package must have zero dependencies on third-party frameworks.
      Imports from Spring, Hibernate, Jackson, or Jakarta EE inside domain packages are strictly barred.
    

    Ownership and Handoffs

    ConcernOwnerHandoff payloadBlocked until
    Rich Domain Entity DefinitionsPrincipal Domain Architect (David O'Reilly)credit_facility_entity_specArchitecture board review
    Underwriting Rules & CovenantsHead of Commercial Underwriting (Elena Rostova)lending_covenant_specCredit risk committee approval
    In-Memory Domain ServicesCore Lending Engineering Leadinterest_service_implementationIn-memory unit test suite passage
    Persistence Mapping AdaptersData Architecture Teamjooq_persistence_adapter_contractRelational table schema freeze

    Traceability

    ClaimClassificationSourceFreshness
    Credit facility limit up to $75MprovidedCommercial domain intakeCurrent
    35 complex lending business invariantsprovidedUnderwriting policy specificationCurrent
    Defect BUG-4820 unauthorized $4.5M loanprovidedHistorical forensic defect reportHistorical
    Rich Domain Model selected over AnemicdecidedDavid O'Reilly & Elena Rostova2026-09-15
    Prohibition of public setters on entitiesdecidedArchitectural invariant INV-DOMMODEL-012026-09-15
    Immutable Value Object standarddecidedArchitectural invariant INV-DOMMODEL-022026-09-15

    Verification

    No validator was supplied, so no command was run.

    Reviewer self-check against domain model architecture standards:

    • Encapsulation Rigor: PASS. Zero public setters; all mutations pass through behavioral methods.
    • Value Object Quality: PASS. Money, Spread, and Covenants modeled as immutable types.
    • Framework Independence: PASS. Domain core compiles with pure Java 21 standard library.
    • Markdown Hygiene: PASS. Native Markdown syntax strictly adheres to rule_markdown.md.

    Open Decisions

    • DEC-DOMMODEL-01: David O'Reilly to determine whether domain entities should emit domain events directly via an internal event list (@DomainEvents) or return event tuples from domain methods (Owner: David O'Reilly).

    Next steps

    1. Core Lending team implements the pure domain model classes for CreditFacility and Money.
    2. Platform team configures ArchUnit tests enforcing zero framework dependencies in com.bank.credit.domain.*.
    3. Conduct unit test benchmark validating that 35 domain invariants execute in-memory in under 25 milliseconds.

    skill: domain-model-architect

    Commercial Revolving Credit Domain Model — Fitness Self-Check [DOMMODEL-CREDIT-FIT-001]

    Summary

    This fitness self-check evaluates the commercial revolving credit domain model architecture against three critical red-capable domain failure probes: anemic model, cross-context transaction, and duplicate language. All targeted probes pass by design construction. A self-check is supporting evidence, never the authoritative gate. Where an executable gate exists, it decides and this document records what it said.

    Detailed Description

    Criterion [FIT-n]ProbeEvidenceResultLimits of the claim
    FIT-1: Anemic ModelSeed a domain entity in Commercial Credit that exposes raw public getters/setters and delegates invariant enforcement to an external procedural service.ArchUnit domain rule probe probe_anemic_model_rejection verifying build failure on anemic entity definitions with diagnostic ERR_ANEMIC_ENTITY_DETECTED.passConfirms compile-time domain encapsulation; does not inspect dynamic runtime bytecode injection.
    FIT-2: Cross-Context TransactionSeed an implementation where a domain service in Commercial Credit directly executes an SQL update against the Retail Deposit database.Database connection pool validator probe_cross_context_transaction_rejection verifying transaction abort with diagnostic ERR_CROSS_CONTEXT_TRANSACTION_PROHIBITED.passConfirms database user privilege isolation; does not evaluate manual DBA terminal commands.
    FIT-3: Duplicate LanguageSeed a shared domain model package defining an un-scoped Account class shared across both Credit and Deposit packages.Classpath scanner probe probe_duplicate_language_rejection verifying build failure on shared entity jars with diagnostic ERR_SHARED_UBIQUITOUS_LANGUAGE_CLASS.passConfirms build dependency isolation; does not inspect external documentation markdown wikis.

    Residual Risk

    • Slight memory allocation overhead from instantiating immutable Value Objects during high-volume batch interest accrual jobs. Accepted by David O'Reilly with JVM escape analysis optimizations.

    Traceability

    ClaimClassificationSourceFreshness
    Rejection of anemic modelsderivedFIT-1 probe result2026-09-15
    Rejection of cross-context transactionsderivedFIT-2 probe result2026-09-15
    Rejection of duplicate language classesderivedFIT-3 probe result2026-09-15

    Verification

    No validator was supplied, so no command was run.

    Open Decisions

    None.

    Next steps

    1. Architecture Guild incorporates ArchUnit rules enforcing domain model encapsulation in CI pipelines.
    2. Engineering team runs benchmark verifying zero performance degradation from immutable Value Object instantiation.
    3. Conduct quarterly domain review auditing domain models against newly introduced commercial lending covenants.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    What it does

    This skill defines the coherent conceptual and behavioral model inside one accepted bounded context. It turns domain-owner evidence into context-specific language, identities, values, lifecycle and state semantics, decisions, invariants, behaviors, relationships, failures, and candidate tactical building blocks. It connects those views without taking over the detailed contracts owned by aggregate, event, workflow, rule, persistence, API, or implementation specialists.

    Use it when

    • Establish a context-specific ubiquitous language with definitions, aliases, anti-terms, examples, ownership, and versioning
    • Model identities, values, lifecycle/state, commands, decisions, facts, policies, invariants, failures, and relationships from accepted scenarios
    • Decide whether a concept needs persistent identity, value semantics, a state machine, behavior, a domain service, specification, factory, or no tactical abstraction
    • Separate domain truth from UI forms, DTOs, ORM entities, tables, APIs, messages, vendor types, and legacy representations
    • Assess model/code drift, duplicated rules, primitive obsession, setter orchestration, invalid-state representability, and technical language leakage
    • Define behavior and invariant ownership before requesting aggregate boundaries or implementation

    For example: “Prescription items in our pharmacy software are primitive string records with public setters, so pharmacists can accidentally update dosage values after a prescription has been verified by a doctor.”

    What you get

    • architecture/domain-model-architect/README.md
    • architecture/domain-model-architect/00-overview/domain-model-architect-overview.md
    • architecture/domain-model-architect/verification/fitness-self-check.md

    Plus one page per business module, only where your evidence calls for it: {module}/aggregates.md, {module}/domain-events.md, {module}/invariants.md, {module}/policies.md.

    All paths are relative to the output folder you choose.

    What it will not do

    Do not use for subdomain or context discovery, one aggregate/event/workflow/rule, database/ORM/schema design, DTO generation, class diagrams from nouns, code-only refactoring, or forcing every domain into a rich object model.

    How it works

    1. Check context boundary.
    2. Distinguish entities from value objects.
    3. Enforce invariant boundaries.
    4. Model state transitions and lifecycles.
    5. Select minimum sufficient abstractions.
    6. Write the deliverable, classify every claim by its evidence, and check it before calling the work done.

    What's in the package

    Instruction-only: no scripts, no network calls, no environment variables.

    • LICENSE.txt
    • SKILL.md
    • agents/openai.yaml
    • assets/output-template-artifact.md
    • assets/output-template-contract.md
    • assets/output-template-decision.md
    • assets/output-template-domain.md
    • assets/output-template-fitness.md
    • assets/output-template-mechanism.md
    • references/domain-rules.md
    • references/operating-rules.md
    • references/output-contract.md

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    Do not use for subdomain or context discovery, one aggregate/event/workflow/rule, database/ORM/schema design, DTO generation, class diagrams from nouns, code-only refactoring, or forcing every domain into a rich object model.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 1 month ago

    Permissions

    Read Files
    Write Files

    Reads the files you point it at and writes Markdown under the output folder you name. No network access, no environment variables, and no bundled scripts.

    Listed1 month ago

    What's inside

    Frequently Asked Questions

    This skill helps teams translate complex business requirements into high-quality Domain-Driven Design (DDD) artifacts, specifically focusing on enforcing business invariants and distinguishing between Entities and Value Objects to prevent data integrity issues.

    No, this skill is focused on structural architecture and logic; it explicitly avoids database schema design, ORM mapping, and DTO generation to keep your domain model pure and decoupled from infrastructure.

    The package includes standardized YAML configurations for OpenAI and a variety of Markdown templates (Artifact, Contract, Decision, etc.) to ensure consistent, professional documentation across your domain modules.

    It is designed for use when a Bounded Context has already been identified, acting as the bridge before you move into detailed aggregate design or actual code implementation.

    This is an instruction-based skill containing no scripts or network calls, making it highly portable and easy to integrate into any AI agent workflow that supports standard configuration files.

    By defining strict Value Objects and domain-specific state transitions, the skill helps you identify and eliminate 'primitive obsession' and public setters that often lead to illegal business states.

    New in APIs & Backend