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>
);
}