Root Contracting: A Novel Method and Utility for Implementing Design by Contract in Domain-Driven Design with Event Sourcing
Event-Sourced Systems (ESSs) that adopt Domain-Driven Design (DDD) are becoming more popular because of their intuitive business process modeling and improved auditability, scalability, and flexibility. However, ensuring the correctness of domain models—particularly event-sourced aggregates (ESAs)—remains challenging. To address this, we propose root contracting, a novel, constrained, and lightweight adaptation of Design by Contract (DbC), specifying the precondition, postcondition, and class invariant exclusively at aggregate roots. Root contracting simplifies correctness enforcement by leveraging DDD principles aligned with DbC and the standardized ESA code structure. We offer uContract, a Java open-source utility that realizes root contracting, enabling automated verification of ESAs with configurable runtime overhead. Through performance evaluation and methodological discussion, we demonstrate that root contracting effectively bridges formal correctness with practical domain modeling. Our approach provides developers with a tool to streamline development workflows, potentially reducing testing overhead and supporting integration with methodologies like Behavior-Driven Development (BDD).
Authors
- Yu-Hsiang Hu (ORCID: https://orcid.org/0000-0002-2141-7580)
- Chien‐Tsun Chen (ORCID: https://orcid.org/0000-0002-4958-5471)
- Yi-Chun Yen (ORCID: https://orcid.org/0000-0001-6281-1210)
- Yu Chin Cheng (ORCID: https://orcid.org/0000-0001-9965-7384)
Institutions
- National Taipei University of Technology (TW)
- Tethys Research Institute (IT)
Publication Details
- Journal
- Electronics
- Published
- 2025-10-28
- DOI
- https://doi.org/10.3390/electronics14214205
- Primary Topic
- Model-Driven Software Engineering Techniques
- Type
- article
- Field-Weighted Citation Impact
- 0.00