# Design Frontend Project Structure

> Use when starting a frontend app (React, Next.js, Vue/Nuxt, Angular, Svelte) or when an existing one has become hard to navigate — huge flat components/ and hoo

- Skill: `jeffreytse/design-frontend-project-structure` (Agent Skill)
- Install (CLI): `npx get-skill add jeffreytse/design-frontend-project-structure`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jeffreytse/design-frontend-project-structure/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: jeffreytse (https://skillmd.com/u/jeffreytse)
- Updated: 2026-12-03
- Page: https://skillmd.com/skills/jeffreytse/design-frontend-project-structure

---

---
name: design-frontend-project-structure
description: Use when starting a frontend app (React, Next.js, Vue/Nuxt, Angular, Svelte) or when an existing one has become hard to navigate — huge flat components/ and hooks/ folders, features scattered across type-based directories, unclear where API calls or state live, or barrel files slowing builds.
source: 'Dodds, "Colocation", kentcdodds.com, 2019; React Documentation (legacy), "File Structure"; Next.js Documentation, "Project Structure and Organization"; Angular, "Style Guide"; alan2207, "Bulletproof React" (GitHub); Vite Documentation, "Performance — Avoid Barrel Files"; Feature-Sliced Design, feature-sliced.design'
tags: [project-structure, frontend, react, colocation, feature-folders, maintainability]
related: [apply-package-by-feature, apply-feature-sliced-design, design-component, design-component-api, apply-module-boundary-enforcement, design-monorepo-structure]
---

# Design Frontend Project Structure

Structure a frontend in three tiers: **app** (routing, providers, global setup), **features** (self-contained business areas that colocate their components, hooks, API calls, state, and tests), and **shared** (generic UI kit, utilities, API client). Imports flow one way: app → features → shared.

## Why This Is Best Practice

**Adopted by:**
- Bulletproof React (one of the most-starred React architecture references).
- Angular's official style guide (folders-by-feature, LIFT).
- Next.js App Router (route-based colocation, private `_folders`, route groups).
- Feature-Sliced Design (a formalized version of the same layering).

**Impact:**
- Colocation (keeping code near where it's used) reduces the cost of finding, changing, and deleting code (Dodds, 2019).
- Avoiding barrel files is recommended by Vite's performance guide, because re-export files force the bundler and dev server to load far more modules than needed.

**Why best:**
- Grouping by file type (`components/`, `hooks/`, `services/`) scales poorly. Every feature is spread across every folder, and nothing signals what's safe to delete.
- Feature folders with a one-way dependency rule keep features independent, make ownership clear, and let you remove a feature by deleting a folder.

Sources: Dodds, K.C. (2019), "Colocation". React docs, "File Structure" (legacy.reactjs.org). Next.js docs, "Project Structure and Organization". Angular Style Guide. Bulletproof React (github.com/alan2207/bulletproof-react). Vite docs, "Performance".

## Steps

1. **Start simple and grow.** Under about 15 components, a flat `src/components/` plus `src/pages/` is fine (React's own docs warn against overthinking it). Introduce the three-tier structure as soon as distinct business areas appear.

2. **Use the three-tier layout:**
   ```
   src/
     app/                 # entry, router/routes, providers, global styles, error boundary
       routes/ (or Next.js app/)
       providers.tsx
     features/
       cart/
         components/      # CartDrawer.tsx, CartItem.tsx
         hooks/           # useCart.ts
         api/             # getCart.ts, addToCart.ts (data fetching + query keys)
         store/           # feature state slice (if needed)
         types.ts
         utils.ts
         cart.test.tsx
         index.ts         # public API (optional; see step 6)
       checkout/
       search/
     shared/ (or components/ + lib/)
       ui/                # Button, Modal, Input: design-system primitives, no business logic
       lib/               # api client, date/format utils, analytics wrapper
       hooks/             # generic hooks (useDebounce, useMediaQuery)
       config/            # env access, constants
     assets/
     test/                # test utils, MSW handlers, setup
   ```

3. **Enforce one-way imports:**
   - `app` may import `features` and `shared`.
   - `features` may import `shared`, and other features only through their public `index.ts` (better: compose them in `app` or routes).
   - `shared` imports nothing above it.

   Add an ESLint rule (`import/no-restricted-paths`, eslint-plugin-boundaries) to enforce this (see `apply-module-boundary-enforcement`).

4. **Keep routes/pages thin.** A page composes feature components and handles layout and route params. Business logic and data fetching live in the feature.

5. **Separate server state from client state.**
   - Server data goes through a data-fetching layer (TanStack Query, SWR, RTK Query, Apollo, framework loaders), defined in each feature's `api/`.
   - Global client state (Zustand, Redux, Pinia) only for true cross-feature UI state.
   - Local state stays in components.

6. **Use barrel files sparingly.** A small `index.ts` per feature as its public API is fine. Avoid big re-export barrels in `shared/` or `components/`, which slow dev servers and tests and break tree-shaking (Vite guide). Prefer direct imports with path aliases (`@/shared/ui/Button`).

7. **Colocate tests, stories, and styles** next to components (`Button.tsx`, `Button.test.tsx`, `Button.stories.tsx`, `Button.module.css`).

8. **Set naming conventions.** PascalCase for component files, camelCase for hooks (`useX`) and utils, kebab-case or camelCase folders consistently. Use one component per file for exported components.

9. **Follow framework routing conventions:**
   - **Next.js App Router:** `app/` for routes only; use `_components` private folders and `(group)` route groups. Keep features in `src/features`.
   - **Nuxt:** `pages/`, `components/` auto-imports, `composables/`. Group by feature subfolders.
   - **Angular:** standalone components with feature folders and lazy-loaded routes.

10. **For larger apps, adopt a formal methodology** such as Feature-Sliced Design (`apply-feature-sliced-design`), or split into monorepo packages (`design-monorepo-structure`).

## Rules

- Group by feature first, file type second (inside the feature).
- Dependencies flow app → features → shared, never upward.
- `shared/ui` holds no business logic or feature-specific API calls.
- Server state is managed by a data-fetching layer, not copied into global stores.
- Deleting a feature should mostly mean deleting its folder.

## Common Mistakes

- **One giant `components/` folder** with hundreds of files mixing primitives and feature UI.
- **Feature-to-feature deep imports** (`features/cart/components/internal/...` used by checkout). Hidden coupling.
- **Global store for everything.** Server data duplicated in Redux and going stale. Use a server-state library.
- **Barrel-everything.** `export *` chains cause slow HMR, circular imports, and bloated test runs.
- **API calls inside presentational components.** Hard to test and reuse. Keep them in feature `api/` hooks.

## Examples

**React + Vite + TanStack Query:** `features/products/api/useProducts.ts` defines the query, `features/products/components/ProductGrid.tsx` renders it, `app/routes/products.tsx` composes `ProductGrid` and `FiltersPanel`, and `shared/ui/Card.tsx` is a design-system primitive.

**Next.js App Router:** `app/(shop)/products/page.tsx` imports from `src/features/products`. Server actions live in `features/products/actions.ts`. `app/(shop)/products/_components/` holds route-only pieces.

## When NOT to Use

- **Tiny apps and prototypes.** A flat structure is faster to work in.
- **Micro-frontend architectures**, where each micro-app follows this internally but the top-level split is per team or app (see `design-monorepo-structure`).

