|
| 1 | +[//]: # (DDD in Django) |
| 2 | + |
| 3 | +[//]: # (A project for the course "Advanced Software Engineering" at the DHBW Karlsruhe) |
| 4 | + |
| 5 | +[//]: # (by Marc Gökce, 2023) |
| 6 | + |
| 7 | +# Domain Driven Design in Python 🐍 |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +###### Sperrvermerk |
| 12 | + |
| 13 | +This project is a _restructuring_ of my existing blog site (www.mkrabs.de) using Domain Driven Design |
| 14 | +principles, as part of the Advanced Software Engineering course in the 6th semester at the Duale Hochschule of |
| 15 | +Karlsruhe. The project code is publicly available on GitHub, but please note that I do not take any responsibility |
| 16 | +for the use of this code / architecture or other mishaps you might write in other projects. I am not liable for any |
| 17 | +negative outcomes, poor grades or broken snakes resulting from the use of this code, as it is intended for educational |
| 18 | +purposes only. |
| 19 | + |
| 20 | +_Use at your own risk, lmao._ |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +###### Table of Contents |
| 25 | + |
| 26 | +Will update as time marches on |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +This project uses python as the programming language and Django as the overlord framework. This is how I plan to |
| 33 | +structure the project: It will incorporate 3 main layers: domain, application and infrastructure, whilst using some |
| 34 | +lesser important ones like abstraction and presentation. |
| 35 | + |
| 36 | +### Domain |
| 37 | + |
| 38 | +The Domain layer encompasses the crucial business logic and entities of the application, including user accounts, blog |
| 39 | +posts, comments, and likes. It defines the fundamental concepts and behaviors of the application, and is composed of |
| 40 | +pure Python code that is technology-agnostic and easy to comprehend and maintain. The entities within this layer serve |
| 41 | +as the fundamental building blocks of the application and embody the core business requirements. Additionally, the |
| 42 | +repository interfaces defined within this layer facilitate data access and manipulation. By separating domain-specific |
| 43 | +concerns from implementation details, the Domain layer promotes better reasoning and modification of the application. |
| 44 | + |
| 45 | +``` |
| 46 | +todo: add code |
| 47 | +``` |
| 48 | + |
| 49 | +### Application |
| 50 | + |
| 51 | +The Application layer encompasses the use cases and business logic of the application, dictating how the core entities |
| 52 | +are utilized and manipulated to accomplish specific objectives, such as generating a blog post or commenting on a post. |
| 53 | +This layer relies on the Domain layer and interfaces with the Infrastructure layer to execute necessary operations. The |
| 54 | +services within this layer encapsulate the business logic and furnish a more elevated API for the presentation layer to |
| 55 | +engage with. By dividing the business logic from implementation details, the Application layer streamlines the process |
| 56 | +of adjusting and advancing the application. |
| 57 | + |
| 58 | +``` |
| 59 | +todo: add code |
| 60 | +``` |
| 61 | +### Infrastructure |
| 62 | + |
| 63 | +The Infrastructure layer serves as a bridge between the Domain layer and the persistence layer, which is typically a |
| 64 | +database or a file system. This layer is responsible for implementing the necessary infrastructure to enable the |
| 65 | +application to interact with external systems, such as web APIs, file systems, or databases. The repositories defined |
| 66 | +within this layer provide a way to persist and retrieve data from the underlying storage system. The implementation of |
| 67 | +these repositories may vary depending on the chosen technology, such as ORM frameworks or raw SQL queries. The |
| 68 | +Infrastructure layer is crucial because it isolates the application's business logic from the underlying implementation |
| 69 | +details of external systems, ensuring flexibility and maintainability. |
| 70 | + |
| 71 | +``` |
| 72 | +todo: add code |
| 73 | +``` |
| 74 | +### Presentation |
| 75 | + |
| 76 | +The Presentation layer encompasses the user interface and presentation logic of the application, dictating how users |
| 77 | +engage with the application and how data is presented to them. This layer relies on the Application layer to retrieve |
| 78 | +and manipulate data. The resources defined in this layer, including HTML, CSS, and JavaScript, determine the visual |
| 79 | +aesthetics and behavior of the application. The primary Python file serves as the application's entry point and manages |
| 80 | +user requests. The Presentation layer is important because it provides the necessary user-facing components, rendering |
| 81 | +the application accessible and usable to individuals. |
| 82 | + |
| 83 | +``` |
| 84 | +todo: add code |
| 85 | +``` |
| 86 | +### Test |
| 87 | + |
| 88 | +The Testing layer is dedicated to testing the application. Testing is an integral aspect of software development, as it |
| 89 | +confirms the functionality of the application and identifies any defects or issues before release. The test directory is |
| 90 | +segregated into two subdirectories: unit and smoke. |
| 91 | + |
| 92 | +The unit directory contains unit tests that test the functionality of individual components in isolation. These tests |
| 93 | +verify that each component of the application performs as expected independently of its interaction with other |
| 94 | +components. Unit tests are crucial in ensuring that the application's building blocks function as intended. |
| 95 | + |
| 96 | +The smoke directory contains integration tests that validate the integration between different layers of the |
| 97 | +application. These tests ensure that the application's components communicate with each other correctly and that the |
| 98 | +different layers interact with one another as intended. Integration tests are essential in guaranteeing the overall |
| 99 | +behavior of the application. |
| 100 | + |
| 101 | +Both types of tests are significant in ensuring the quality and correctness of the application. By writing tests, |
| 102 | +developers can detect errors and issues early in the development process, reducing the costs and time required to |
| 103 | +address them. Furthermore, tests serve as documentation for the application's behavior, simplifying the understanding |
| 104 | +and modification of the code for future developers. |
| 105 | + |
| 106 | +``` |
| 107 | +todo: add example of unit test and smoke test |
| 108 | +``` |
| 109 | +--- |
| 110 | + |
| 111 | +# Conclusion |
| 112 | + |
| 113 | +###### and or summary |
| 114 | + |
| 115 | +## Summary of the work done |
| 116 | + |
| 117 | +## Review of the benefits of using DDD principles |
| 118 | + |
| 119 | +## Future work and improvements |
| 120 | + |
| 121 | +###### Back to top [▲](#table-of-contents) |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +# References |
| 126 | + |
| 127 | +###### Write the references used in the project |
| 128 | + |
| 129 | +* https://docs.djangoproject.com/en/4.2/misc/design-philosophies/#models |
| 130 | +* https://www.cosmicpython.com/book/preface (very nice) |
| 131 | +* https://wiki.c2.com/?CouplingAndCohesion |
| 132 | +* https://iktakahiro.dev/python-ddd-onion-architecture |
| 133 | +* https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215 |
| 134 | +* https://github.com/jdiazromeral/django-ddd |
| 135 | +* https://openbase.com/python/Django-ddd |
| 136 | +* https://michalgodkowicz.medium.com/another-way-to-persist-ddd-aggregates-in-django-d148f4cad298 |
| 137 | +* https://www.apress.com/gp/blog/all-blog-posts/domain-driven-design-with-django/16172586 |
| 138 | +* https://thedomaindrivendesign.io/why-use-domain-driven-design/ |
| 139 | + |
| 140 | +###### Video References |
| 141 | + |
| 142 | +* https://www.youtube.com/watch?v=hv-LiKQgN90 |
| 143 | +* https://www.youtube.com/watch?v=Ru2T4fu3bGQ |
| 144 | + |
| 145 | +###### Back to top [▲](#table-of-contents) |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +_Thank you for reading._ |
| 150 | + |
| 151 | +[@MKrabs](https://www.github.com/MKrabs) - [Website](https://www.mkrabs.de) |
| 152 | + |
| 153 | +[//]: # (Styles) |
| 154 | +<style> |
| 155 | + |
| 156 | +ol { list-style-type: upper-roman; } |
| 157 | +ol ol { list-style-type: decimal; } |
| 158 | + |
| 159 | +</style> |
0 commit comments