#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
React Fundamentals

React Source Code Structure

The source code structure of a React project is the set of folders and files a project generator creates for you, and the role each one plays in turning your components into a running app. Knowing what lives where tells you which files to edit, which to leave alone, and how the browser goes from a nearly empty HTML page to your full interface. The layout below is what Vite creates; Create React App is similar with a few differences noted.

A tour of the generated folders

my-app/
├── node_modules/      installed packages (never edit, never commit)
├── public/            files copied as-is, e.g. favicon, robots.txt
├── src/               your application code
│   ├── assets/        images and files imported by components
│   ├── App.css
│   ├── App.jsx        the root component
│   ├── index.css      global styles
│   └── main.jsx       entry point that mounts React
├── index.html         the single HTML page
├── package.json       scripts and dependency list
├── package-lock.json  exact installed versions
└── vite.config.js     build tool settings

Create React App differs slightly: index.html lives inside public/, the entry file is src/index.js, and there is no Vite config file.

How the app starts

The browser first loads index.html. It contains almost nothing: a <div id="root"></div> and a script tag pointing at /src/main.jsx. That entry file finds the empty div and tells React to render your root component into it.

// src/main.jsx
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App.jsx';

createRoot(document.getElementById('root')).render(
  <StrictMode>
    <App />
  </StrictMode>
);

From there, App renders other components, which render others, forming the component tree. You rarely touch main.jsx again except to add app-wide wrappers such as a router or a context provider. Most of your daily work happens in App.jsx and new component files.

public versus src/assets

Both hold static files, but they behave differently. Files in src/assets are imported in code, for example import logo from './assets/logo.svg'. The build tool processes them, adds a content hash to the filename for caching, and fails the build if a file is missing, which catches typos early. Files in public are copied unchanged and referenced by absolute path, like /favicon.svg. Use public for files that need a fixed name or URL, and src/assets for everything your components use.

Growing the structure as the app grows

React does not enforce a layout inside src. A common, simple approach for small to medium apps is:

  • src/components/ for reusable pieces such as buttons, cards and modals.
  • src/pages/ for components tied to a route, such as Home.jsx and Profile.jsx.
  • src/hooks/ for custom hooks.
  • src/services/ or src/api/ for functions that call your backend.

Some teams prefer grouping by feature instead, such as src/features/cart/ holding the cart's components, hooks and API calls together. Either works if the team is consistent.

Files beginners should not change

Never edit anything inside node_modules; your changes vanish on the next install and others will not have them. Do not edit the dist or build output either, since it is regenerated by every build. If the project behaves strangely after editing package.json by hand, delete node_modules and run npm install again. Finally, keep the id="root" div in index.html; if its id does not match the one in main.jsx, React throws an error saying the target container is not a DOM element.

Takeaway

index.html provides the empty root, main.jsx mounts React into it, App.jsx starts your component tree, and everything you write lives under src. With that map in mind, JSX in the next lesson will feel much less mysterious.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course