React Project Directory Structure and Entry Points
React Project Directory Structure and Entry Points
1. Anatomy of a Production React Project
When you scaffold a modern React application using Vite, a clean and standardized folder structure is created. Understanding the exact role of each file and folder ensures smooth collaboration and clean architectural scalability.
2. The HTML Host: index.html
Unlike older bundlers where index.html resided in a hidden public folder, Vite treats index.html as the project's direct entry point at the root level.
The <div id="root"></div> serves as the container where React mounts its component tree. Notice the direct <script type="module" src="/src/main.jsx"></script> tag, which gives Vite immediate visibility into the JavaScript entry point.
3. The React Entry Point: src/main.jsx
In main.jsx, React establishes its bridge to the browser's Document Object Model using react-dom/client:
Key Elements of main.jsx:
createRoot(React 18+): Creates a modern concurrent root container. This unlocks automatic batching of state updates and concurrent rendering capabilities.<React.StrictMode>: A development-only wrapper that helps surface potential side-effect bugs, deprecated APIs, and uncleaned timers by intentionally invoking component render functions twice in local development. It is completely inactive in production builds.
4. The Root Component: src/App.jsx
App.jsx is the topmost React component in your application hierarchy. It imports child components, coordinates global layouts, and returns JSX markup:
5. public/ vs src/assets/
Front-end engineers often confuse static asset locations:
public/: Files placed here (e.g.,robots.txt,favicon.ico) are served directly at the root path (/favicon.ico). They are not processed or hashed by Vite's build pipeline.src/assets/: Images, fonts, and stylesheets placed here are imported directly into JavaScript files (import logo from './assets/logo.png'). Vite hashes their filenames for long-term browser cache invalidation (logo.8f3a12.png) and inlines small images as base64 data URIs.
Practice Quiz
index.html file located?ReactDOM.createRoot in React 18+?<React.StrictMode> do during development?src/assets/ rather than referenced from public/?id used by conventional React starters to mount the root application component?Virtual DOM and React Render Cycle Explained
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Setting Up Modern React with Vite | Virtual DOM and React Render Cycle Explained |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.