Quantivex Technologies logo

How to Structure a Web Project Folder: Best Practices

By Hafeez Ur Rehman · November 19, 2026 · 7 min read

Every web project starts with a clean slate, but without a clear organizational system, codebases quickly deteriorate into chaos. Files get dumped into generic directories, circular dependencies emerge, and simple feature additions turn into archaeological digs. A disciplined folder structure is not about strict dogma; it is about reducing cognitive overhead, establishing predictable patterns, and allowing multiple developers to collaborate without stepping on each other's toes.

Whether you are building a straightforward marketing site, a large-scale Single Page Application (SPA), or a full-stack monorepo, organizing your project intentionally from day one pays compound dividends over the life of your application.

Core Principles of Project Organization

Before creating a single folder, it helps to understand the underlying principles that keep a codebase healthy as it scales from dozens of files to thousands.

  • Predictability: A developer unfamiliar with the codebase should be able to guess where a file lives based solely on its purpose or name.
  • Co-location: Keep code that changes together close together. If a component relies on a specific stylesheet, unit test, and mock dataset, place them in the same directory rather than scattering them across separate top-level folders.
  • Single Responsibility: Avoid catch-all files like helpers.js or misc.css. Every file and folder should have a clearly defined, narrow responsibility.
  • Shallow Over Deep: Over-nesting creates friction. Navigating through six layers of subfolders to reach a three-line utility function slows down development and complicates import paths. Try to keep folder depth to three or four levels at most.

1. The Fundamental Structure for Static Sites

For standard multi-page websites relying primarily on vanilla HTML, CSS, and JavaScript, simplicity is paramount. The directory should clearly delineate source assets from core documents.

  • index.html, about.html, contact.html: Placed at the root level for clear routing in static hosting environments.
  • assets/: Contains all static media that does not require compilation.
    • images/: Subdivided into vectors (SVG), photography (WebP, PNG), and user avatars or icons.
    • fonts/: Self-hosted typography files (WOFF2).
  • css/ or styles/: Contains your base stylesheets, reset files, and modular page styles.
  • js/ or scripts/: Contains modular JavaScript files, often split into entry scripts and utilities.

This layout is intuitive, has near-zero barrier to entry, and works seamlessly with local file servers and simple static hosting providers.

2. Modern Frontend Applications (React, Vue, Svelte)

Modern frontend frameworks require a more robust structure to handle components, state management, routing, and build tools. Two main paradigms dominate modern application design: Grouping by Type and Grouping by Feature.

The Anti-Pattern: Overusing "Group by Type"

Early-stage projects often default to organizing the entire src/ directory strictly by technical file type: a components/ folder holding 100 components, an actions/ folder holding 100 actions, and a reducers/ folder holding 100 reducers. While this works for tiny projects, it forces developers to constantly jump between three or four distant directories just to edit a single feature.

The Better Solution: Feature-First (Domain-Driven) Architecture

In a feature-driven architecture, the project is divided into business domains or functional modules. Shared code lives in a global location, while domain-specific code is self-contained.

Consider a typical production-grade frontend layout inside the src/ folder:

  • assets/: Global images, icons, and static vector graphics.
  • components/: Truly generic, reusable UI primitives (buttons, modals, input fields, layout wrappers). These components contain no business logic.
  • config/: Application constants, third-party library configurations, and environment setups.
  • features/ (or modules/): The core of your application. Each subfolder represents a distinct feature set (e.g., auth/, billing/, dashboard/).
    • Inside each feature, you colocate the components, API hooks, state slices, and utility functions that belong exclusively to that domain.
  • hooks/ (or composables/): Shared, non-feature-specific hooks for stateful logic (e.g., useDebounce, useWindowSize).
  • layouts/: High-level page shells (e.g., authenticated app shell, public landing shell).
  • pages/ (or routes/): View components tied directly to your router. When using file-system routers like Next.js or Nuxt, this folder mirrors your URL paths directly.
  • services/ or api/: HTTP client setup, global API interceptors, and base endpoints.
  • utils/ or lib/: Pure, stateless utility functions (formatting dates, sanitizing strings, parsing currency).

Comparing Architectural Approaches

Choosing the right structure depends heavily on the size of your team and the expected lifecycle of the project.

