A modern, scalable React boilerplate with TypeScript, Material UI, and a feature-based architecture.
- React 19 - UI library
- TypeScript 5 - Type safety with strict mode
- Parcel 2 - Zero-config bundler
- Material UI 7 - Component library
- vanilla-extract - Zero-runtime CSS-in-TypeScript
- MobX 6 - State management
- React Router 6 - Client-side routing
- Vitest - Unit testing framework
- ESLint 9 + Prettier - Code quality
- Husky - Git hooks
- pnpm - Fast package manager
src/
βββ app/ # Application configuration
β βββ routes/ # Route definitions
β βββ AppRoutes.tsx
βββ features/ # Feature-based modules
β βββ auth/ # Authentication feature
β β βββ components/ # Feature-specific components
β β β βββ ProtectedRoute/
β β βββ hooks/ # Feature-specific hooks
β β β βββ useAuth.ts
β β βββ pages/ # Feature pages
β β β βββ LoginPage/
β β βββ stores/ # Feature state (MobX)
β β βββ auth.store.ts
β βββ home/ # Home feature
β βββ pages/
β βββ HomePage/
βββ shared/ # Shared/common code
β βββ components/ # Reusable components
β βββ ErrorBoundary/
βββ core/ # Core services (API, global stores)
β βββ api/
β βββ stores/
βββ App.tsx # Root component
βββ index.tsx # Entry point
This boilerplate follows a feature-based architecture:
features/- Each feature is a self-contained module with its own components, pages, hooks, stores, and typesshared/- Reusable components and utilities used across multiple featurescore/- Application-wide services like API clients and global stateapp/- Application configuration, routing, and providers
Styles are written using vanilla-extract in separate .styles.css.ts files:
// Component.styles.css.ts
import { style } from '@vanilla-extract/css';
export const container = style({
display: 'flex',
padding: '24px',
});// Component.tsx
import * as styles from './Component.styles.css';
const Component = () => <div className={styles.container}>...</div>;- Node.js 20+
- pnpm 9+
# Clone the repository
git clone https://github.com/your-username/reactjs-boilerplate.git
# Navigate to project directory
cd reactjs-boilerplate
# Install dependencies
pnpm install
# Start development server
pnpm startThe app will open at http://localhost:1234
| Script | Description |
|---|---|
pnpm start |
Start development server |
pnpm build |
Build for production |
pnpm typecheck |
Run TypeScript type checking |
pnpm lint |
Run ESLint |
pnpm format |
Format code with Prettier |
pnpm test |
Run tests in watch mode |
pnpm test:run |
Run tests once |
pnpm test:coverage |
Run tests with coverage |
This boilerplate includes a basic authentication setup:
- Login page with Material UI form
- Protected routes using
ProtectedRoutecomponent - Auth store (MobX) managing authentication state
- Token persistence in localStorage
Note: The current implementation uses a fake token for demonstration. Replace with your actual authentication logic.
The boilerplate includes a production-ready HTTP client built on Axios:
import { httpClient } from '@/core/api';
// GET request
const response = await httpClient.get<User>('/users/me');
// POST request
await httpClient.post('/auth/login', { email, password });
// Other methods: put, patch, deleteFeatures:
- Singleton pattern - Single instance across the app
- Automatic token injection - Reads from localStorage and adds to request headers
- Request/Response interceptors - For logging, error handling, etc.
- Comprehensive error handling - Network errors, HTTP errors, specific status codes
- TypeScript support - Fully typed responses and errors
- Configurable - Base URL, timeout, and custom headers
Error Handling:
All API errors follow the ApiError interface:
interface ApiError {
message: string;
status: number;
code?: string;
details?: unknown;
}Configuration: Configure the base URL and other options when initializing (optional):
const client = HttpClient.getInstance({
baseURL: 'https://api.example.com',
timeout: 30000,
headers: { 'X-Custom-Header': 'value' },
});Material UI theme is configured in src/index.tsx:
const theme = createTheme({
typography: {
fontFamily: 'Poppins, sans-serif',
},
});-
Create a new folder under
src/features/:src/features/my-feature/ βββ components/ βββ hooks/ βββ pages/ βββ stores/ βββ index.ts -
Export public API from
index.ts -
Add routes in
src/app/routes/AppRoutes.tsx
Tests are written using Vitest and React Testing Library:
import { describe, it, expect } from 'vitest';
import { render, screen } from '../../test/test-utils';
import MyComponent from './MyComponent';
describe('MyComponent', () => {
it('renders correctly', () => {
render(<MyComponent />);
expect(screen.getByText('Hello')).toBeInTheDocument();
});
});MIT