Skip to content

dscdut/react-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

tailwindcss

React Boilerplate πŸš€

typescript react tailwindcss shadcn-ui vite eslint prettier husky

πŸ“ Overview

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.

✨ Features

πŸ›  Core Technologies

  • ⚑️ 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

πŸ›‘ Development Tools

  • πŸ“¦ ESLint - Code linting
  • πŸ’… Prettier - Code formatting
  • 🦊 Husky - Git hooks
  • πŸ§ͺ Jest - Unit testing
  • πŸ“ Commitlint - Lint commit messages

🎯 Main Features

1. Authentication System

  • JWT-based authentication
  • Protected routes
  • Role-based access control
  • Persistent login state
  • Automatic token refresh

2. State Management

  • Zustand for local state
  • Type-safe state management
  • DevTools integration
  • Middleware support

3. Internationalization (i18n)

  • Multi-language support
  • Dynamic language switching
  • RTL support
  • Translation management
  • Lazy loading of translations

4. Theme System

  • Dark/Light mode
  • System theme detection
  • Custom theme support
  • Persistent theme preference
  • Smooth theme transitions

5. API Integration

  • Axios instance with interceptors
  • Request/Response caching
  • Error handling
  • Loading states
  • Retry mechanism

6. Form Handling

  • React Hook Form integration
  • Form validation with Zod
  • Dynamic form fields
  • Custom form components
  • Error messages

7. Performance Optimization

  • Code splitting
  • Lazy loading
  • Image optimization
  • Bundle analysis
  • Performance monitoring

πŸ§ͺ Unit Testing Setup

1. Configuration Files

// 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"]
}

2. Test Structure

src/
β”œβ”€β”€ __tests__/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── ui/
β”‚   β”‚       └── button.test.tsx
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   └── useAuth.test.ts
β”‚   └── utils/
β”‚       └── formatDate.test.ts

3. Writing Tests

// 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()
  })
})

4. Running Tests

# Run all tests
yarn test

# Run tests in watch mode
yarn test:watch

# Run tests with coverage
yarn test:coverage

5. Testing Best Practices

  • Use @testing-library/react for 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

πŸš€ Getting Started

Prerequisites

  • Node.js 16+
  • Yarn package manager

Installation

  1. Clone the repository:
git clone https://github.com/your-username/react-boilerplate-the-best-2025.git
cd react-boilerplate-the-best-2025
  1. Install dependencies:
yarn install
  1. Set up environment variables:
cp .env.example .env
  1. Start development server:
yarn dev

Visit http://localhost:4000 to see your application.

πŸ“ Project Structure

β”œβ”€β”€ 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

πŸ“‚ Key Directories Explained

src/app/

  • Contains app-level components and providers
  • Layout components for different page types
  • Global providers (Theme, Query, etc.)

src/components/

  • Reusable UI components
  • Organized by feature/domain
  • UI components from shadcn
  • Custom components for specific features

src/core/

  • Core application functionality
  • API configuration and setup
  • Utility functions and helpers
  • State management setup

src/hooks/

  • Custom React hooks
  • Shared logic between components
  • Feature-specific hooks

src/pages/

  • Page components
  • Organized by route/feature
  • Each page has its own directory for related components

src/services/

  • API service functions
  • Organized by domain/feature
  • Handles API calls and data transformation

src/styles/

  • Global styles
  • Tailwind configuration
  • Theme customization

__tests__/

  • Test files mirroring src structure
  • Component tests
  • Hook tests
  • Utility function tests

πŸ›  Available Scripts

  • yarn dev

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ by ThanhDev

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published