provides the mounting point for the React application.
loads the JavaScript entry point.
8. Understanding the public Folder
The public folder stores static assets that should be served directly. In a standard Vite setup, files in this folder are copied to the root of the production output without being processed through the source module graph.
Example Structure
public/
├── favicon.ico
├── robots.txt
└── company-logo.png
When Should You Use public?
- For a favicon.
- For a
robots.txt file.
- For files that need a stable public URL.
- For static files that should be served as-is.
For example, if company-logo.png is stored directly inside public, it can normally be referenced as /company-logo.png.
9. Understanding the assets Folder
The assets folder is commonly located inside src. It stores files such as images, SVGs, and fonts that are imported into components or stylesheets.
Example Structure
src/
└── assets/
├── logo.png
├── banner.jpg
└── icons.svg
Example: Importing an Image
import logo from "./assets/logo.png";
function App() {
return (
<div>
<h1>My Website</h1>
<img src={logo} alt="Company logo" />
</div>
);
}
export default App;
When a source asset is imported, Vite can process it as part of the application's build. The exact output depends on the asset and build configuration.
10. Understanding package.json
The package.json file contains information about the project, dependencies, and scripts used to run development tasks.
Example: package.json
{
"name": "my-react-app",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"vite": "^6.0.0"
}
}
Note: This is an illustrative example, not a guaranteed current configuration. The versions and dependencies in your actual project may be different.
Important Sections
name: Identifies the project package.
version: Specifies the package version.
private: Helps prevent accidental publication to the npm registry when set to true.
scripts: Defines commands such as npm run dev and npm run build.
dependencies: Lists packages needed by the application at runtime.
devDependencies: Lists packages used mainly for development and building.
11. Understanding package-lock.json
The package-lock.json file records the resolved dependency tree for an npm project. It helps ensure that installations use consistent package versions across development environments.
Why Is It Important?
- Records the resolved versions of dependencies.
- Helps team members install a consistent dependency tree.
- Supports repeatable builds and deployments.
- Should normally be committed to Git for an application using npm.
Do not manually edit the lock file unless you understand the effects. Use npm commands to manage dependencies.
12. Understanding node_modules
The node_modules folder contains the packages installed for the project, including React, React DOM, Vite, and their dependencies.
Important Points
- It is generally created when you run
npm install.
- It can contain many files and nested folders.
- It is usually excluded from Git using
.gitignore.
- Other developers can recreate it by installing dependencies from the package files.
13. Understanding vite.config.js
The vite.config.js file is used to configure Vite. A basic React application may work with very little configuration, but plugins and settings can be added when needed.
Example: vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()]
});
Explanation
defineConfig helps define Vite configuration.
@vitejs/plugin-react provides React-related integration for Vite.
plugins lists the plugins used by Vite.
The generated configuration can differ by template and Vite version. You usually do not need to modify this file when first learning React.
14. Organizing Reusable Components
As an application grows, reusable components can be placed inside a dedicated components folder.
Example Structure
src/
├── components/
│ ├── Header.jsx
│ ├── Footer.jsx
│ ├── Navbar.jsx
│ └── Button.jsx
├── App.jsx
└── main.jsx
Example: Header.jsx
function Header() {
return (
<header>
<h1>My React Website</h1>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</header>
);
}
export default Header;
Use Header in App.jsx
import Header from "./components/Header.jsx";
function App() {
return (
<div>
<Header />
<main>
<h2>Welcome to the Home Page</h2>
</main>
</div>
);
}
export default App;
Using components helps keep the application organized and allows common UI elements to be reused across different screens.
15. Organizing Pages
For applications with multiple screens, you can create a pages folder. A page component usually represents a complete screen or a route in the application.
Example Structure
src/
├── pages/
│ ├── Home.jsx
│ ├── About.jsx
│ ├── Contact.jsx
│ └── Products.jsx
├── components/
│ ├── Header.jsx
│ └── Footer.jsx
├── App.jsx
└── main.jsx
For example, Home.jsx can contain the homepage UI, while Products.jsx can display product information. A routing library can connect these pages to different URLs when needed.
The pages folder is a convention, not a built-in React requirement.
16. Organizing Hooks, Services, and Utilities
Larger projects often use additional folders to separate application logic from UI components.
| Folder |
Purpose |
Example Files |
hooks/ |
Contains reusable custom React Hooks. |
useAuth.js, useFetch.js |
services/ |
Contains functions for API calls or external services. |
api.js, userService.js |
utils/ |
Contains general helper functions. |
formatDate.js, formatCurrency.js |
context/ |
Contains shared React context definitions when needed. |
AuthContext.jsx, ThemeContext.jsx |
features/ |
Groups files by application feature. |
auth/, products/, cart/ |
Only create these folders when they provide a clear organizational benefit. Small projects do not need every possible folder.
17. Example of a Well-Organized React Project
The following structure is one possible approach for a medium-sized e-commerce application.
my-shop/
├── public/
│ ├── favicon.ico
│ └── robots.txt
├── src/
│ ├── assets/
│ │ ├── logo.png
│ │ └── product-placeholder.png
│ ├── components/
│ │ ├── Header.jsx
│ │ ├── Footer.jsx
│ │ ├── ProductCard.jsx
│ │ └── Button.jsx
│ ├── pages/
│ │ ├── Home.jsx
│ │ ├── Products.jsx
│ │ ├── Cart.jsx
│ │ └── Contact.jsx
│ ├── hooks/
│ │ └── useCart.js
│ ├── services/
│ │ └── productService.js
│ ├── utils/
│ │ └── formatCurrency.js
│ ├── App.jsx
│ ├── App.css
│ ├── index.css
│ └── main.jsx
├── index.html
├── package.json
├── package-lock.json
├── vite.config.js
└── .gitignore
Benefits of This Structure
- Reusable UI elements are stored in
components.
- Full-screen views are stored in
pages.
- Custom Hooks are stored in
hooks.
- API-related functions are stored in
services.
- General helper functions are stored in
utils.
- Images and other imported assets are stored in
assets.
18. Component-Based Project Structure
React applications are built from components. Each component can represent a small part of the user interface, and multiple components can be combined to create a complete page.
Example Component Hierarchy
App
|
├── Header
│ ├── Logo
│ └── Navbar
|
├── HomePage
│ ├── Banner
│ └── ProductList
│ ├── ProductCard
│ ├── ProductCard
│ └── ProductCard
|
└── Footer
This component hierarchy is a conceptual example. You can adjust the component names and nesting to suit your application.
19. File Naming Conventions in React
Consistent naming conventions make files easier to find and understand.
| File Type |
Recommended Example |
Purpose |
| React component |
ProductCard.jsx |
Uses PascalCase for a component name. |
| Page component |
HomePage.jsx |
Represents a full page or screen. |
| Custom Hook |
useAuth.js |
Starts with use and follows Hook naming conventions. |
| Utility function |
formatDate.js |
Uses camelCase for helper functions. |
| CSS file |
ProductCard.css |
Contains styles for a component. |
| CSS Module |
ProductCard.module.css |
Provides locally scoped CSS class names when supported by the build setup. |
| Service file |
productService.js |
Contains product-related API or service functions. |
These are common conventions rather than strict React rules. The important thing is to choose a consistent approach.
20. How a React Application Starts
Understanding the relationship between the main project files helps explain how React renders the application.
Browser Requests the Application
|
v
index.html
|
v
src/main.jsx
|
v
Creates React Root
|
v
src/App.jsx
|
v
Child Components Render
|
v
UI Appears in the Browser
Explanation:
- The browser loads the HTML entry document.
- The HTML document loads the JavaScript entry point.
main.jsx creates a React root at the selected DOM element.
- The root renders
App.jsx.
- The App component renders its child components.
- React updates the browser DOM as needed to display the UI.
21. Common Mistakes in React Project Structure
| Mistake |
How to Avoid It |
| Putting every component in one large file |
Split components into separate files when doing so improves readability and reuse. |
| Mixing unrelated features together |
Group related files by component type or application feature. |
| Confusing App.jsx and main.jsx |
Remember that App usually describes the main UI, while main initializes React rendering. |
| Putting every image in public |
Use src/assets for assets you want to import and public for files served directly. |
| Incorrect import paths |
Verify the relative path and the file name's capitalization. |
| Creating unnecessary folders |
Start with a simple structure and add folders as the application grows. |
| Committing node_modules to Git |
Keep node_modules in .gitignore and share the package files instead. |
| Using inconsistent file names |
Choose clear naming conventions and apply them consistently. |
| Keeping unused imports after deleting files |
Remove imports that reference files or packages that no longer exist. |
22. Best Practices for React Project Structure
- Keep the initial project structure simple.
- Separate reusable components from full-page components when it improves clarity.
- Keep related code together where practical.
- Use meaningful folder and file names.
- Keep global styles separate from component-specific styles when appropriate.
- Store API functions in a dedicated service layer when the project needs one.
- Use custom Hooks for reusable stateful logic.
- Organize larger applications by feature if that makes related code easier to find.
- Do not create folders simply because another project uses them.
- Keep dependency files such as
package.json and package-lock.json under version control for npm projects.
- Document setup commands and project conventions in
README.md.
23. Practice Exercise: Create a Simple React Website Structure
Create a small React website with a header, home page, and footer. Use separate files for each component.
Step 1: Create the Folders
src/
├── components/
│ ├── Header.jsx
│ └── Footer.jsx
├── pages/
│ └── Home.jsx
├── App.jsx
└── main.jsx
Step 2: Create Header.jsx
function Header() {
return (
<header>
<h1>My React Website</h1>
</header>
);
}
export default Header;
Step 3: Create Footer.jsx
function Footer() {
return (
<footer>
<p>Copyright 2026 My React Website</p>
</footer>
);
}
export default Footer;
Step 4: Create Home.jsx
function Home() {
return (
<main>
<h2>Welcome to the Home Page</h2>
<p>This page is part of my React project.</p>
</main>
);
}
export default Home;
Step 5: Import Components into App.jsx
import Header from "./components/Header.jsx";
import Footer from "./components/Footer.jsx";
import Home from "./pages/Home.jsx";
function App() {
return (
<div>
<Header />
<Home />
<Footer />
</div>
);
}
export default App;
Practice Tasks
- Create the project using Vite.
- Create the
components and pages folders.
- Add the Header, Home, and Footer components.
- Import the components into
App.jsx.
- Add CSS styling to the page.
- Create an About page and include it in your application.
- Run the application and check for import or rendering errors.
24. Frequently Asked Interview Questions
Q1. What is React Project Structure?
It is the organization of files and folders in a React application, including components, styles, assets, configuration files, and dependencies.
Q2. What is the purpose of the src folder?
The src folder contains the main source code of the application, such as components, styles, and application logic.
Q3. What is the difference between App.jsx and main.jsx?
App.jsx usually defines the main UI component, while main.jsx initializes React rendering and mounts the App component into the HTML document.
Q4. What is the purpose of index.html in Vite?
It is the HTML entry document that provides the root element and loads the JavaScript entry point.
Q5. What is the difference between public and assets?
The public folder contains files served directly, while assets inside src can be imported and processed as part of the application's build.
Q6. What is package.json?
It contains project metadata, dependencies, and scripts for commands such as development and production builds.
Q7. What is node_modules?
It is the folder where npm installs the project's dependencies.
Q8. What is the purpose of components?
Components divide the interface into reusable, manageable pieces.
Q9. What is the purpose of the pages folder?
It commonly contains components that represent full screens or application routes. It is a convention, not a React requirement.
Q10. Does React enforce a specific folder structure?
No. React allows developers to choose a structure that fits their application and team.
Q11. Why should node_modules not usually be committed to Git?
It contains installed dependencies that can be recreated from the project's package files, so it is usually excluded from version control.
Q12. What is vite.config.js?
It is an optional configuration file used to customize Vite behavior and configure plugins.
25. Quick Revision Notes
- React Project Structure: Organization of application files and folders.
- src: Main source code folder.
- App.jsx: Usually contains the main App component.
- main.jsx: Initializes React rendering.
- index.html: HTML entry document in a Vite project.
- public: Static files served directly.
- assets: Imported images, fonts, and other assets.
- components: Reusable UI elements.
- pages: Full-page or route-level components, by convention.
- hooks: Custom React Hooks.
- services: API and external service functions.
- utils: General helper functions.
- package.json: Project metadata, dependencies, and scripts.
- node_modules: Installed dependencies.
- vite.config.js: Optional Vite configuration.
26. Conclusion
React Project Structure helps developers organize an application so that components, pages, styles, assets, and application logic are easy to locate and maintain. In a typical Vite React project, index.html loads main.jsx, which renders App.jsx. As the application grows, folders such as components, pages, hooks, services, and utils can be introduced when useful.
The best project structure is one that keeps the code understandable and supports the actual needs of the application. Start simple and introduce additional organization as the project grows.
Learn React JS with JustAcademy
Explore the JustAcademy React JS Training Course to learn React fundamentals, components, project setup, and modern frontend development.
Interested in a course demo? Register for the React JS Course Demo.
Official Learning Resources