Project Structure

Overview

A well‑organized folder layout makes it easier for new developers to understand the codebase and speeds up onboarding. Below is the recommended structure for a modern web application.

Directory Layout

my-app/
β”œβ”€ public/               # Static assets served as‑is
β”‚   β”œβ”€ index.html
β”‚   └─ favicon.ico
β”œβ”€ src/                  # Source code
β”‚   β”œβ”€ assets/           # Images, fonts, etc.
β”‚   β”œβ”€ components/       # Reusable UI components
β”‚   β”œβ”€ pages/            # Route‑level pages
β”‚   β”œβ”€ hooks/            # Custom React hooks
β”‚   β”œβ”€ utils/            # Helper functions
β”‚   β”œβ”€ store/            # State management (e.g., Redux, Zustand)
β”‚   β”œβ”€ App.jsx
β”‚   └─ main.jsx          # Entry point
β”œβ”€ tests/                # Unit & integration tests
β”‚   └─ ... 
β”œβ”€ .env                  # Environment variables
β”œβ”€ .gitignore
β”œβ”€ package.json
β”œβ”€ vite.config.js        # Build tool config (example)
└─ README.md

Key Folders

public

Contains files that are copied directly to the build output without processing. Typical files include index.html, favicons, and robots.txt.

src

The heart of the application. Every component, utility, and business logic lives under src. Keep related files together (e.g., component styles next to the component).

tests

All test files should mirror the structure of src for easy navigation. Use .test.jsx or .spec.js naming conventions.

Example Component File

src/components/Button.jsx

import React from 'react';
import './Button.css';

export default function Button({children, onClick, variant='primary'}) {
  return (
    <button className={`btn ${variant}`} onClick={onClick}>
      {children}
    </button>
  );
}