{
    "componentChunkName": "component---src-templates-post-js",
    "path": "/blog/folder-structure-n-component-naming",
    "result": {"data":{"markdownRemark":{"html":"<p>I bet, for many developers or for me at least, there’s often a dilemma in the initial phase of a development project.\nThat is …</p>\n<p><strong>_ How to set up the folder structure and file naming conventions, a.k.a the project structure? _</strong></p>\n<p>Project structure plays a critical role in the long-term productivity, maintainability and architectural excellency of any development project.\nHaving laid it out myself as well as worked on someone else’s setup, I learned it the hard way.</p>\n<p>As ReactJS is my primary FE library of choice, this article will depict a sample ReactJS project and its structure.</p>\n<p><code class=\"language-text\">Precaution: Nothing here is written in rocks, the methodology I am describing here is just one of many approaches 😏</code></p>\n<h3>Folder Structure</h3>\n<p>One of the questions I often face is regarding to how structure files and folders. In this post, I am starting off with a minimum structure, the one created with create-react-app.\nThe <code class=\"language-text\">create-react-app</code> generates a basic project for us, containing in its root, the files: <code class=\"language-text\">.gitignore</code>, <code class=\"language-text\">package.json</code>, <code class=\"language-text\">README.md</code>, <code class=\"language-text\">yarn.lock</code></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 320px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/118946372103c6d0c9ea7b0d4e13bcab/4e610/create-react-app-structure.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 119.42857142857142%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAYCAYAAAD6S912AAAACXBIWXMAAAsTAAALEwEAmpwYAAACeklEQVQ4y52V2ZKaQBSG5wGSqowLoKwKKioqmw3N6pbJVd7/YTL0mTrtEh1FLS9OQQt+/P9Zut9k1arsscuGoxlzZgGbTH3W6faY1DFqQ5T0uvh80/QRo8kaknQN5eoPZPkWZLkPbUEFQdRuhijpIHWM0/UYoqRXb4KoMU0fwmweMlRKkxXzA8ryYsd2H39ZUe5YFBV8necbRmnJFMVkgqRfqD0BcSErJgfO5iHMXQLLZQq2PQfdGPHAD+rG//iu7gqIi/HERWUQhCnk+QYGgyk0W8pTlq+AnW4P7PGCuV4MYZjyl369SzyP5zn6lq/bCg95gK7cZ72+DYPRDFwvgsnUw49cJb4Gfm0Zi4O5NK0pZNkGoiiHIExeB+JV1Sywhg7QZAXhAdZodm/afAqoqBZYA4f3IkJRoTML7sLuAtFyrz/mdhcuAc+LwXUjwKK9BOSWB1NIMIdxAWm2AdOaQKutvm7ZNCcQLlNud+r4D9U9tIxVjmkJlJbguoTDELqP2734EIhF8fwYSJRz0Hujy6t9jGZbuZiWmj7c5xCLgnZJlJ2szxeEr5ckBc+nvPKy0q9XeHjAc4jAothBlm8OwD0EN4wgoPw336eg1AERhAPf648Z2o3iEopiC4RkuGHAj5+tC7vcckuut3ycZVkxGW5VqIYm5X70goRbRuX4B8znw6Kcbw5GzwZCct6Dq/UHV7kkGQeKovZc25wDVW0IJC4gz7dQrn7Dfn9MUP3zk3LMoW6M2GDoMNeL2MKNWBQXzHGCi4Pp3gF1pRBtoWU8Bmx7wWcYx1C4Y/WGUt42n3iDIYha1WzJVautVI2mXLUFtZI6RnV8/kT8+wLyU5eXoyEJYgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"initial structure by create-react-app\"\n        title=\"initial structure by create-react-app\"\n        src=\"/static/118946372103c6d0c9ea7b0d4e13bcab/4e610/create-react-app-structure.png\"\n        srcset=\"/static/118946372103c6d0c9ea7b0d4e13bcab/1aaec/create-react-app-structure.png 175w,\n/static/118946372103c6d0c9ea7b0d4e13bcab/4e610/create-react-app-structure.png 320w\"\n        sizes=\"(max-width: 320px) 100vw, 320px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>It also generates the folders: <code class=\"language-text\">public</code> and <code class=\"language-text\">src</code>. The last one is where we keep our source code.</p>\n<h3>Containers and Components</h3>\n<p>I tried the separation between Containers and Presentation Components in the project’s root folder. I mean, inside src, I had a folder named <code class=\"language-text\">components</code> and another folder named <code class=\"language-text\">containers</code>:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 554px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/ce4b77fdb385d322337943cd72bb030c/5c9af/component-container-sep.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 17.71428571428571%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAS0lEQVQY06XMsREAIQhEUfqvjcDUCnBMlIBBSNYxuAaO4M2PdikikJl4PeeU0RgDIoI5J/beUNXf3p5aa2Bm9N6x1qofmhk+7l52AYToMz+XPSJhAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"following the conceptual separation in the project structure\"\n        title=\"following the conceptual separation in the project structure\"\n        src=\"/static/ce4b77fdb385d322337943cd72bb030c/5c9af/component-container-sep.png\"\n        srcset=\"/static/ce4b77fdb385d322337943cd72bb030c/1aaec/component-container-sep.png 175w,\n/static/ce4b77fdb385d322337943cd72bb030c/98287/component-container-sep.png 350w,\n/static/ce4b77fdb385d322337943cd72bb030c/5c9af/component-container-sep.png 554w\"\n        sizes=\"(max-width: 554px) 100vw, 554px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>However, this kind of approach introduced some issues like:</p>\n<ul>\n<li>Subjectives rules</li>\n</ul>\n<p>You don’t have clear rules about what is a Container and what is a Presentational Component. The difference between each other can be subjective and when you are in a team, it will be hard to have all the developers agreeing and judging equally this matter.\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 700px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/e3f435c8eb31db842147959728e1183c/554bf/subjective.jpg\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 74.28571428571428%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAMEBf/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAHbQyaLwK//xAAZEAACAwEAAAAAAAAAAAAAAAABAgADESH/2gAIAQEAAQUCZgFS7ZscEwUtoHP/xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAYEAADAQEAAAAAAAAAAAAAAAAAEEERIv/aAAgBAQAGPwLTpQi//8QAGhABAAIDAQAAAAAAAAAAAAAAAQARITFRwf/aAAgBAQABPyFhxE0B7KTFdYuAFNiUAW3s/9oADAMBAAIAAwAAABCDD//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABURAQEAAAAAAAAAAAAAAAAAAAEQ/9oACAECAQE/EFn/xAAaEAEBAQEBAQEAAAAAAAAAAAABESEAUTFB/9oACAEBAAE/EFbUeB+vnSINgl12iectOGtG5Pnzqs4sbHzs8o1Bvf/Z'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"lol...\"\n        title=\"lol...\"\n        src=\"/static/e3f435c8eb31db842147959728e1183c/03346/subjective.jpg\"\n        srcset=\"/static/e3f435c8eb31db842147959728e1183c/71299/subjective.jpg 175w,\n/static/e3f435c8eb31db842147959728e1183c/1e9fe/subjective.jpg 350w,\n/static/e3f435c8eb31db842147959728e1183c/03346/subjective.jpg 700w,\n/static/e3f435c8eb31db842147959728e1183c/554bf/subjective.jpg 720w\"\n        sizes=\"(max-width: 700px) 100vw, 700px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<ul>\n<li>Lost dynamism of the components</li>\n</ul>\n<p>Even when you decide a component fits in one of the specific types, it’s easy to get it changed along the project lifetime, and forcing you to move it from components to containers folder and vice-versa.</p>\n<ul>\n<li>Components with the same name</li>\n</ul>\n<p>Components should have declarative and unique names in the application, to avoid confusion about the responsibility of each one. However, the above approach opens a breach to having two components with the same name, one being a container and other being a presentational.</p>\n<ul>\n<li>Productivity loss</li>\n</ul>\n<p>You have to constantly navigate between containers and components folders, even when working in a single feature. Because it’s common that a single feature has components of the two types.</p>\n<p>For those reasons, I realized that when organizing folders and files, it’s irrelevant to split the components by the concept of presentational vs container.</p>\n<h3>Separating and grouping the code</h3>\n<p>Inside the <code class=\"language-text\">components</code> folder, I would group the files by module/feature.</p>\n<p>For example, for a CRUD of user, the structure would be as the following:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 545px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/e8b03b85d021216f7f756fdcc48b0815/084e3/components-user-scope.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 20%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAXElEQVQY052OuwpAIQxD+/9/5yYOgmCF4uCjOOdSweGOOpwk0yHUWoOx1sKcc6Oqz1CtFTFGhBCQc8YYY0utXyCzMjOcc/De732E5/ENZNF7h4ggpYRSyu/hrfADn94wV1szX/kAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"scoped for user module\"\n        title=\"scoped for user module\"\n        src=\"/static/e8b03b85d021216f7f756fdcc48b0815/084e3/components-user-scope.png\"\n        srcset=\"/static/e8b03b85d021216f7f756fdcc48b0815/1aaec/components-user-scope.png 175w,\n/static/e8b03b85d021216f7f756fdcc48b0815/98287/components-user-scope.png 350w,\n/static/e8b03b85d021216f7f756fdcc48b0815/084e3/components-user-scope.png 545w\"\n        sizes=\"(max-width: 545px) 100vw, 545px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>When a component is composed by more than one file, I’d put this component and its files in a folder with the same name. Eg: Let’s say you have a <code class=\"language-text\">Form.css</code> containing the <code class=\"language-text\">Form.jsx</code>’s styles. In this case, the structure would be like:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 544px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/38b696acef56a62db546bf7d49851c79/b0e00/components-user-scope-enhanced.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 24.571428571428573%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAbElEQVQY06XOOwrAIBAEUO9/NjtBG8FCBfH/OcAEFxJIGVPMLkzxdllKCaUUzDnRWsMY45XdfwmLMUJrDaUUnHMPcoIRuNYiSEoJ7z16779QtkcIAcYYcM4hhEDOGfvQMVhrJdRaS/v+7gS8AFKJe89SZ/qJAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"scoped for user module (enhanced)\"\n        title=\"scoped for user module (enhanced)\"\n        src=\"/static/38b696acef56a62db546bf7d49851c79/b0e00/components-user-scope-enhanced.png\"\n        srcset=\"/static/38b696acef56a62db546bf7d49851c79/1aaec/components-user-scope-enhanced.png 175w,\n/static/38b696acef56a62db546bf7d49851c79/98287/components-user-scope-enhanced.png 350w,\n/static/38b696acef56a62db546bf7d49851c79/b0e00/components-user-scope-enhanced.png 544w\"\n        sizes=\"(max-width: 544px) 100vw, 544px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>The test files stay with the file that is being tested. In the above case, the test for <code class=\"language-text\">Form.jsx</code> would stay in its same folder and would be named as <code class=\"language-text\">Form.spec.jsx</code></p>\n<h3>UI Components</h3>\n<p>Beyond separating the components by modules, I’d also include a <code class=\"language-text\">UI</code> folder inside <code class=\"language-text\">src/components</code>, to keep all the generic components in it.\nUI components are components generic enough not to belong to a module and likely to be reused. I could go with <code class=\"language-text\">Common</code> instead of <code class=\"language-text\">UI</code>, but the name <code class=\"language-text\">UI</code> represents the difference well with <code class=\"language-text\">logic</code>.\nExamples of these components are: Buttons, Inputs, Checkboxes, Selects, Modals, Data display elements, etc…</p>\n<h3>Naming components</h3>\n<p>The name we give to the components, should be clear and unique in the application, in order to make them easier to find and to avoid possible confusions.\nA component’s name is very handy when we need to debug using tools as <code class=\"language-text\">React Dev Tools</code>, and when run time errors happen in the application. The error always come with the component name where it happened.\nBasically, a component that is located at: <code class=\"language-text\">components/User/List.jsx</code> would be named as <code class=\"language-text\">UserList</code>.\nWhen the file is inside a folder with same name, we don’t need to repeat the name. That said, <code class=\"language-text\">components/User/Form/Form.jsx</code>, would be named as <code class=\"language-text\">UserForm</code> and not as <code class=\"language-text\">UserFormForm</code>.</p>\n<ul>\n<li>Search for the component definition</li>\n</ul>\n<p>I use <code class=\"language-text\">sublime</code> or <code class=\"language-text\">VSCode</code> as the IDE for the web development, and they support the <em>fuzzy search</em>.\nTherefore, file name not being identical to the component name doesn’t pose any difficulty in search.\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 700px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/4a3d8c230514d80a241781a61993aa4c/acc8b/fuzzy-search-sublime.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 28.57142857142857%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAIAAABM9SnKAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAyElEQVQY04XL246CMBCA4T6GiCjIQg8s7aCdWiiHoKxkN9H3fxzjaS/QxOTLZJKZn0hZQuEYwyj+9vz1zItmXnib7839eBEkQZAEK0oG89e1x8Z243gefk5QVJttXWwcFNUrBSXlmmcmyy3lSGz1W46j6491PTTtYMuucr1GJ5VWgBNSaco1E4YJZMIQiwez7dHsJeySNA/XIorFckXnfvzKX3w94ysCuYPMATS5cinTlOPd/wcThme7yfKIqcCUY8qQ8untY3wB2Z4/XaOoTsEAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"fuzzy search on sublime\"\n        title=\"fuzzy search on sublime\"\n        src=\"/static/4a3d8c230514d80a241781a61993aa4c/39600/fuzzy-search-sublime.png\"\n        srcset=\"/static/4a3d8c230514d80a241781a61993aa4c/1aaec/fuzzy-search-sublime.png 175w,\n/static/4a3d8c230514d80a241781a61993aa4c/98287/fuzzy-search-sublime.png 350w,\n/static/4a3d8c230514d80a241781a61993aa4c/39600/fuzzy-search-sublime.png 700w,\n/static/4a3d8c230514d80a241781a61993aa4c/57cd1/fuzzy-search-sublime.png 1050w,\n/static/4a3d8c230514d80a241781a61993aa4c/4af54/fuzzy-search-sublime.png 1400w,\n/static/4a3d8c230514d80a241781a61993aa4c/acc8b/fuzzy-search-sublime.png 1568w\"\n        sizes=\"(max-width: 700px) 100vw, 700px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<ul>\n<li>DRY on imports</li>\n</ul>\n<p>When I followed this naming convention, I could avoid some lengthy and repeated names in the import path.\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 544px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/0575b769393e900d8878f4861e9626e9/b0e00/shorter-import-path.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 25.142857142857146%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAsklEQVQY012Q2Q6FIAxE/f8PVGPcRdxXwNe5mSYQvQ8nLW2ZgUbTNKGqKjRNg6IoUNe1nEnbtlBKYRxHXNeF4zhwnqfk5L7vT04iCsZxjCzLJJI0TYUkSSTmeS5GZVmKcd/34L1/QcaIjuu6wlqL53ngnPvAOjHGBHj5nXsxeSHFtNZYlkVc53kOsMb+tm2hz+jhzL7v3xeyyF11XRf2xm/xi9zfMAyyQ99n5Iyfo8lb8AehoHU2hWhiggAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"shorter import path\"\n        title=\"shorter import path\"\n        src=\"/static/0575b769393e900d8878f4861e9626e9/b0e00/shorter-import-path.png\"\n        srcset=\"/static/0575b769393e900d8878f4861e9626e9/1aaec/shorter-import-path.png 175w,\n/static/0575b769393e900d8878f4861e9626e9/98287/shorter-import-path.png 350w,\n/static/0575b769393e900d8878f4861e9626e9/b0e00/shorter-import-path.png 544w\"\n        sizes=\"(max-width: 544px) 100vw, 544px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<h3>Screens</h3>\n<p>Screens, as the name already suggests, would be the screens that we have in the application.\nFor <code class=\"language-text\">users</code> scope, we would have a screen for the user list, a screen for creating a user and a screen for editing a user.\nA screen is where I use components to compose a page. Most of the time, the screen would’t contain any logic and would be a functional component.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> UserForm <span class=\"token keyword\">from</span> <span class=\"token string\">'../../components/User/Form/Form'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">ScreensUserForm</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">match</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> params <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token operator\">!</span>params<span class=\"token punctuation\">.</span>id <span class=\"token operator\">?</span> <span class=\"token string\">'Create'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'Update'</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token plain-text\"> User\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">UserForm</span></span> <span class=\"token attr-name\">id</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>params<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n  </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ScreensUserForm<span class=\"token punctuation\">;</span></code></pre></div>\n<p>And the folder structure and component naming within the screens folder should follow the same convention as the <code class=\"language-text\">components</code> folder, except that we conveniently add a prefix to descriminate the screen components, i.e. <code class=\"language-text\">ScreensUserForm</code>\nThe final structure of this example project would look like:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 543px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/497801064f29c470a73bca89112ba28e/8586d/final-proj-structure.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 43.99999999999999%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAnElEQVQoz6WRzQqFIBCFe/9nayMJQghplkUUaro/lxko7jZdHHQ2H+enO44DIQTc940YI1JKLLqf94u6ZVmgtYZSCuu6NsEYeJ4npmmClBLOuddptUOKTM4I2vc9g733yDnXA8mZMQbzPDfHZiBp33eUUljNHY7jiGEYQP9n8f+1PwGv6+K41J0QgmOTy2qHtOi2bbDWcn8tCxPwB8TnqthuiQzKAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"the final project structure\"\n        title=\"the final project structure\"\n        src=\"/static/497801064f29c470a73bca89112ba28e/8586d/final-proj-structure.png\"\n        srcset=\"/static/497801064f29c470a73bca89112ba28e/1aaec/final-proj-structure.png 175w,\n/static/497801064f29c470a73bca89112ba28e/98287/final-proj-structure.png 350w,\n/static/497801064f29c470a73bca89112ba28e/8586d/final-proj-structure.png 543w\"\n        sizes=\"(max-width: 543px) 100vw, 543px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>Note that <code class=\"language-text\">Root.jsx</code> is the component where routing is defined</p>\n<h3>Additional thoughts</h3>\n<p>Personally, I would put some non-component files in the relevantly named folders directly under <code class=\"language-text\">src</code> folder.\nFor example, <code class=\"language-text\">utils</code> for the helper functions, <code class=\"language-text\">hooks</code> for custom hooks, and <code class=\"language-text\">services</code> for API handlers.</p>\n<h3>Conclusion</h3>\n<p>This approach is definitely a <strong>work in progress</strong> as I’d constantly seek for a better alternative, be it an enhanced version of this one or a completely different one.\nThe foremost question is if I really need <code class=\"language-text\">Screens</code> folder, but it seems convenient at the moment.</p>\n<p>To be continued …</p>","frontmatter":{"title":"Developer's Dilemma - Folder Structure and Component Naming","description":"I bet, for many developers or for me at least, there’s","date":"2020-05-14T00:00:00.000Z","slug":"/blog/folder-structure-n-component-naming","tags":["Blogging","Tech"]}}},"pageContext":{}},
    "staticQueryHashes": ["2009693873","2077189868","3303540520","3505212370","3825832676"]}