Structure Strategy Best Suited For Primary Advantage Primary Trade-off
Flat / Type-Based Prototypes, small sites (< 20 components) Fast to set up; low initial cognitive load. Becomes unmaintainable as components multiply.
Feature-Driven Medium-to-large single-page apps High co-location; easy to delete or refactor features. Requires discipline to decide what is "shared" vs "feature-specific".
Monorepo / Workspace Multi-app ecosystems, enterprise teams Code sharing between web, mobile, and backend packages. Requires specialized build tooling (e.g., Turborepo, Nx).

3. Managing Root-Level Files Cleanly

The root folder of a project is the first thing a developer encounters. A cluttered root makes a project look unmaintained and confusing. To maintain cleanliness, keep the root strictly reserved for global configurations and infrastructure files.

A standard clean root should contain:

  • Documentation: A comprehensive README.md, along with CONTRIBUTING.md and LICENSE where applicable.
  • Dependency Definitions: package.json and its corresponding lockfile (e.g., package-lock.json, pnpm-lock.yaml). Avoid committing multiple different lockfiles to the same repository.
  • Environment Variables: An .env.example template showing required keys with dummy values. Never commit active .env.local or secret-bearing configuration files.
  • Tool Configurations: Tooling files such as tsconfig.json, .eslintrc.json, prettier.config.js, and build bundler setups (e.g., vite.config.js).
  • Ignored Lists: A strict .gitignore preventing accidental check-ins of build directories (dist/, .next/), caches, and node_modules/.

4. Naming Conventions and Consistency

Inconsistent casing and nomenclature undermine even the most carefully planned folder hierarchy. Operating systems handle file casing differently: macOS and Windows are generally case-insensitive by default, whereas Linux (often your deployment or CI/CD environment) is case-sensitive. Inconsistent casing can lead to painful build failures that only trigger in production.

  1. Folders: Use lowercase kebab-case (e.g., user-profile/) or uniform camelCase. Kebab-case is widely considered safest across varying operating systems.
  2. Components: Match the component name directly. In React ecosystems, PascalCase (e.g., UserProfileCard.tsx) is common. If colocating files in a folder, name the directory UserProfileCard/ containing index.tsx, UserProfileCard.module.css, and UserProfileCard.test.tsx.
  3. Utilities and Services: Use kebab-case.ts or camelCase.ts (e.g., format-currency.ts or dateUtils.ts). Choose one pattern and enforce it throughout the project.

Key Takeaways

  • Optimize for deletion: A well-structured project allows you to remove a feature cleanly by deleting a single directory, without leaving orphan files scattered across the system.
  • Adopt a feature-first mindset: For modern web applications, group code by business domain rather than technical layer.
  • Keep generic UI separate: Maintain a dedicated, logic-free folder for base design system elements like buttons, inputs, and layouts.
  • Enforce casing rules: Use uniform casing across files and directories to avoid cross-platform deployment bugs.
  • Keep the root minimal: Restrict your top-level directory strictly to infrastructure, build tool configs, documentation, and dependencies.

Frequently Asked Questions

Should I organize my components by feature or keep them in a shared components folder?

Use both strategically. Truly generic, reusable UI primitives that do not contain application business logic—such as standard modals, tooltips, buttons, and form inputs—belong in a top-level shared components/ folder. Components that contain specific business rules, fetch specific data, or relate to a single functional area belong inside that specific domain's feature folder.

How many layers of folder nesting are considered too many?

A good rule of thumb is to avoid nesting deeper than three to four levels. Deep nesting leads to unwieldy relative imports (e.g., ../../../../utils/format.js) and makes repository navigation tedious. If you find your folder hierarchy going deeper than four levels, consider flattening your feature boundaries or utilizing path aliases (such as mapping @/ to your src/ directory).

Where should tests and documentation live in the structure?

Tests should be colocated directly alongside the code they test. For example, place Button.test.tsx in the exact same directory as Button.tsx. This makes it instantly apparent whether a file has unit test coverage, and ensures tests are moved or deleted alongside their associated implementation. Broad end-to-end (E2E) tests or integration suites that touch multiple flows are the exception; these should reside in a dedicated tests/ or e2e/ directory at the root.

Hafeez Ur Rehman · Editor & Publisher

He is a digital entrepreneur who builds digital solutions and online businesses.

Related articles