DEV Community

Cover image for Folder Structure for Modern Web Applications
Obaseki Noruwa
Obaseki Noruwa

Posted on

Folder Structure for Modern Web Applications

It is critical to create a maintainable folder structure while developing web apps, having the right files in the correct folder helps organize your code and makes other developers have an idea of how the architecture of your web application is or will be during development. In this post, I am going to explain some folder names when building your modern web project.

Maintaining a well-organized folder structure is crucial when developing web applications, even though it may not be the first thing that comes to mind when working alone or with few resources. If not, you run the risk of coming across as unprofessional.

Some Tips In Designing Your Folder Structure

  • Understand the purpose of your web project: In order to figure out how to organize your web project, you will need to establish a good understanding of what you have, depending on how many assets you are trying to organize and the features in your web applications.
  • Use proper naming convention for your folders and files, they should be descriptive of the purpose in your web application.

Folder Structures and their explanation

Assets
The assets folder contains all images, icons, css files, font files, etc. that will be used in your web application. Custom images, icons, paid fonts are being placed inside this folder.

Assets

Context
When using React Js as your preferred frontend ui library, the context folder stores all your react context files that are used across components and multiple pages.

Context

Components
The components folder holds the UI for your application. It contains all our UI components like navbar, footer, buttons, modals, cards, etc.

Components

Composables
In the context of Vue applications, a "composable" is a function that leverages Vue's Composition API to encapsulate and reuse stateful logic.

Data
The data folder is used for storing text data which will be used in different sections and pages as JSON files. Doing this will enable updating of information easier.

Data JSON

Data

Features
This folder contains individual folder feature for each page (authentication, theme, modals). For example each page might have a modal feature.

Features

Hooks
Hooks are functions that let you “hook into” React state and lifecycle features from function components. Also we can create custom hooks whose name starts with 'use' and can be used to call other hooks.

Hooks

Layouts
When defining the general look and feel of the web page, the Layouts folder comes in handy. It is used to place layout-based components such as the sidebar, navbar, and footer. If your web application has many layouts, this folder is a fantastic place to save them.

Layouts

Modules
Modules folder handles specific tasks in your application.

Modules

Pages
The pages directory contains your web application views. Pages directory in frontend frameworks like Next Js and Nuxt Js reads all files inside the directory and automatically creates the router configuration for you.

Public
The public directory is directly served at the server root and contains public files that won't change e.g favicon.ico.

Routes
The routes folder is just a place in your web application to store the routes path to different screens.

Utility/Utils
This folder is for storing all utility functions, such as auth, theme, handleApiError, etc.

Views
Views folder are like the pages folder, The views are used to represent your pages properly, that users can navigate back and forth.

Conclusion

A good folder structure allows you and other developers to find files faster and manage them more easily. A well-organized folder structure makes you appear professional.

Latest comments (48)

Collapse
 
tarxjvf profile image
shell

Nice info

Collapse
 
awatansa profile image
awatansa

Seems to me like a good approach initially (means for small sized projects), but very bad on enterprise level projects.

My Point of view is to create a structure more like modules/feature based and keep some common functions/classes or whatever in a separate folder such as common/core.

Collapse
 
henningholm profile image
Henning • Edited

To me this seems like a nightmare arcitecture. My experience is that on most projects there are people comming and going, many with limited experience.

By using a more horisontal arctecture projects will quickly become very messy, and if some people dont follow it correct, (which is going to happen), it will create a lot of confusion. As uncle Bob says in one of his talks => you should be able to somehow visualize the app by looking at the folder structure. Vertical/feature based arcitecture pretty much always better in my opinion... As we all need to take some shortcuts once in a while, as long as the shortcut only affect the feature your building, there is no issue because of the encaptulation. For me this description is very much the oposite of encaptulation which one of the main reason why our job as developers can be a nightmare.

Collapse
 
chasi profile image
Wayne "Chasi" Godo

I've been needing this. Thank you!

Collapse
 
konhi profile image
Jan Szymański

that's cool, but i prefer "move the files around untill it feels right"

Collapse
 
devnaqvi profile image
devnaqvi • Edited

Thanks but I disagree with you on keeping the styles in assets directory.

Collapse
 
shubhsharma19 profile image
Shubh Sharma

Great share!

Collapse
 
szeredaiakos profile image
szeredaiakos

That is functional domain partitioning. It's very good at creating small apps fast. However if extended it completely breaks down on maintenance. Recomended only for less than 30 un-nested screens.

I prefer problem domain. In all cases even if i have to write more code.

Collapse
 
quocbahuynh profile image
Quoc Huynh Website

Unfortunately, it's very bad when you are still using pure JS in a React project. In the real-world, we will work with a lot of developers, and each developer will be responsible for write a user story. You should put all related components into a folder.

Collapse
 
leob profile image
leob • Edited

Yeah not bad, very generic though, not every project needs all these folders, and some projects need more/other folders ... another remark is that oftentimes much of the folder structure tends to be more or less 'dictated' by the framework that you're using.

The distinction between views and pages is pretty vague - views are supposed to be "higher level" than components, but "lower level" than pages?

(funny how I'm in fact contradicting myself because in my latest project I have indeed "components", "views" and "pages", so it seems to fulfill a need, lol)