A React project is more than a collection of JavaScript files. A modern project normally contains source code, dependencies, build configuration, static assets, and an entry point that connects the React application to the browser.
1 Creating a React Application with Vite
Vite is a modern frontend build tool commonly used to create and run React applications during development. It provides a development server, fast module updates, and a production build process.
npm create vite@latest my-react-app
cd my-react-app
npm install
npm run dev
During project creation, React can be selected as the framework and JavaScript or TypeScript can be selected as the language.
2 Typical Project Structure
my-react-app
public
src
assets
App.jsx
main.jsx
index.html
package.json
package-lock.json
vite.config.js
The exact files can vary depending on the Vite template and whether JavaScript or TypeScript is selected, but the overall responsibilities remain similar.
3 public Folder
The public folder contains static files that can be served directly. These files are normally referenced by a URL rather than imported through JavaScript.
For example, a static image placed in the public folder can be referenced using a path such as:
<img src="/logo.png" alt="Logo" />
Files that need to participate in the module build process are often better placed under src and imported into the application.
4 src Folder
The src folder contains the application source code. This is where components, pages, hooks, services, styles, state management code, and other application modules are normally organized.
A small project may have only a few files. A larger project should normally organize code around clear responsibilities rather than putting everything into one file.
5 main.jsx — Application Entry Point
The entry point is responsible for starting the React application and connecting the React component tree to a DOM element in the HTML document.
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
);
The important sequence is that the browser loads the HTML document, the JavaScript entry point executes, React finds the root DOM element, and React renders the application component tree into that element.
6 index.html
In a Vite React application, index.html is the HTML entry document. It normally contains a root element such as:
<div id="root"></div>
React does not replace the complete HTML document. Instead, the React application is mounted into the root element.
7 App.jsx
App.jsx commonly represents the top-level application component. It can contain the main layout and compose other components.
function App() {
return (
<main>
<h1>My Application</h1>
</main>
);
}
export default App;
As the application grows, App should not become a container for every piece of business logic. It should primarily compose the major parts of the application.
8 package.json
package.json describes the project and its npm dependencies. It can contain scripts, package versions, project metadata, and other configuration.
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
}
The scripts allow common project commands to be standardized for the development team.
9 package-lock.json
The lock file records the resolved dependency tree and versions. This helps different environments install consistent dependency versions.
10 vite.config.js
The Vite configuration file is used when project-specific Vite configuration is required. Examples include plugins, aliases, development server settings, or other build configuration.
11 React Startup Flow
flowchart TD
A[Browser Requests Application] --> B[index.html]
B --> C[Root Element]
B --> D[JavaScript Entry]
D --> E[main.jsx]
E --> F[React Root]
F --> G[App Component]
G --> H[Child Components]
H --> I[Rendered UI]
12 Recommended Source Organization
There is no single mandatory folder structure for every React project. The organization should make ownership and responsibilities clear.
src
components
pages
hooks
services
context
utils
assets
App.jsx
main.jsx
- components: Reusable UI components.
- pages: Screen-level components.
- hooks: Reusable React hook logic.
- services: API and external-service communication.
- context: Shared context providers when required.
- utils: General-purpose helper functions.
- assets: Application assets imported through the source tree.
13 Development vs Production Build
During development, Vite provides a development server and fast feedback when files change. A production build generates optimized assets intended to be deployed to a web server or static hosting platform.
npm run build
The generated output is normally placed in a build directory such as dist, depending on the configuration.
14 Important Concepts
| File or Folder | Purpose |
|---|---|
| index.html | HTML entry document containing the root element. |
| main.jsx | Starts React and mounts the root component. |
| App.jsx | Common top-level application component. |
| src | Application source code. |
| public | Static files served directly. |
| package.json | Project metadata, scripts, and dependencies. |
| package-lock.json | Resolved npm dependency information. |
| vite.config.js | Optional Vite-specific configuration. |
15 Common Mistakes
- Thinking
App.jsxis the actual browser entry point. - Confusing
index.htmlwith the React component tree. - Putting all application logic into
App.jsx. - Editing generated production files instead of source files.
- Committing unnecessary generated directories to source control.
- Using the public folder for every asset without considering whether the asset belongs in the module source tree.
16 Interview Questions
- What is Vite?
- What is the purpose of
main.jsx? - What is the purpose of the root element in
index.html? - What is the difference between
publicandsrc? - What information is stored in
package.json? - What is the purpose of
package-lock.json? - What happens when
npm run devis executed? - What happens during
npm run build? - Where should reusable components be placed?
- How does the browser reach the React component tree?
17 Key Takeaways
- Vite provides the development and build tooling for a modern React project.
index.htmlprovides the browser document and root element.main.jsxstarts React and mounts the application.App.jsxcommonly acts as the top-level component.package.jsonmanages project scripts and dependencies.- A clear source structure becomes increasingly important as an application grows.
Conclusion
Understanding the project structure makes it easier to debug startup issues, organize features, add dependencies, and explain the React application lifecycle during interviews. The most important flow to remember is: browser loads the HTML, the JavaScript entry point starts React, React mounts the root component, and the component tree produces the UI.