Skip to content

mohsen104/boilerplate-react

React Boilerplate πŸš€

poster

A modern, scalable, and production-ready React boilerplate with built-in authentication, state management, and developer tools.

πŸ“ Project Structure

src/
β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”œβ”€β”€ icons/          # Icon components
β”‚   β”œβ”€β”€ layouts/        # Layout components (AuthLayout, RootLayout)
β”‚   β”œβ”€β”€ shared/         # Shared components across features
β”‚   └── ui/             # Base UI components (Button, Input, Modal, etc.)
β”œβ”€β”€ features/           # Feature-based modules
β”‚   β”œβ”€β”€ auth/           # Authentication feature
β”‚   β”‚   β”œβ”€β”€ components/ # Auth-specific components
β”‚   β”‚   β”œβ”€β”€ hooks/      # Auth custom hooks
β”‚   β”‚   β”œβ”€β”€ services/   # Auth API services
β”‚   β”‚   β”œβ”€β”€ slices/     # Auth state slices
β”‚   β”‚   └── types/      # Auth type definitions
β”‚   β”œβ”€β”€ home/           # Home feature module
β”‚   └── products/       # Products feature module
β”œβ”€β”€ pages/              # Page components
β”‚   β”œβ”€β”€ HomePage.tsx
β”‚   β”œβ”€β”€ LoginPage.tsx
β”‚   └── ProductListPage.tsx
β”œβ”€β”€ hooks/              # Global custom hooks
β”œβ”€β”€ context/            # React Context providers
β”œβ”€β”€ providers/          # App providers (AppProviders, QueryProvider, etc.)
β”œβ”€β”€ routes/             # Routing configuration
β”œβ”€β”€ services/           # API services
β”œβ”€β”€ store/              # Redux store configuration
β”œβ”€β”€ types/              # Global TypeScript type definitions
β”œβ”€β”€ utils/              # Utility functions
β”œβ”€β”€ lib/                # Third-party library configurations
β”œβ”€β”€ styles/             # Global styles and themes
β”œβ”€β”€ config/             # App configuration files
β”œβ”€β”€ mocks/              # Mock data and API handlers
└── assets/             # Static assets (images, fonts, etc.)

πŸ›  Tech Stack

Core Technologies

  • Frontend Framework: React 19 with TypeScript
  • Build Tool: Vite with SWC
  • Styling: Tailwind CSS 4
  • Routing: React Router
  • Package Manager: Bun

State Management & Data Fetching

  • Client State: Redux Toolkit (feature-based slices)
  • Server State: React Query (TanStack Query)
  • Context API: For auth and theme management

Development & Quality

  • Language: TypeScript (strict mode)
  • Linting: ESLint + Biome (formatting & linting)
  • Git Hooks: Husky + lint-staged
  • Mocking: MSW (Mock Service Worker)

Deployment & Containerization

  • Containerization: Docker & Docker Compose
  • Environment Management: Dotenv

✨ Features

πŸ” Authentication System

  • JWT-based authentication
  • Protected routes with ProtectedRoute component
  • Role-based access control with AccessControl
  • Auth context with useAuth hook
  • Automatic token refresh
  • Login/Logout functionality

πŸ— Project Architecture

  • Feature-based folder structure
  • Modular and scalable design
  • Separation of concerns
  • Reusable component library
  • Custom hooks for business logic

🎨 Developer Experience

  • Hot module replacement (HMR) with Vite
  • TypeScript for type safety
  • Path aliases configured
  • Pre-commit hooks with Husky
  • Consistent code formatting with Biome
  • Mock API with MSW

πŸ“¦ Production Ready

  • Docker containerization
  • Environment variables management
  • Optimized build output
  • SEO-friendly (robots.txt)
  • Asset optimization

πŸ”§ Development Tools

  • Biome for blazing-fast formatting and linting
  • SWC for fast compilation
  • Bun for fast package management
  • TypeScript strict configuration
  • Pre-configured path aliases

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ (version specified in .nvmrc)
  • Bun package manager
  • Docker (optional)

Installation

  1. Clone the repository

    git clone https://github.com/mohsen104/boilerplate-react
    cd react-ts-boilerplate
  2. Install dependencies

    bun install
  3. Set up environment variables

    cp .env.example .env
  4. Start development server

    bun run dev

Docker Development

# Start with Docker Compose
docker-compose up -d

# Stop containers
docker-compose down

# View logs
docker-compose logs -f

πŸ“œ Available Scripts

  • bun run dev - Start development server with HMR
  • bun run preview - Preview production build locally
  • bun run build - Build for production (includes TypeScript compilation)
  • bun run lint - Run Biome linting and auto-fix issues
  • bun run format - Format code with Biome
  • bun run check - Comprehensive Biome check (lint + format)
  • bun run msw:init - Initialize MSW service worker

🏷 TypeScript Configuration

  • Strict type checking enabled
  • Path aliases for clean imports
  • Environment variables typing
  • API response types with generics
  • Custom hooks with proper return types

🎯 Core Concepts

Feature-Based Architecture

Each feature is self-contained with:

  • Components (UI components)
  • Hooks (custom React hooks)
  • Services (API calls and business logic)
  • Slices (Redux state management)
  • Types (TypeScript definitions)

Routing & Navigation

  • Protected routes with authentication
  • Layout-based routing system
  • Lazy loading with React.Suspense
  • Route-based code splitting

πŸ”§ Configuration Details

Vite Configuration

  • TypeScript support with SWC
  • Path aliases mapping
  • Environment variables exposure
  • Asset optimization

🀝 Contributing Guidelines

  1. Follow the feature-based architecture
  2. Use TypeScript for all new code
  3. Follow Biome formatting rules
  4. Write meaningful commit messages
  5. Add proper TypeScript types
  6. Update documentation when needed
  7. Use meaningful component and file names

Built with ❀️ using modern web technologies