• Home
  • Skills
  • Projects
  • Blog
  • Resume
Resume
Naser Rasouli

Author

Naser Rasouli

Front-End developer - sharing lessons learned, notes, and write-ups from real projects.

GitHubLinkedIn

Last posts

No posts yet.

Feature-Based Architecture in React

Feature-Based Architecture in React

2025-10-29
reactjsarchitecturefrontendscalable-design

Introduction

As a React application grows, its folder structure becomes one of the most defining factors in how maintainable and scalable the app remains.
Traditional flat structures like components/, pages/, and hooks/ quickly get messy when the codebase expands. Eventually, you end up with hundreds of unrelated files dumped into global folders — making searching, refactoring, and onboarding extremely painful.

To solve this, Feature-Based Architecture groups code by domain or functionality instead of file type. This keeps each feature isolated, modular, and maintainable as the application grows.

In this article, I will walk through the concept, benefits, and — most importantly — a complete real-world folder structure that I use in production React applications.


What Is Feature-Based Architecture?

Feature-Based Architecture is an organizational approach where everything related to a specific feature lives inside its own directory.

Instead of placing all components in components/ and all hooks in hooks/, we group them based on the domain they belong to — for example:

  • Auth/
  • Menu/
  • Branch/
  • Setting/

Each feature becomes a self-contained module including:

  • UI components
  • API calls
  • hooks
  • validation schemas
  • state stores
  • routing
  • pages
  • types

This separation makes large applications predictable and easy to navigate.


🧩 Traditional Structure (By File Type)

src/
├── components/
│   ├── PostItem.tsx
│   ├── PostList.tsx
├── pages/
│   └── PostsPage.tsx
├── hooks/
│   └── usePost.ts
├── types/
│   └── post.types.ts

❌ Logic becomes scattered across multiple global folders
❌ Hard to maintain and refactor
❌ Not scalable for real-world applications


✅ Feature-Based Structure Example

Below is a real, production-ready folder structure — the exact one used in my project.

It combines Core-Oriented Architecture with a clean Feature-Based approach, making it suitable for medium to large teams and enterprise-level frontends.

src/
├── core/
│   ├── assets/         # Global images, icons, fonts, and styles
│   ├── components/     # Reusable shared UI components
│   ├── configs/        # Application-wide configuration (env, axios, constants)
│   ├── constant/       # Global constants
│   ├── guard/          # Route guards (AuthGuard, RoleGuard)
│   ├── hooks/          # Global reusable hooks
│   ├── layouts/        # Global layout components (MainLayout, AuthLayout)
│   ├── plugins/        # Libraries requiring initialization (i18n, toast, dayjs)
│   ├── routes/         # Global application routing definitions
│   ├── stores/         # Global state management (Zustand, Redux)
│   ├── types/          # Shared TypeScript types
│   └── utils/          # General-purpose utility functions
│
├── features/
│   ├── Auth/
│   │   ├── api/          # Auth API requests
│   │   ├── components/   # Auth-specific UI
│   │   ├── hooks/        # Auth-specific hooks
│   │   ├── pages/        # Auth pages (Login, Register)
│   │   ├── routes/       # Feature-level routes
│   │   ├── stores/       # Auth state (tokens, user)
│   │   ├── types/        # Auth-related TS types
│   │   └── validation/   # Form validation schemas
│   │
│   ├── Branch/           # Branch management feature
│   ├── Menu/             # Menu management feature
│   └── Setting/          # Setting & configuration feature
│
├── App.tsx
├── main.tsx
└── vite-env.d.ts

📌 Layer Breakdown

1. core/ — Global App Logic

Everything here is app-wide and not tied to a specific feature.

Includes:

  • global assets
  • axios/http clients
  • providers (auth, theme, query client)
  • layouts
  • shared hooks
  • route guards
  • global config
  • utils & helpers
  • shared state management

If something is used across multiple features, it belongs in core/.


2. shared components inside core/components/

These are UI blocks reusable anywhere in the app:

  • Button
  • Modal
  • Input
  • Table
  • Pagination

They are not tied to business domains — purely UI utilities.


3. features/ — The Heart of the Architecture

Each folder inside features/ represents a complete domain module.

A feature contains everything it needs:

  • components → UI for this feature only
  • hooks → business logic
  • api → fetch logic
  • pages → actual views
  • stores → local state management
  • types → TypeScript domain models
  • validation → form schemas
  • routes → routes belonging to this feature

This makes features fully isolated and easy to extend, replace, or delete.


4. Routing Structure

Your routing is a hybrid:

  • core/routes → app-level routing
  • features/*/routes.ts → feature-level routes

This makes code splitting and lazy loading much easier.


Why This Structure Works

✔ Scalable

Handles large apps with many pages and modules.

✔ Feature isolation

Changing one feature rarely affects others.

✔ Easier onboarding

New developers can understand the architecture quickly.

✔ Predictable

Every feature has the same skeleton.

✔ Enterprise-friendly

Supports advanced patterns like module federation, microfrontends, and domain-driven design.


GitHub Example

This repository demonstrates the same architecture in a clean boilerplate:

👉 https://github.com/naserrasoulii/feature-based-react

Feel free to clone, fork, or contribute.


Conclusion

Feature-Based Architecture is one of the most scalable and maintainable ways to structure large React applications. By grouping code by feature instead of file type — and by supporting it with a clean core layer — you get:

  • modularity
  • maintainability
  • flexibility
  • developer-friendly structure