When you first create a new React project, you might feel a little overwhelmed by all the files and folders that appear. But don’t worry! We’re going to walk through each part of the project step by step, so you’ll understand what everything does and why it’s there.
Here’s what the typical project structure looks like right after you run the Create React App command:
my-first-react-app/
├── node_modules/
├── public/
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
├── src/
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ └── logo.svg
├── .gitignore
├── package.json
├── package-lock.json
└── README.md
Let’s go through each part of this structure to understand what it all means.
node_modules/
FolderThis is one of the most important folders in your project, but it’s also the one you’ll probably never touch directly. The node_modules/folder contains all the dependencies (or libraries) that your project needs to work.
Think of it like a toolbox. Whenever you use React or another library, the actual code for that tool lives inside node_modules/. You don’t need to worry about modifying any files here—it’s all managed by npm .
It might seem big and full of files, but that’s because there are a lot of tools React relies on to work smoothly. Whenever you install a new package (like React Router, for example), it gets added to this folder.
public/
FolderThe public/
folder contains files that are publicly accessible by the browser. Anything in this folder can be accessed directly from the browser, which makes it important for storing static files that don’t change, like images, icons, and the main index.html file.
public/
: favicon.ico
: This is the small icon that appears next to your website’s name in the browser tab. You can replace it with your own logo or icon if you like.index.html
: This is the main HTML file for your React app. It’s the single HTML file where your entire React app is injected. You don’t need to edit this file often, but it’s important to know that this is where React attaches your app to the DOM. manifest.json
: This file contains metadata about your app, like its name, icons, and theme color. It’s used when your app is installed on mobile devices or used as a Progressive Web App (PWA).src/
FolderThis is where the magic happens! The **src/** folder contains all the source code for your React app. Every time you write new code, you’ll be working inside this folder. Let’s take a closer look at the important files here:
src/
: App.js
: This is the main component of your React app. When you start coding, you’ll write most of your logic inside App.js
. Think of it as the brain of your application, where you control what the app does and how it looks.App.js
is the main component that holds the other components. When you start building your project, you’ll add more components, but this file is where you usually start. App.css
: This file contains the styles (CSS) for the App.js
component. If you want to change how your app looks (colors, fonts, layout), you can edit this file. App.test.js
: This file is used for testing your React components. Don’t worry about this too much for now, especially if you’re a beginner, but know that this file is where you can write tests to make sure your app is working correctly.index.js
: This is a very important file. It’s the entry point of your app. index.js
is responsible for rendering the App.js
component inside the `index.html` file we talked about earlier.index.html
and inserts your React app there. index.css
: This file contains global styles for your entire app. Any styles written here will apply to all components in your app.logo.svg
: This is the React logo that you see when you first run your app. You can replace this with your own logo or image later.package.json
FileThe package.json file is like the "blueprint" for your project. It contains important information like:
Scripts
: These are commands that help you run or build your app. For example, the script `"start"` runs your app in development mode. You’ll usually run this using `npm start`.README.md
FileThe README.md
file contains information about your project. This is where you can write instructions or notes for anyone looking at your project. If you share your project with others (like on GitHub), this file will be the first thing people see when they visit your project page.
.gitignore
FileThe .gitignore
file tells Git which files or folders to ignore when you push your project to a repository (like GitHub). This is useful for avoiding unnecessary files (like node_modules/ ) from being uploaded to your repository.
Now that you understand what each file and folder does, let’s quickly summarize how they all work together:
index.html
: The single HTML file where your React app is rendered.index.js
: The JavaScript file that "mounts" your React app to the DOM (inside the `root` div in index.html ). App.js
: The main component of your React app, where most of your code will go.node_modules/
: Contains all the libraries and tools your project depends on.public/
: Contains files that are publicly accessible, likeindex.html
and icons.With this structure in mind, you now have a clear idea of where to write your code, where your styles go, and how everything connects.
Now that you understand the project structure, you’re ready to start writing code! In the next section, we’ll dive deeper into creating and organizing components, styling them, and building interactive features for your React app.