<?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: Adomas S</title>
    <description>The latest articles on Forem by Adomas S (@adomassk).</description>
    <link>https://forem.com/adomassk</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%2F1250463%2F3ca13290-249c-45ea-b4a0-edf80da847dc.jpeg</url>
      <title>Forem: Adomas S</title>
      <link>https://forem.com/adomassk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/adomassk"/>
    <language>en</language>
    <item>
      <title>Q: How would you structure project code?</title>
      <dc:creator>Adomas S</dc:creator>
      <pubDate>Sat, 06 Jan 2024 19:11:48 +0000</pubDate>
      <link>https://forem.com/adomassk/q-how-would-do-you-structure-project-code-2d6i</link>
      <guid>https://forem.com/adomassk/q-how-would-do-you-structure-project-code-2d6i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Note: new here at dev.to, and couldn't quickly find a similar post/thread&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How would you structure project code? (I'm talking mostly about directories here)&lt;/p&gt;

&lt;p&gt;I mainly work in web development with React, but I have worked on multiple project in varying size and longevity.&lt;/p&gt;

&lt;p&gt;One thing that always annoys me is when I see, what I call, (maybe there's a proper word for it) MVC architecture (explained below). The (only?) other way of structuring code is with what I call Feature based architecture, which I think is far more superior.&lt;/p&gt;

&lt;h3&gt;
  
  
  "MVC architecture"
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
  models/
    Post.code
  views/
    Post.code
  controllers/
    Post.code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
  reducers/
  actions/
  components/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's when code is structured by layers and in my experience structuring code in this way have two main issues:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Hard to find related code&lt;/strong&gt; - if I'm trying to pin down code for a specific logic and start at &lt;code&gt;views/PostActions.code&lt;/code&gt; I will be lucky if the code I'm looking for is in &lt;code&gt;models/PostActions.code&lt;/code&gt;, but most of the cases PostActions will have multiple actions which will do different things in model layer, good luck finding it by names alone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaboration and code reuse&lt;/strong&gt; - If I need to do something new in &lt;code&gt;views/PostActions&lt;/code&gt;, I'll look there, and will only see code related to it's view, but when adding new code I'm less likely to find a &lt;code&gt;model/Something&lt;/code&gt;, which I could reuse and not re-implement.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Feature based architecture
&lt;/h2&gt;

&lt;p&gt;Where code is structured by logical parts or domains if you will.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
  post/
    View.code
    Model.code
    Controller.code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I find this way better since it's easier to see the whole code that is related to the post, which greatly reduces both issues I mentioned in "MVC architecture". If code needs to be reused it can be extracted above &lt;code&gt;post&lt;/code&gt; which will indicate that this file can be used in all files "bellow".&lt;/p&gt;

&lt;h3&gt;
  
  
  What do you use?
&lt;/h3&gt;

&lt;p&gt;So, let me know what you think of these? Are there any other way to structure code? Which you prefer? And do you even care?&lt;/p&gt;

</description>
      <category>ask</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
