The importance of a good project structure and how I structure mine.
--
Brief . . .
Whenever we start with a project, there are a few things we need to make sure of —
- Reusable code,
- Destructuring code,
- Easier codability,
- Easier searchability of content (code under focus),
- A better view of code ( less amount of code in a single view),
- Improving the level of abstraction of code.
And all this can be achieved via a good project folder structuring
I will be using a web app to explain mine, hope this helps for other domains as well.
Main Project Folder —
(bold >> folders and normal >> files)
— libraries
— public
— src
| — js
|||| — actions (redux)
|||| — components (redux)
|||| ||||— views (contains components like dashboards, etc which may or may not be reusable anywhere)
|||| |||| ||||— Sub-views (contains sub-components like buttons, appbars, drawers etc which is a part of the main view)
|||| — helpers (reusable functions that could be used anywhere like string checking, etc)
|||| — pages (basic URL routes, sign-in, sign-up, main-page, etc)
|||| — reducers (redux)
|||| — routes (API calls)
|||| — stores (redux)
|||| — App.jsx
| — styles
|||| — components
|||| — index.scss
— starter app
[IMPORTANT] if you notice in the picture
there's an index.js or index.jsx file in every folder (except the main src folder). Over here I import all the files on the same level and export it from one place, so later if I create a new file may it be any folder, I just need to import it in the index file in the same folder and thus making it available everywhere.
So what I get by maintaining this
- I know where to create my specific files/components/views and where to import them so that it’s available everywhere,
- I can reuse the file as I now know what it does,
- Code is destructured,
- Easy code ability (from smaller file size),
- Code snippet search is easy,
- A lesser amount of text means a better view,
- This adds a level of abstraction,
- This makes the project to be worked on from different endpoints thus increasing the production speed,
- Makes the code easier to understand, helping the developer to only need to check the input and output data type/structure, etc (another advantage of abstraction),
- I think I can add literally all the features of abstraction,
- you could all increase the level of abstraction to another level like —
PROJECT STRUCTURE
— BACKEND
— FRONTEND
| — DESKTOP (web app / website)
| — MOBILE (mobile app — (decide accordingly))
|||| — IOS
|||| — android
|||| — native-app
Some additional points which you need to make sure if you are a group of people ( probably using a common repository )
- Keep the naming in smaller cases (for windows it’s fine but in Linux, it tends to by-default treat everything in small cases)
- Do try to follow the [IMPORTANT] point
- And use an IDE something like a VS Code or whatever which gives us a good view of the project file structure
And that's all for now…