A modern, production-ready React boilerplate with TypeScript, TailwindCSS, and Shadcn UI. This template provides a solid foundation for building scalable React applications with best practices and modern tooling.
- β‘οΈ React 18 - A JavaScript library for building user interfaces
- π₯ TypeScript - Static type checking
- π¨ TailwindCSS - Utility-first CSS framework
- π― Shadcn UI - Re-usable components built with Radix UI and Tailwind CSS
- β‘οΈ Vite - Next Generation Frontend Tooling
- π¦ Tanstack Query - Tanstack Query auto caching & background refetching
- π¦ ESLint - Code linting
- π Prettier - Code formatting
- π¦ Husky - Git hooks
- π§ͺ Jest - Unit testing
- π Commitlint - Lint commit messages
- JWT-based authentication
- Protected routes
- Role-based access control
- Persistent login state
- Automatic token refresh
- Zustand for local state
- Type-safe state management
- DevTools integration
- Middleware support
- Multi-language support
- Dynamic language switching
- RTL support
- Translation management
- Lazy loading of translations
- Dark/Light mode
- System theme detection
- Custom theme support
- Persistent theme preference
- Smooth theme transitions
- Axios instance with interceptors
- Request/Response caching
- Error handling
- Loading states
- Retry mechanism
- React Hook Form integration
- Form validation with Zod
- Dynamic form fields
- Custom form components
- Error messages
- Code splitting
- Lazy loading
- Image optimization
- Bundle analysis
- Performance monitoring
// jest.config.cjs
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.cjs'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
}
// babel.config.cjs
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]]
}
// tsconfig.jest.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react-jsx",
"esModuleInterop": true
},
"include": ["src", "jest.setup.cjs"]
}src/
βββ __tests__/
β βββ components/
β β βββ ui/
β β βββ button.test.tsx
β βββ hooks/
β β βββ useAuth.test.ts
β βββ utils/
β βββ formatDate.test.ts
// Example component test
import { render, screen } from '@testing-library/react'
import { Button } from '@/components/ui/button'
describe('Button', () => {
it('renders children', () => {
render(<Button>Click me</Button>)
expect(screen.getByText('Click me')).toBeInTheDocument()
})
it('handles click events', () => {
const handleClick = jest.fn()
render(<Button onClick={handleClick}>Click me</Button>)
screen.getByText('Click me').click()
expect(handleClick).toHaveBeenCalled()
})
})# Run all tests
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with coverage
yarn test:coverage- Use
@testing-library/reactfor component testing - Follow the Arrange-Act-Assert pattern
- Mock external dependencies
- Test user interactions
- Test accessibility
- Use meaningful test descriptions
- Keep tests focused and isolated
- Node.js 16+
- Yarn package manager
- Clone the repository:
git clone https://github.com/your-username/react-boilerplate-the-best-2025.git
cd react-boilerplate-the-best-2025- Install dependencies:
yarn install- Set up environment variables:
cp .env.example .env- Start development server:
yarn devVisit http://localhost:4000 to see your application.
βββ public/ # Static files
β βββ favicon.ico # Favicon
β βββ robots.txt # Robots file
β
βββ src/ # Source code
β βββ app/ # App-level components
β β βββ layout/ # Layout components
β β β βββ layout-main.tsx
β β β βββ layout-auth.tsx
β β βββ providers/ # App providers
β β βββ theme-provider.tsx
β β βββ query-provider.tsx
β β
β βββ assets/ # Static assets
β β βββ images/ # Image files
β β βββ icons/ # Icon files
β β βββ fonts/ # Font files
β β
β βββ components/ # Reusable components
β β βββ ui/ # UI components (shadcn)
β β β βββ button.tsx
β β β βββ input.tsx
β β β βββ ...
β β βββ header-nav/ # Header components
β β βββ language/ # Language components
β β βββ logo/ # Logo components
β β
β βββ core/ # Core functionality
β β βββ configs/ # Centralized configuration files
β β β βββ const.tsx # Small constants for UI or logic
β β β βββ consts.ts # Large constants, enums, or value lists
β β β βββ env.ts # Environment variables (API URL, upload limits, etc.)
β β β βββ i18n.ts # Internationalization (i18n) configuration
β β β βββ icon-size.ts # Standard icon sizes for consistent UI
β β βββ lib/ # Utility functions
β β β βββ utils.ts
β β β βββ validations.ts
β β βββ store/ # State management
β β βββ zustand/
β β βββ redux/
β β
β βββ hooks/ # Custom React hooks
β β βββ use-auth.ts
β β βββ use-theme.ts
β β βββ use-router-element.tsx
β β
β βββ locales/ # Internationalization
β β βββ en/
β β β βββ common.json
β β βββ vi/
β β βββ common.json
β β
β βββ models/ # TypeScript interfaces/types
β β βββ user.ts
β β βββ api.ts
β β
β βββ pages/ # Page components
β β βββ 404/
β β βββ auth/
β β β βββ login.tsx
β β β βββ register.tsx
β β βββ dashboard/
β β βββ home/
β β
β βββ services/ # API services
β β βββ auth.service.ts
β β βββ user.service.ts
β β
β βββ styles/ # Global styles
β β βββ globals.css
β β βββ tailwind.css
β β
β βββ App.tsx # Root component
β βββ main.tsx # Entry point
β
βββ __tests__/ # Test files
β βββ components/ # Component tests
β βββ hooks/ # Hook tests
β βββ utils/ # Utility tests
β
βββ .eslintrc.js # ESLint configuration
βββ .prettierrc # Prettier configuration
βββ .env.example # Example environment variables
βββ .gitignore # Git ignore file
βββ babel.config.cjs # Babel configuration
βββ index.html # HTML template
βββ jest.config.cjs # Jest configuration
βββ package.json # Project dependencies
βββ tsconfig.json # TypeScript configuration
βββ vite.config.ts # Vite configuration
- Contains app-level components and providers
- Layout components for different page types
- Global providers (Theme, Query, etc.)
- Reusable UI components
- Organized by feature/domain
- UI components from shadcn
- Custom components for specific features
- Core application functionality
- API configuration and setup
- Utility functions and helpers
- State management setup
- Custom React hooks
- Shared logic between components
- Feature-specific hooks
- Page components
- Organized by route/feature
- Each page has its own directory for related components
- API service functions
- Organized by domain/feature
- Handles API calls and data transformation
- Global styles
- Tailwind configuration
- Theme customization
- Test files mirroring src structure
- Component tests
- Hook tests
- Utility function tests
yarn dev
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ by ThanhDev
