DEV Community

Cover image for How to Organize Your React Project Like a Pro
Ender
Ender

Posted on

How to Organize Your React Project Like a Pro

So, you’ve started developing your React app, and everything is going smoothly until you notice that your project folder is getting chaotic. Sound familiar? Don’t stress—we’ve all been there. Organizing a React app can seem daunting, but with the right structure, you can maintain a clean, scalable, and easily navigable codebase.

In this guide, I’ll walk you through a folder structure that has worked exceptionally well for me. It’s beginner-friendly, scalable, and ideal for small to medium-sized projects. Let’s get started!

1. assets/ 🖼️

This directory is for all static assets like images, icons, fonts, and other media. Keeping them in one place simplifies management and access throughout your app.

What to store here:

  • Images (logo.png, background.jpg)
  • Icons (SVGs or icon fonts)
  • Fonts (custom or third-party)

Image description

2. components/ 🧩

This is where all reusable UI components reside. Buttons, cards, modals, and any other elements used across your app should be stored here.

What to store here:

  • Reusable components (Button.jsx, Card.jsx)
  • Component-specific styles (if not using CSS-in-JS)
  • Subfolders for complex components (e.g., components/Header/)

Image description

3. contexts/ 🌐

React Context is great for managing global state without prop drilling. This directory stores all context providers and related logic.

What to store here:

  • Context providers (AuthContext.js, ThemeContext.js)
  • Reducers or custom hooks for managing context

Image description

4. Use Jinno to Create Stories for Your Components 🚀

Jinno is a VS Code extension that allows you to create component stories directly inside your editor. Unlike Storybook, where you need to modify your component or set up an external environment, Jinno integrates seamlessly with your code. This means you can define different examples for your components without modifying their implementation.

With Jinno, you can define a .story.tsx file next to each component, allowing you to quickly preview different prop variations.

Example: Create a [YOUR_COMPONENT_NAME].story.tsx file next to your React component. For example, if your file is UsersList.tsx, create UsersList.story.tsx in the same directory and define different prop examples.

// UsersList.story.tsx
import { User } from './types';
import { UserIcon } from './UserIcon';

export default {
  examples: {
    default: {
      users: [
        {
          id: '1',
          username: 'snow123',
          name: 'John Snow',
          age: 25,
          avatar: UserIcon,
        } as User,
      ],
    },
  },
};
Enter fullscreen mode Exit fullscreen mode

Why jinno is importent to structure your project:

  • Define component stories without modifying the component code
  • Live preview of different prop configurations inside VS Code
  • **Jinno will isolate the component for you, no need to change your code
  • No need to set up an external tool like Storybook or change your code to isolate the components

I’ve been using Jinno in my projects, and it has dramatically improved my development workflow. If you want to streamline your component testing process, try Jinno here.

5. pages/ 📄

This folder stores the main components that define each page of your application. Every file here corresponds to a specific route in your app.

What to store here:

  • Page components (Home.jsx, About.jsx, Contact.jsx)
  • Page-specific logic and styles

Image description

6. services/ 🌍

This folder is dedicated to managing API requests and external integrations. By keeping these files separate, it makes the code easier to manage and mock during testing.

What to store here:

  • API service files (authService.js, userService.js)
  • API configuration files (e.g., apiConfig.js)

Image description

7. styles/ 🎨

This folder is where global styles, themes, and CSS utilities are managed. If you’re using a CSS-in-JS solution, you might not need this folder, but it remains useful for defining overarching styles.

What to store here:

  • Global styles (global.css)
  • Theme configurations (theme.js for styled-components or Material-UI)
  • Reusable CSS utility classes

Image description

8. App.js 🎯

The App.js file serves as the entry point of your React application. This is where you define your app’s structure, routes, and global configurations.

What to include here:

  • Routing setup (react-router-dom)
  • Context providers (AuthProvider, ThemeProvider)
  • Global error boundaries and wrappers

With this structured setup, your React app will remain clean, maintainable, and scalable as it grows!

🚀 Final Thoughts

Building a React app can be overwhelming, but with a well-structured folder setup, you’ll have a strong foundation for scalability and maintainability. By organizing your files efficiently, you make it easier to collaborate with others, debug issues, and extend your application in the future. Plus, tools like Jinno can further enhance your development experience by making component previews and testing seamless. Now, you’re ready to build with confidence—go create something amazing! 🚀

Top comments (0)