<?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>Forem: Etshy</title>
    <description>The latest articles on Forem by Etshy (@etshy).</description>
    <link>https://forem.com/etshy</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%2F632461%2Fece7beb4-7241-4d87-8812-7b5eda37e831.png</url>
      <title>Forem: Etshy</title>
      <link>https://forem.com/etshy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/etshy"/>
    <language>en</language>
    <item>
      <title>Reflexion note about: DDD and Aggregate implementation with Symfony and Doctrine</title>
      <dc:creator>Etshy</dc:creator>
      <pubDate>Tue, 27 Jun 2023 23:40:31 +0000</pubDate>
      <link>https://forem.com/etshy/reflexion-note-about-ddd-and-aggregate-implementation-with-symfony-and-doctrine-2f9f</link>
      <guid>https://forem.com/etshy/reflexion-note-about-ddd-and-aggregate-implementation-with-symfony-and-doctrine-2f9f</guid>
      <description>&lt;p&gt;Hey Everyone, that's my first post and that's a quite heavy one (for me at least).&lt;/p&gt;

&lt;p&gt;It's been quite a long time I read about how to implement DDD and especially Aggregate within a Symfony and Doctrine project and every implementation I saw until now always feels like there is something missing.&lt;/p&gt;

&lt;p&gt;So here's some shower thoughts I had today about this.&lt;br&gt;
Of course this idea is far from conclusive and I feel liek it's REALLY too heavy for a real project. And I make this Post mostly to have some backup, if someone ever find this page.&lt;/p&gt;

&lt;p&gt;So to summarise, I saw a lot article about making either an Doctrine Entity/Document as the Aggregate itself, or making an aggregate containing Doctrine entities. And Repositories creating these Aggregates.&lt;/p&gt;

&lt;p&gt;That's fine by me, and working mostly with ODM I'll surely take the first approach as my go-to as it's way simpler than what I thought about.&lt;/p&gt;

&lt;p&gt;But I feel like having our "DataModel" as or within Aggregate are not good, keeping the Infrastucture and Domain layer too tied up.&lt;/p&gt;
&lt;h2&gt;
  
  
  My "idea", FINALLY!
&lt;/h2&gt;

&lt;p&gt;With all that as backstory, my "idea" is quite simple... &lt;br&gt;
Making the DataModel (Doctrine entities/Documents) part of the Infrastructure layer, and making Aggregates simple classes that are mapped from Doctrine Entities.&lt;/p&gt;

&lt;p&gt;For a Query We'd have a process like this:&lt;br&gt;
&lt;code&gt;Controller&lt;/code&gt; &amp;gt; &lt;code&gt;QueryHandler&lt;/code&gt; &amp;gt; &lt;code&gt;AggregateRepositoryAbstractionService&lt;/code&gt; (didn't think about a name yet) &amp;gt; &lt;code&gt;Repository&lt;/code&gt;&lt;br&gt;
The &lt;code&gt;Repository&lt;/code&gt; is returning the Doctrine Entity/Document&lt;br&gt;
The &lt;code&gt;AggregateRepositoryAbstractionService&lt;/code&gt; is calling the repository and map these Entities/Documents to the chosen Aggregate and return the Aggregate&lt;/p&gt;

&lt;p&gt;This way, the &lt;code&gt;DataModel&lt;/code&gt;s are completely separated from the &lt;code&gt;Aggregate&lt;/code&gt;s and you can easily make different &lt;code&gt;Aggregate&lt;/code&gt;s for different context.&lt;/p&gt;

&lt;p&gt;Let's take the common example with &lt;code&gt;Post&lt;/code&gt; and &lt;code&gt;Comments&lt;/code&gt;.&lt;br&gt;
And different contexts : &lt;code&gt;GetPostAndComments&lt;/code&gt;, &lt;code&gt;GetPostOnly&lt;/code&gt;, &lt;code&gt;GetComment&lt;/code&gt;, etc.&lt;br&gt;
You could make multiple Aggregate &lt;code&gt;PostFullAggregate&lt;/code&gt;, &lt;code&gt;PostOnlyAggregate&lt;/code&gt;, &lt;code&gt;PostCommentAggregate&lt;/code&gt;, etc.&lt;br&gt;
I think you get this now, &lt;code&gt;PostFullAggregate&lt;/code&gt; (with &lt;code&gt;/posts/1&lt;/code&gt; url) would query the &lt;code&gt;Post&lt;/code&gt; and every &lt;code&gt;Comment&lt;/code&gt;s, &lt;code&gt;PostCommentAggregate&lt;/code&gt; (with &lt;code&gt;/posts/1/comments/1&lt;/code&gt; url) would query only a comment of the post etc.&lt;/p&gt;

&lt;p&gt;Concerning File structure you could have something like that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── src
│   ├── Application
│   ├── ├── Query // contains the Query, QueryHandler, etc.
│   ├── ├── RepositoryAbstraction // not sure if this should be here though
│   ├── Domain
│   │   ├── Post
│   │   ├── ├── PostFullAggregate.php
│   │   ├── ├── PostCommentAggregate.php
│   ├── Infrastucture
│   ├── ├── DataModel
│   ├── ├── Mapping
│   ├── ├── Repository
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like I said, It's a bit more heavy to develop than common implementation you could find here and there, because you have both Aggregates and DataModel and an optional RepositoryAbstraction.&lt;/p&gt;

&lt;p&gt;Hope someone will find this page and will give me his opinion about this, maybe I'm completely wrong.&lt;/p&gt;

&lt;p&gt;ps: This Article is really rough, and I could edit some things.&lt;/p&gt;

</description>
      <category>doctrine</category>
      <category>programming</category>
      <category>php</category>
      <category>ddd</category>
    </item>
  </channel>
</rss>
