← Back to React Course | Chapter 13: Advanced React & Architecture | Lesson 9 of 14

Scalable Folder Architecture बनाना

Folder architecture एक kitchen को organize करने जैसा है — एक drawer में knives, दूसरे में spices — ताकि kitchen कितनी भी बड़ी हो जाए, आप जो चाहिए वह तेज़ी से ढूंढ सकें।

छोटे Apps के लिए Simple Structure

एक छोटे app के लिए, एक flat structure — एक components/ folder, एक hooks/ folder, शायद एक utils/ folder — अक्सर काफी sufficient और navigate करना आसान होता है।

ज़रूरत पड़ने से पहले ज़्यादा elaborate structure जोड़ना real benefit के बिना friction जोड़ सकता है।

Note:
  • Simple शुरू करें।
  • आप हमेशा बाद में एक ज़्यादा elaborate structure में reorganize कर सकते हैं जब app की असली shape clear हो जाए।
Warning: 5 components वाले एक project के लिए folder structure को over-engineer करना codebase को actually से ज़्यादा complicated feel करा सकता है।

उदाहरण: Creating a Flat Folder Structure

bash
$ mkdir -p src/components src/hooks src/utils
$ ls src
components  hooks  utils  App.jsx  main.jsx

⚠️ Run this in your own terminal or Node.js environment.

बड़े Apps के लिए Feature-Based Structure

जैसे एक app बढ़ता है, files को FEATURE के हिसाब से group करना (एक shopping cart के सारे components, hooks, और logic एक features/cart/ folder में साथ) file TYPE के हिसाब से करने के बजाय related code को physically close रखता है, एक साथ किसी feature से relevant सब कुछ ढूंढना आसान बनाते हुए।

Note: यह एक अच्छा signal है कि आप एक flat structure से outgrow हो गए हैं: आपको frequently एक feature पर काम करने के लिए कई distant folders के बीच jump करना पड़ता है।
Warning: दोनों organizing principles को inconsistently mix करना (कुछ features group किए गए, बाकी type के हिसाब से scattered) अक्सर एक approach चुनने और उससे चिपके रहने से ज़्यादा confusing है।

उदाहरण: Creating a Feature-Based Folder Structure

bash
$ mkdir -p src/features/cart/components src/features/cart/hooks
$ ls -R src/features/cart
src/features/cart:
components  hooks  cartSlice.js  CartPage.jsx

src/features/cart/components:
CartItem.jsx  CartSummary.jsx

⚠️ Run this in your own terminal or Node.js environment.

Perfection से ज़्यादा Consistency

कोई single universally correct folder structure नहीं है — अलग teams और frameworks अलग conventions successfully favor करते हैं। जो सबसे ज़्यादा मायने रखता है वह ONE approach चुनना और उसे consistently apply करना है, ताकि team का कोई भी (या future you) predict कर सके कि कोई given file कहां मिलेगी या add करनी है।

Note: अपने project के chosen convention को briefly document करें (even एक छोटा README section) ताकि new contributors को guess न करना पड़े।
Warning: कई competing, inconsistently-applied organizing schemes वाला एक codebase अक्सर एक single, simpler, consistently-followed convention वाले से navigate करना ज़्यादा hard है।
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Purely file TYPE के हिसाब से organize करना (एक giant components folder, एक giant hooks folder) FEATURE के हिसाब से करने के बजाय, related files को दूर-दूर scattered बनाते हुए।
  2. एक tiny app के लिए folder structure over-engineer करना जिसे अभी इसकी ज़रूरत नहीं।
  3. कोई consistent convention न होना बिल्कुल भी, हर contributor को files अलग-अलग organize करने देना।
चैप्टर सारांश
  • छोटे apps simple रह सकते हैं: एक flat components/ folder अक्सर काफी है।
  • बड़े apps अक्सर feature-based folders (features/cart/, features/auth/) से फायदा उठाते हैं जो related components, hooks, और logic को साथ group करते हैं।
  • Consistency किसी एक correct structure से ज़्यादा मायने रखती है — एक convention चुनें और इसे uniformly apply करें।
  • Folder structure को app के साथ evolve करना चाहिए; premature over-organization early on friction जोड़ सकता है।
ब्राउज़र सपोर्ट

कोई React-version restriction नहीं — यह एक project organization convention है, कोई API नहीं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.