Skip to content

KhenCahyo13/ReactJS-Boilerplate

Repository files navigation

React Boilerplate

A production-ready React boilerplate with TypeScript, Vite, TanStack Router, TanStack Query, Zustand, and shadcn/ui. Built with modern best practices and scalable architecture patterns.

πŸš€ Features

  • ⚑️ Vite - Lightning-fast development with HMR
  • βš›οΈ React 19 - Latest React with concurrent features
  • 🎯 TypeScript - Full type safety across the stack
  • πŸ—‚ File-based Routing - Type-safe routing with TanStack Router
  • πŸ”„ Data Fetching - TanStack Query for server state management
  • 🎨 shadcn/ui - Beautiful, accessible component library
  • πŸ’… Tailwind CSS - Utility-first styling with v4
  • πŸ“ TanStack Form - Type-safe forms with validation
  • πŸ—ƒ Zustand - Lightweight global state management
  • πŸ“š Storybook - Component development and documentation
  • πŸ§ͺ Vitest - Fast unit testing
  • 🎭 Playwright - End-to-end testing
  • πŸ“ ESLint - Code quality and consistency
  • πŸ’Ž Prettier - Code formatting
  • πŸͺ Husky - Git hooks for quality gates

πŸ“¦ Tech Stack

Category Technology
Core React 19, TypeScript, Vite
Routing TanStack Router (file-based)
Data Fetching TanStack Query + Axios
State Management Zustand
Forms TanStack Form + Zod
UI Components shadcn/ui + Radix UI
Styling Tailwind CSS v4
Icons Tabler Icons + Lucide
Dev Tools Storybook, Vitest, Playwright

πŸ— Project Structure

src/
β”œβ”€β”€ api/              # API client functions
β”œβ”€β”€ components/       # Reusable UI components
β”‚   β”œβ”€β”€ ui/           # shadcn/ui base components
β”‚   β”œβ”€β”€ core/         # App-level providers
β”‚   β”œβ”€β”€ layouts/      # Layout components
β”‚   β”œβ”€β”€ tanstack-form/# Form components
β”‚   β”œβ”€β”€ datatable/    # DataTable components
β”‚   └── fallback/     # Loading/error states
β”œβ”€β”€ features/         # Feature-based modules
β”‚   β”œβ”€β”€ auth/         # Authentication feature
β”‚   β”œβ”€β”€ dashboard/    # Dashboard feature
β”‚   └── posts/        # Posts feature
β”œβ”€β”€ hooks/            # Custom React hooks
β”œβ”€β”€ lib/              # Utility functions
β”œβ”€β”€ routes/           # File-based routing
β”‚   β”œβ”€β”€ __root.tsx    # Root layout
β”‚   β”œβ”€β”€ (authenticated)/  # Protected routes
β”‚   └── (unauthenticated)/ # Public routes
β”œβ”€β”€ stores/           # Zustand stores
β”œβ”€β”€ stories/          # Storybook stories
└── types/            # Global TypeScript types

πŸ“– For detailed folder explanations, see the README.md in each folder.

🎯 Architecture Patterns

Container-Presentational Pattern

Features use separation of concerns:

  • Container (index.tsx): Data fetching, business logic
  • Presentational (view.tsx): UI rendering, props-based

Component Organization

  • Global components β†’ src/components/
  • Feature-specific β†’ src/features/*/components/
  • UI primitives β†’ src/components/ui/

State Management Strategy

  • Server state β†’ TanStack Query
  • Global client state β†’ Zustand
  • Form state β†’ TanStack Form
  • URL state β†’ TanStack Router

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and pnpm

Installation

# Clone the repository
git clone <repository-url>
cd react-boilerplate

# Install dependencies
pnpm install

# Start development server
pnpm dev

Available Scripts

# Development
pnpm dev              # Start dev server (http://localhost:5173)
pnpm storybook        # Start Storybook (http://localhost:6006)

# Build
pnpm build            # Build for production
pnpm build-storybook  # Build Storybook

# Code Quality
pnpm lint             # Run ESLint
pnpm format           # Format with Prettier

# Preview
pnpm preview          # Preview production build

🧩 Key Concepts

Adding a New Feature

  1. Create feature folder:

    src/features/tickets/
    β”œβ”€β”€ list/
    β”‚   β”œβ”€β”€ index.tsx      # Container
    β”‚   β”œβ”€β”€ view.tsx       # Presentational
    β”‚   β”œβ”€β”€ data.tsx       # TanStack Query hooks
    β”‚   β”œβ”€β”€ types.d.ts     # Types
    β”‚   └── components/    # Feature-specific components
    β”œβ”€β”€ create/
    └── details/
    
  2. Add API calls:

    // src/api/tickets.ts
    export const ticketApi = {
      getAll: () => api.get<Ticket[]>('/tickets'),
      create: (data) => api.post('/tickets', data),
    };
  3. Create route:

    // src/routes/(authenticated)/tickets/index.lazy.tsx
    import { createLazyFileRoute } from '@tanstack/react-router';
    import TicketsList from '@/features/tickets/list';
    
    export const Route = createLazyFileRoute('/(authenticated)/tickets/')({
      component: TicketsList,
    });

Using Global State

// src/stores/my-store.ts
import { create } from 'zustand';

export const useMyStore = create<State & Actions>((set) => ({
  count: 0,
  increment: () => set((s) => ({ count: s.count + 1 })),
}));

// In component
const count = useMyStore((s) => s.count);

Form Validation

// schema.ts
import { z } from 'zod';

export const loginSchema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
});

export const defaultValues = {
  email: '',
  password: '',
};

πŸ“š Documentation

  • Folder Structure: See README.md files in each src/ subfolder
  • Component Stories: Run pnpm storybook and check "Stories Overview"
  • API Reference: Check inline JSDoc comments

🀝 Contributing

  1. Follow the established folder structure
  2. Use TypeScript for type safety
  3. Write Storybook stories for new components
  4. Keep features self-contained
  5. Update relevant README files

πŸ“ Code Style

  • TypeScript: Strict mode enabled
  • Naming: PascalCase for components, camelCase for functions
  • Imports: Use @/ alias for absolute imports
  • Components: Prefer named exports
  • Formatting: Prettier runs on commit via Husky

πŸ”§ Configuration Files

  • vite.config.ts - Vite configuration
  • eslint.config.js - ESLint rules
  • tsconfig.json - TypeScript compiler options
  • tailwind.config.js - Tailwind customization
  • components.json - shadcn/ui configuration

πŸ“„ License

MIT

πŸ™ Acknowledgments

Built with amazing tools from:

About

A production-ready React boilerplate with TypeScript, Vite, TanStack Router, TanStack Query, Zustand, and shadcn/ui. Built with modern best practices and scalable architecture patterns.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors