React App Folder Structure Explanation
π Root Folder Structure
my-app/
β
βββ node_modules/
βββ public/
βββ src/
β βββ App.css
β βββ App.js
β βββ App.test.js
β βββ index.css
β βββ index.js
β βββ logo.svg
β βββ reportWebVitals.js
β
βββ .gitignore
βββ package.json
βββ package-lock.json
βββ README.md
βββ yarn.lock
1. node_modules/
This folder holds all third-party dependencies (libraries) your project needs. When you run npm install, all required packages get downloaded into this folder.
Do not modify this folder manually. It is managed by npm.
2. public/
Contains static files directly accessible in the browser. These are not processed by Webpack.
- index.html: The single HTML file served to the browser. React will inject your components here.
- favicon.ico: Icon shown in browser tabs.
- manifest.json: Used for Progressive Web Apps (PWA).
- robots.txt: Guides crawlers like Googlebot on what to index.
3. src/ (Source Folder)
The main folder for development where React components, styling, and logic live.
- App.js: Main React component acting as the root component.
- App.css: Styles specific to
App.js.
- index.js: Entry point where React renders your App into the DOM using
ReactDOM.render().
- index.css: Global CSS that affects the whole app.
- logo.svg: A sample SVG (Scalable Vector Graphics) image for demo purposes.
- reportWebVitals.js: For performance measuring using Web Vitals (optional).
- App.test.js: A basic test file using Jest.
4. Configuration & Metadata Files
- package.json: Contains metadata about the app, dependencies, scripts, and configurations.
- package-lock.json: Automatically generated to lock the exact version of packages β ensures consistent installations.
- .gitignore: Lists files/folders (like node_modules) that should be ignored by Git.
- README.md: A markdown file to document your projectβs purpose, instructions, and details.
- yarn.lock: Similar to package-lock.json but used if you prefer Yarn instead of npm.
π‘ Where Should You Place Your Own Files?
- Components: Inside
/src/components/
- Pages: React Router based pages inside
/src/pages/
- Assets: Images, videos, fonts in
/src/assets/
- Hooks: Custom React hooks in
/src/hooks/
- Context: Context API files in
/src/context/
ποΈ Sample Scalable Folder Structure
src/
βββ assets/
β βββ logo.png
βββ components/
β βββ Header.js
β βββ Footer.js
β βββ Navbar.js
βββ pages/
β βββ Home.js
β βββ About.js
βββ hooks/
β βββ useFetch.js
βββ context/
β βββ AuthContext.js
βββ App.js
βββ index.js
βββ index.css
β¨ Important Terms Explained
- Webpack: Bundles your JS, CSS, images into optimized files for production.
- Crawlers: Programs that scan websites to index content for search engines.
- DOM: The browser's way of representing the structure of web pages.
- PWA: Web app that feels like a mobile app with offline support.
- Jest: Testing tool for checking code correctness in React apps.
Tip: Do not touch node_modules/ or public/index.html unnecessarily. Focus only on the src/ folder for development.
Summary
- public/: Contains static files and the main HTML file.
- src/: Contains app logic, components, styles.
- node_modules/: Contains third-party libraries (managed by npm).
- Root Config Files: Manage dependencies, Git, and project metadata.