04_Folder Structure - Maniconserve/React-Wiki GitHub Wiki

React Project Structure — Developer Wiki

A guide to understanding the folder and file structure of a standard React application (created with create-react-app).


📁 Project Root Overview

my-react-app/
├── node_modules/
├── public/
│   ├── index.html
│   ├── manifest.json
│   └── robots.txt
├── src/
│   ├── index.js
│   ├── index.css
│   ├── App.js
│   ├── App.css
│   └── reportWebVitals.js
├── package.json
└── package-lock.json

📦 node_modules/

Contains all the third-party libraries and dependencies your project needs to run — things like react, react-dom, babel, and more.

Important: You should never commit node_modules/ to Git. It is listed in .gitignore by default because it can contain thousands of files and is very large.

Anyone cloning your project can recreate it by running:

npm install

This reads package.json and installs everything automatically.


🌐 public/

This folder holds static assets — files that do not need any processing or transformation before being served to the browser.

index.html

The single HTML page that serves as the entry point for your React app. React mounts the entire application inside the <div id="root"> element here.

manifest.json

A configuration file for Progressive Web App (PWA) settings. You can define:

  • App name and short name
  • Theme and background colors
  • Icons for home screen installation

Example:

{
  "short_name": "MyApp",
  "name": "My React Application",
  "theme_color": "#000000",
  "background_color": "#ffffff"
}

robots.txt

Tells search engine crawlers (like Googlebot) which pages or files they are allowed or not allowed to index.

User-agent: *
Disallow: /admin        # Search engines will NOT index /admin
Allow: /                # Search engines CAN index everything else

⚙️ src/ (Source)

This is where all your application code lives. Files here are written in JSX (HTML-like syntax inside JavaScript), which needs to be processed and compiled by Babel before the browser can understand it.

index.js

The JavaScript entry point of your app. It connects the React component tree to the index.html file by rendering the root <App /> component into the DOM.

index.css

Global styles that apply across your entire application.

App.js / Component files

Each React component typically has two files:

  • A .js file — contains the component logic and JSX structure (HTML + JavaScript)
  • A .css file — contains styles specific to that component

Think of each component as a self-contained unit of UI with its own HTML, CSS, and JavaScript.

reportWebVitals.js

Used to measure and report performance metrics of your web app (e.g., page load time, interactivity, layout stability). You can log results to the console or send them to an analytics service.


📋 package.json

The central configuration file for your project. It describes:

1. Dependencies

Lists all the libraries your project needs. When someone clones your repo and runs npm install, npm reads this file to install the correct packages.

{
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}

2. Scripts

Defines shortcut commands you can run with npm run <script-name>.

{
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "runmyjs": "node ./index.js"
  }
}

Running npm run runmyjs will look up "runmyjs" in the scripts section and execute node ./index.js.


🔒 package-lock.json

Records the exact version of every package (and its sub-dependencies) that was installed. This ensures every developer on the team gets the same dependency tree.


🔢 Version Syntax in package.json

npm uses semantic versioning: MAJOR.MINOR.PATCH (e.g., 18.2.3)

Symbol Example Meaning
^ (caret) ^18.2.0 Install latest version where minor ≥ 2 (e.g., 18.3.0 is OK, but 19.0.0 is not)
~ (tilde) ~18.2.3 Install latest version where patch ≥ 3 (e.g., 18.2.5 is OK, but 18.3.0 is not)
No symbol 18.2.0 Install exactly this version

When package-lock.json is present, npm install will always install the exact versions recorded in it, regardless of what ranges are specified in package.json. This guarantees consistency across all environments.


🔄 Summary Diagram

Browser
  └── public/index.html         ← Static entry point
        └── src/index.js        ← React entry point (processed by Babel)
              └── App.js        ← Root component
                    └── Other Components...

npm install └── reads package.json / package-lock.json └── downloads to node_modules/


Last updated for React 18 / Create React App

⚠️ **GitHub.com Fallback** ⚠️