<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammed Yousry</title>
    <description>The latest articles on DEV Community by Muhammed Yousry (@moyousry).</description>
    <link>https://dev.to/moyousry</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F963145%2F2b1a9074-e881-4093-9824-c00600eb313b.png</url>
      <title>DEV Community: Muhammed Yousry</title>
      <link>https://dev.to/moyousry</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moyousry"/>
    <language>en</language>
    <item>
      <title>DDD-Layered Architecture</title>
      <dc:creator>Muhammed Yousry</dc:creator>
      <pubDate>Wed, 02 Nov 2022 14:23:44 +0000</pubDate>
      <link>https://dev.to/moyousry/ddd-layered-architecture-2f73</link>
      <guid>https://dev.to/moyousry/ddd-layered-architecture-2f73</guid>
      <description>&lt;p&gt;How to implement DDD as a software design approach with Layered Architecture in large projects?&lt;/p&gt;

&lt;p&gt;First, I'm gonna introduce an important pattern in Domain Driven Design which's &lt;strong&gt;Bounded Context pattern&lt;/strong&gt;. ✌️&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s the &lt;strong&gt;Bounded Context&lt;/strong&gt;?
&lt;/h2&gt;

&lt;p&gt;Bounded Context is a central pattern in Domain-Driven Design. It is the focus of DDD's strategic design section which is all about dealing with large models and teams. DDD deals with large models by dividing them into different Bounded Contexts.&lt;/p&gt;

&lt;p&gt;For Example in the E-commerce food apps we have Order context, payment context, menu context, delivery context, checkout context, subscription context, and every context is a large model and has a boundaries and each model can work independently. &lt;br&gt;
In the future, &lt;br&gt;
you can easily move each context to a microservice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9eh3ftbwlkytxo73iry5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9eh3ftbwlkytxo73iry5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s the &lt;strong&gt;DDD&lt;/strong&gt; ?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;is a software design approach focusing on modeling software to match a domain according to input from the domain’s experts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;is to bridge the gap between domain experts and developers by using the same language to create the same understanding&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the structure and language of software code (class names, class methods, class variables ) should match the business domain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;is very suitable for complex domains.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;EX:  if a software processes food applications, it might have classes like Order, OrderPayment and Customer, and methods such as CreateOrder, AcceptOrder, checkout and.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s the &lt;strong&gt;Layered (N-Tier) Architecture&lt;/strong&gt; ?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The most common architecture pattern is the layered architecture pattern.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Components within the layered architecture pattern are organized into horizontal layers, each layer performing a specific role within the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The layered architecture pattern does not specify the number and types of layers that must exist in the pattern, most layered architectures consist of four standard layers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(The layers of isolation concept ) Changes made in one layer of the architecture generally don’t impact or affect components in other layers.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Layered architecture digram example:-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssbvmtjijix8r95bsyeq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssbvmtjijix8r95bsyeq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DDD-layered architecture digram example:- &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb0vrhy4i20xke13fcm2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb0vrhy4i20xke13fcm2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Project folder structure example :- &lt;br&gt;
(ruby on rails project)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwvtlqljtnqpg88vbkhu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwvtlqljtnqpg88vbkhu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why DDD and Layered Arch ?
&lt;/h2&gt;

&lt;p&gt;I am now working on an e-commerce application (Food Industry)&lt;br&gt;
And I was mainly working in the Order domain functionality, when we needed to change something in the code or add a new feature which was difficult and impossible because:- &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code complexity.&lt;/li&gt;
&lt;li&gt;Inability to effectively debug.&lt;/li&gt;
&lt;li&gt;Development speed issue.&lt;/li&gt;
&lt;li&gt;Legacy and unstructured code.&lt;/li&gt;
&lt;li&gt;Order was tightly coupled with payments and delivery.&lt;/li&gt;
&lt;li&gt;There is a gap between the business and the codebase.&lt;/li&gt;
&lt;li&gt;Missing the single responsibility principle.&lt;/li&gt;
&lt;li&gt;There is no single source of truth.&lt;/li&gt;
&lt;li&gt;Identifying layers responsibilities.&lt;/li&gt;
&lt;li&gt;Readability issue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We needed to isolate the field with known boundaries&lt;br&gt;
To make our life easy in code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The approach Pros:-
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;very suitable for complex domains.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The layers/domains of isolation concept.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Communication&lt;/strong&gt; &lt;br&gt;
bridge the gap between domain business and developers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flexibility&lt;/strong&gt; &lt;br&gt;
Since the system was built to model the &lt;br&gt;
   business domain, it will generally be more flexible to &lt;br&gt;
   change as new functional requirements would fit in &lt;br&gt;
   naturally.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintainability&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The approach Cons:-
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Requires Domain Expertise.&lt;/li&gt;
&lt;li&gt;Requires Developers have the knowledge of the DDD and Layered arch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Costly&lt;/strong&gt; 

&lt;ol&gt;
&lt;li&gt;This often results in a longer development and 
duration that ultimately translates to higher costs 
for the business, 
2.Therefore it isn’t suited for short-term projects or 
projects where there isn’t a high domain complexity.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HINT: I will add a POC project using ruby on rails later &lt;/p&gt;

</description>
      <category>rails</category>
      <category>ddd</category>
      <category>layeredarch</category>
    </item>
  </channel>
</rss>
