Designing Scalable Frontend Folder Structures: Best Practices and Real‑World Example
This article explains why a well‑planned directory layout is essential for frontend projects, compares default flat structures with a feature‑oriented hierarchy, and provides step‑by‑step guidance—including folder definitions, creation commands, and import rules—to build maintainable, modular applications.
In modern frontend projects, designing a clear and logical folder structure is crucial for scalability and maintainability.
Without considering micro‑frontend architectures, the article proposes practical methods to improve project organization using existing technologies, making future upgrades easier.
Default Directory Structure
Popular frameworks generate a flat, shallow directory layout that lacks hierarchy. For example, Vue.js creates a simple structure without specific guidance on where to place files.
Typical Vue directories include:
assets : static resources such as images, fonts, and CSS.
components : reusable Vue components, usually kept flat.
main.js : entry point that initializes Vue and configures plugins.
App.vue : root component serving as a container for other components.
For large projects, this flat architecture quickly becomes chaotic, requiring modularization to locate files, define clear boundaries, and avoid tight coupling.
Feature‑Based Decomposition
Complex web applications should be split into independent functional modules. Using Twitter as a case study, the article shows how the homepage consists of a timeline core surrounded by navigation, tweet creation, sidebars, and floating messages.
Placing all components in a single folder is unrealistic and hampers maintainability.
Refined Project Structure
Based on experience, a more comprehensive folder hierarchy is recommended:
components – shared UI components.
composables – reusable composition functions.
config – application configuration files.
features – core functional modules (the main codebase).
layouts – different page layouts.
lib – third‑party libraries and related configuration.
pages – page components.
services – shared services and providers.
stores – global state management.
test – testing utilities, mocks, and configurations.
types – shared TypeScript type definitions.
utils – general utility functions.
Create these directories with a single command:
mkdir -p src/{composables,layouts,pages,utils,assets,config,lib,services,test,components,features,stores,types}Key Considerations
Pages should remain minimal; most logic belongs elsewhere.
Most application code should reside in the features folder, with each subfolder containing domain‑specific code.
Ideally, components, composables, stores, and services stay within their respective feature folders; cross‑feature sharing should be planned carefully.
Inside the features Folder
Each feature subdirectory typically includes:
api – data‑fetching logic, decoupling API from UI.
components – feature‑specific components.
composables – feature‑specific composition functions.
stores – state management for the feature.
types – TypeScript definitions relevant to the feature.
index.ts – public API that re‑exports only what should be exposed, preventing circular dependencies.
Importing via the feature’s entry point is encouraged:
# Bad usage 🚫
import { UserProfile } from '@/features/profile/components/UserProfile.vue'
# Good usage ✅
import { UserProfile } from '@/features/profile'Enforce this pattern with ESLint rules such as no-restricted-imports and import/no-cycle.
Conclusion
A feature‑oriented directory architecture is a proven method for building complex frontend projects, allowing code to be decoupled into independent modules and avoiding scalability issues as the application grows.
Proper folder organization improves code predictability, reduces debugging time, and enhances the overall developer experience.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
