Enabling Test-Driven Development, Domain-Driven Design, and Event-Driven Microservices
Harry Percival and Bob Gregory

Python#
Architecture#
Patterns#
TDD#
DDD#
Test-Driven_Development,#
Domain-Driven_Design#
Event-driven#
clean_architecture#
🐍 با رشد روزافزون پایتون، پروژهها بزرگتر و پیچیدهتر شدهاند. بسیاری از توسعهدهندگان پایتون به طراحیهای سطح بالا مانند Hexagonal/Clean Architecture، معماری مبتنی بر رویداد و الگوهای استراتژیک Domain-Driven Design (DDD) علاقهمند شدهاند. اما پیادهسازی این الگوها در پایتون همیشه ساده نیست.
⚡ ویژگیهای کلیدی کتاب:
📚 فهرست مطالب
بخش اول: ساخت معماری برای پشتیبانی از مدلسازی دامنه
فصل ۱: مدلسازی دامنه
فصل ۲: الگوی مخزن
فصل ۳: مرور اجمالی: اتصال و انتزاع
فصل ۴: اولین مثال عملی ما: API و لایه سرویس با Flask
فصل ۵: تست محور با سرعت بالا و پایین
فصل ۶: الگوی واحد کار
فصل ۷: Aggregates و مرزهای سازگاری
بخش دوم: معماری مبتنی بر رویداد
فصل ۸: رویدادها و پیامرسان
فصل ۹: پیادهسازی پیشرفته روی پیامرسان
فصل ۱۰: دستورات و مدیریتکنندهها
فصل ۱۱: استفاده از رویدادها برای یکپارچهسازی میکروسرویسها
فصل ۱۲: جداسازی مسئولیت دستورات و پرسوجو
فصل ۱۳: تزریق وابستگی و راهاندازی
ضمائم
ضمیمه A: نمودار و جدول خلاصه
ضمیمه B: ساختار پروژه نمونه
ضمیمه C: جایگزینی زیرساخت با CSV
ضمیمه D: پیادهسازی Repository و Unit of Work با Django
ضمیمه E: اعتبارسنجی
📌 مخاطب کتاب:
👤 درباره نویسندگان:
As Python continues to grow in popularity, projects are becoming larger and more complex. Many Python developers are taking an interest in high-level software design patterns such as hexagonal/clean architecture, event-driven architecture, and the strategic patterns prescribed by domain-driven design (DDD). But translating those patterns into Python isn’t always straightforward.
With this hands-on guide, Harry Percival and Bob Gregory from MADE.com introduce proven architectural design patterns to help Python developers manage application complexity—and get the most value out of their test suites.
Each pattern is illustrated with concrete examples in beautiful, idiomatic Python, avoiding some of the verbosity of Java and C# syntax. Patterns include:
Table of Contents
Part I. Building an Architecture to Support Domain Modeling
Chapter 1. Domain Modeling
Chapter 2. Repository Pattern
Chapter 3. A Brief Interlude: On Coupling and Abstractions
Chapter 4. Our First Use Case: Flask API and Service Layer
Chapter 5. TDD in High Gear and Low Gear
Chapter 6. Unit of Work Pattern
Chapter 7. Aggregates and Consistency Boundaries
Part II. Event-Driven Architecture
Chapter 8. Events and the Message Bus
Chapter 9. Going to Town on the Message Bus
Chapter 10. Commands and Command Handler
Chapter 11. Event-Driven Architecture: Using Events to Integrate Microservices
Chapter 12. Command-Query Responsibility Segregation (CQRS)
Chapter 13. Dependency Injection (and Bootstrapping)
Epilogue
Appendix A. Summary Diagram and Table
Appendix B. A Template Project Structure
Appendix C. Swapping Out the Infrastructure: Do Everything with CSVs
Appendix D. Repository and Unit of Work Patterns with Django
Appendix E. Validation
Here are a few things we assume about you, dear reader:
We structure our explorations of architectural patterns around an example app, building it up chapter by chapter. We use TDD at work, so we tend to show listings of tests first, followed by implementation. If you’re not used to working test-first, it may feel a little strange at the beginning, but we hope you’ll soon get used to seeing code “being used” (i.e., from the outside) before you see how it’s built on the inside.
We use some specific Python frameworks and technologies, including Flask, SQLAlchemy, and pytest, as well as Docker and Redis. If you’re already familiar with them, that won’t hurt, but we don’t think it’s required. One of our main aims with this book is to build an architecture for which specific technology choices become minor implementation details.
Origins of this book:
At the end of Harry’s last book, Test-Driven Development with Python (O’Reilly), he found himself asking a bunch of questions about architecture, such as, What’s the best way of structuring your application so that it’s easy to test? More specifically, so that your core business logic is covered by unit tests, and so that you minimize the number of integration and end-to-end tests you need? He made vague references to “Hexagonal Architecture” and “Ports and Adapters” and “Functional Core, Imperative Shell,” but if he was honest, he’d have to admit that these weren’t things he really understood or had done in practice.
And then he was lucky enough to run into Bob, who has the answers to all these questions. Bob ended up a software architect because nobody else on his team was doing it. He turned out to be pretty bad at it, but he was lucky enough to run into Ian Cooper, who taught him new ways of writing and thinking about code.
Our aim with this book is to introduce several classic architectural patterns and show how they support TDD, DDD, and event-driven services. We hope it will serve as a reference for implementing them in a Pythonic way, and that people can use it as a first step toward further research in this field.
Bob Gregory is a UK-based software architect with MADE.COM. He has been building event driven systems with domain-driven design for more than a decade.
After an idyllic childhood spent playing with BASIC on French 8-bit computers like the Thomson T-07 whose keys go "boop" when you press them, Harry Percival spent a few years being deeply unhappy as a management consultant. Soon he rediscovered his true geek nature, and was lucky enough to fall in with a bunch of XP fanatics, working on the pioneering but sadly defunct Resolver One spreadsheet. He worked at PythonAnywhere LLP, spreading the gospel of TDD world-wide at talks, workshops and conferences. He is now with MADE.COM.









