React
I. React Fundamentals
1. Introduction to React
2. React vs JavaScript
3. Setting Up React Environment
4. JSX Basics
5. Components Overview
6. Functional Components
7. Props
8. State Basics
II. Core React Concepts
9. Event Handling
10. Conditional Rendering
11. Lists and Keys
12. Forms in React
13. Controlled Components
14. useEffect Hook
15. useState Hook
16. Custom Hooks
III. Adv. React & Ecosystem
17. Context API
18. React Router
19. API Calls with Fetch
20. API Calls with Axios
21. Lifting State Up
22. Performance Optimization
23. Code Splitting
24. Error Boundaries
IV. Projects & Practices
25. React Best Practices
26. Folder Structure
27. Testing React Components
28. Security in React
29. React Interview Questions
30. Mini Project – Todo App
31. Mini Project – Dashboard
32. Mini Project – Ecommerce UI
33. Mini Project – API Integration
34. React Case Study
35. React Real-World Use Cases
36. React Project Planning
37. React Final Project
38. React Deployment
39. React Course Review
40. React Wrap-Up
41. Advanced React Patterns
42. React with TypeScript
43. React Accessibility
44. React Performance Audit
45. React Career Roadmap
LESSON 26
Folder Structure
Build a scalable project organization system that grows with your DataFlow dashboard and prevents chaos as features multiply.
A messy React project looks like a teenager's bedroom. Files scattered everywhere. Components lost in random folders. Nobody knows where anything lives. Professional React apps need structure. Think of your folder organization like a library system. Every book has a home. Every component knows its place. The DataFlow team just hit 50 components across their dashboard. Time to organize before the codebase becomes unmaintainable.The Anatomy of React Folders
React doesn't enforce folder structure. That's both freedom and danger. Too much choice paralyzes teams. Most React projects start flat. Everything dumped into onesrc folder:
src/
App.js
Header.js
Sidebar.js
Dashboard.js
Chart.js
Table.js
Button.js
Modal.js
utils.js
api.jsFeature-First Structure
The most scalable approach groups files by feature, not type. Instead of putting all components in one folder, group related pieces together. Here's how DataFlow organizes their dashboard:src/
components/
common/
Button/
Button.js
Button.css
Modal/
Modal.js
Modal.css
features/
dashboard/
StatsCard.js
ChartSection.js
DataTable.js
auth/
LoginForm.js
SignupForm.js
hooks/
useAuth.js
useApi.js
utils/
formatters.js
constants.js
App.js
index.jsComponent Organization Patterns
Every component needs friends. The JavaScript file rarely stands alone. Styles, tests, and story files cluster around it. The component folder pattern keeps families together:StatsCard/
StatsCard.js // Main component
StatsCard.css // Styles
StatsCard.test.js // Tests
StatsCard.stories.js // Storybook stories
index.js // Export barrelindex.js file acts like a receptionist. It exports the main component, so imports look clean:
// Clean import
import StatsCard from './components/StatsCard';
// Instead of
import StatsCard from './components/StatsCard/StatsCard.js';Naming Convention
Use PascalCase for component folders and files. React components must start with capital letters. Keep the convention consistent across your entire project structure.
Shared Resources Strategy
Some code belongs everywhere and nowhere. Utility functions, constants, API helpers. These shared resources need their own neighborhoods. Theutils folder becomes your toolbox:
utils/
formatters.js // Date, currency, number formatting
validators.js // Form validation functions
constants.js // App-wide constants
api.js // HTTP request helpers
storage.js // localStorage abstractionshooks/
useAuth.js // Authentication state
useApi.js // API call logic
useLocalStorage.js // Browser storage
useDebounce.js // Performance optimizationassets/
images/
logo.svg
hero-banner.jpg
icons/
chevron-down.svg
user-circle.svgScale Considerations
Small projects can get away with simple structures. Large applications need more sophistication. The DataFlow dashboard started with 5 components. Now they have 200+. Here's how their structure evolved:SMALL PROJECT (5-20 components)
Flat structure works fine. Group by type: components, utils, hooks. Simple and discoverable.
MEDIUM PROJECT (20-100 components)
Feature folders emerge. Dashboard, auth, settings get separate homes. Shared components centralized.
LARGE PROJECT (100+ components)
Deep nesting required. Sub-features, component libraries, design system integration. Enterprise complexity.
ENTERPRISE (500+ components)
Multiple apps, shared packages, monorepo tools. Architecture becomes critical for team coordination.
Real-World Structure Example
Here's the actual folder structure DataFlow uses for their production dashboard. 50,000 lines of code organized for maximum developer productivity:src/
components/
ui/ // Design system components
Button/
Input/
Modal/
Card/
layout/ // Layout components
Header/
Sidebar/
Footer/
features/
dashboard/
components/
StatsCard/
ChartSection/
hooks/
useDashboardData.js
services/
dashboardApi.js
analytics/
components/
ReportChart/
FilterPanel/
utils/
chartHelpers.js
auth/
components/
LoginForm/
ProtectedRoute/
hooks/
useAuth.js
shared/
hooks/
useApi.js
useLocalStorage.js
utils/
formatters.js
validators.js
constants/
api.js
routes.js
assets/
images/
icons/
styles/
global.css
variables.css
App.js
index.jsTeam Agreement Required
The best folder structure is the one your team actually follows. Document decisions. Create templates for new features. Consistency matters more than perfection.
Import Organization
File structure only helps if imports stay clean. Messy imports create maintenance nightmares. Follow this import order convention:// External libraries first
import React, { useState, useEffect } from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
// Internal components (relative imports)
import Header from './components/layout/Header';
import Sidebar from './components/layout/Sidebar';
import Dashboard from './features/dashboard/Dashboard';
// Utilities and constants last
import { formatCurrency } from './utils/formatters';
import { API_BASE_URL } from './constants/api';// Instead of relative path nightmare
import Button from '../../../components/ui/Button';
// Use absolute imports
import Button from 'components/ui/Button';Environment-Specific Files
Different environments need different configurations. Development, staging, and production each have unique requirements. Environment files live at the project root:.env // Shared defaults
.env.local // Local overrides (gitignored)
.env.development // Dev-specific
.env.staging // Staging-specific
.env.production // Production-specificREACT_APP_:
// .env.development
REACT_APP_API_URL=http://localhost:3001
REACT_APP_DEBUG=true
// .env.production
REACT_APP_API_URL=https://api.dataflow.com
REACT_APP_DEBUG=false.env.local for sensitive data.
Security Warning
Environment variables in React become part of the client bundle. Anyone can see them. Never put API keys or secrets in REACT_APP_ variables. Use server-side proxies for sensitive operations.
Migration Strategies
Existing projects rarely start with perfect structure. Gradual refactoring beats big bang rewrites. The DataFlow team migrated their messy codebase over three months:1
Week 1-2: Create New Structure
Build empty folders. Document conventions. Create component templates.
2
Week 3-6: Move Shared Components
Relocate reusable components first. Update imports gradually. Test thoroughly.
3
Week 7-10: Group By Features
Move feature-specific code. Create logical boundaries. Eliminate circular dependencies.
4
Week 11-12: Cleanup and Documentation
Remove old files. Update documentation. Train team on new conventions.
Quiz
1. What is the main principle behind feature-first folder structure in the DataFlow dashboard?
2. What is the purpose of an index.js file in a component folder like StatsCard/?
3. Why should you never put API keys in REACT_APP_ environment variables for the DataFlow dashboard?
Up Next: Testing React Components
Master the art of bulletproof React testing with Jest, React Testing Library, and comprehensive component verification strategies.