Developer ToolsFeatured

React Velocity Starter: Building the Modern React Template I Wish I Had

Creating a feature-driven React starter template with modern tooling, comprehensive testing, and developer experience optimization.

December 22, 2024
12 min read
By Manjunatha C
ReactViteTypeScriptStarter TemplateDeveloper ExperienceModern Tooling

Learn how to build a production-ready React starter template from scratch, following the exact methodology I used to create React Velocity Starter. This comprehensive tutorial will guide you through creating a modern, scalable React application foundation with the latest tools and best practices.

๐ŸŽฏ What You'll Build

By the end of this tutorial, you'll have created:

FeatureDescription
Feature-Based ArchitectureScalable project structure that grows with complexity
Modern ToolingReact 19, TypeScript 5.8+, Vite 6+ for optimal DX
Comprehensive TestingVitest, Playwright, MSW for reliable testing
InternationalizationType-safe translations with react-i18next
Code GenerationPlop.js templates for consistent development
Production ReadyOptimized builds and deployment configuration

๐Ÿ“‹ Prerequisites

Before we start, ensure you have:

RequirementVersionPurpose
Node.js18+ (22+ recommended)JavaScript runtime
pnpm9+Package manager (preferred)
GitLatestVersion control
KnowledgeReact, TypeScript, modern JSDevelopment foundation

๐Ÿš€ Step 1: Project Initialization and Basic Setup

Let's start by creating our project structure:

bash
# Create the project directory mkdir react-velocity-starter cd react-velocity-starter # Initialize the project npm init -y # Install pnpm globally if you haven't already npm install -g pnpm

Update your package.json:

json
{ "name": "react-velocity-starter", "private": true, "version": "0.1.0", "type": "module", "description": "Modern React starter template with TypeScript, Vite, and comprehensive tooling", "keywords": [ "react", "typescript", "vite", "starter", "template" ], "scripts": { "dev": "vite", "build": "tsc && vite build", "preview": "vite preview", "test": "vitest", "test:ui": "vitest --ui", "test:e2e": "playwright test", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint:fix": "eslint . --ext ts,tsx --fix", "type-check": "tsc --noEmit", "generate": "plop" } }

๐Ÿ—๏ธ Step 2: Feature-Based Architecture

Create a scalable folder structure:

bash
# Create the folder structure mkdir -p src/{features,shared,app,pages} mkdir -p src/shared/{components,hooks,utils,types,constants} mkdir -p src/features/{auth,dashboard} mkdir -p src/features/auth/{components,hooks,services,types} mkdir -p public/{icons,images} mkdir -p docs mkdir -p tests/{e2e,fixtures,mocks}

๐Ÿ“ Folder Structure Benefits

DirectoryPurposeBenefits
src/features/Domain-specific codeBetter code organization, easier to maintain
src/shared/Reusable components and utilitiesPromotes code reuse and consistency
src/app/Application-level configurationCentralized app setup and providers
tests/Testing utilities and fixturesOrganized testing infrastructure

โšก Step 3: Modern Tooling Configuration

๐Ÿ”ง Vite Configuration

Create vite.config.ts:

typescript
import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' import { resolve } from 'path' export default defineConfig({ plugins: [react()], resolve: { alias: { '@': resolve(__dirname, './src'), '@/features': resolve(__dirname, './src/features'), '@/shared': resolve(__dirname, './src/shared'), '@/app': resolve(__dirname, './src/app'), '@/tests': resolve(__dirname, './tests') } }, server: { port: 3000, open: true }, build: { rollupOptions: { output: { manualChunks: { vendor: ['react', 'react-dom'], router: ['react-router-dom'], utils: ['date-fns', 'clsx'] } } } }, test: { globals: true, environment: 'jsdom', setupFiles: ['./tests/setup.ts'] } })

๐Ÿ“ TypeScript Configuration

Create tsconfig.json:

json
{ "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "baseUrl": ".", "paths": { "@/*": ["./src/*"], "@/features/*": ["./src/features/*"], "@/shared/*": ["./src/shared/*"], "@/app/*": ["./src/app/*"], "@/tests/*": ["./tests/*"] } }, "include": ["src", "tests"], "exclude": ["node_modules", "dist"] }

๐Ÿงช Step 4: Comprehensive Testing Setup

โš™๏ธ Testing Stack Overview

ToolPurposeBenefits
VitestUnit and integration testsFast, Vite-native, ESM support
Testing LibraryComponent testing utilitiesUser-centric testing approach
PlaywrightEnd-to-end testingCross-browser, reliable, fast
MSWAPI mockingRealistic network layer mocking

๐Ÿ”ฌ Test Setup Configuration

Create tests/setup.ts:

typescript
import '@testing-library/jest-dom' import { beforeAll, afterEach, afterAll } from 'vitest' import { cleanup } from '@testing-library/react' import { server } from './mocks/server' // Start the MSW server before all tests beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) // Clean up after each test afterEach(() => { cleanup() server.resetHandlers() }) // Close the server after all tests afterAll(() => server.close()) // Mock IntersectionObserver global.IntersectionObserver = class IntersectionObserver { observe() { return null } disconnect() { return null } unobserve() { return null } }

๐ŸŽญ Playwright Configuration

Create playwright.config.ts:

typescript
import { defineConfig, devices } from '@playwright/test' export default defineConfig({ testDir: './tests/e2e', fullyParallel: true, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, reporter: 'html', use: { baseURL: 'http://localhost:3000', trace: 'on-first-retry', screenshot: 'only-on-failure' }, projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'] } }, { name: 'firefox', use: { ...devices['Desktop Firefox'] } }, { name: 'webkit', use: { ...devices['Desktop Safari'] } } ], webServer: { command: 'pnpm dev', url: 'http://localhost:3000', reuseExistingServer: !process.env.CI } })

๐ŸŽจ Step 5: Code Generation with Plop.js

Automate component and feature creation:

javascript
// plopfile.js export default function (plop) { // Component generator plop.setGenerator('component', { description: 'Create a new React component', prompts: [ { type: 'input', name: 'name', message: 'Component name:' }, { type: 'list', name: 'type', message: 'Component type:', choices: ['shared', 'feature'] }, { type: 'input', name: 'feature', message: 'Feature name (if feature component):', when: (answers) => answers.type === 'feature' } ], actions: (data) => { const basePath = data.type === 'shared' ? 'src/shared/components' : `src/features/${data.feature}/components` return [ { type: 'add', path: `${basePath}/{{pascalCase name}}/{{pascalCase name}}.tsx`, templateFile: 'plop-templates/component.hbs' }, { type: 'add', path: `${basePath}/{{pascalCase name}}/{{pascalCase name}}.test.tsx`, templateFile: 'plop-templates/component.test.hbs' }, { type: 'add', path: `${basePath}/{{pascalCase name}}/index.ts`, templateFile: 'plop-templates/index.hbs' } ] } }) // Feature generator plop.setGenerator('feature', { description: 'Create a new feature module', prompts: [ { type: 'input', name: 'name', message: 'Feature name:' } ], actions: [ { type: 'add', path: 'src/features/{{kebabCase name}}/index.ts', template: 'export * from "./components"\nexport * from "./hooks"\nexport * from "./services"' }, { type: 'add', path: 'src/features/{{kebabCase name}}/components/index.ts', template: '// Export components here' }, { type: 'add', path: 'src/features/{{kebabCase name}}/hooks/index.ts', template: '// Export hooks here' }, { type: 'add', path: 'src/features/{{kebabCase name}}/services/index.ts', template: '// Export services here' }, { type: 'add', path: 'src/features/{{kebabCase name}}/types/index.ts', template: '// Export types here' } ] }) }

๐ŸŽฏ Key Benefits of This Starter Template

๐Ÿš€ Developer Experience

  • โ€ข Hot module reloading with Vite
  • โ€ข TypeScript for type safety
  • โ€ข Code generation for consistency
  • โ€ข Comprehensive linting and formatting

๐Ÿงช Testing Excellence

  • โ€ข Unit tests with Vitest
  • โ€ข Component tests with Testing Library
  • โ€ข E2E tests with Playwright
  • โ€ข API mocking with MSW

๐Ÿ—๏ธ Scalable Architecture

  • โ€ข Feature-based organization
  • โ€ข Clear separation of concerns
  • โ€ข Reusable shared components
  • โ€ข Consistent code structure

๐Ÿšข Production Ready

  • โ€ข Optimized build configuration
  • โ€ข Bundle analysis and splitting
  • โ€ข Performance monitoring setup
  • โ€ข Deployment-ready scripts

๐Ÿ“ฆ Installation and Setup Commands

Install all necessary dependencies:

bash
# Core dependencies pnpm add react react-dom react-router-dom pnpm add @tanstack/react-query axios pnpm add react-i18next i18next i18next-browser-languagedetector pnpm add clsx tailwind-merge lucide-react # Development dependencies pnpm add -D typescript @types/react @types/react-dom pnpm add -D vite @vitejs/plugin-react-swc pnpm add -D vitest @vitest/ui jsdom pnpm add -D @testing-library/react @testing-library/jest-dom pnpm add -D @testing-library/user-event pnpm add -D @playwright/test pnpm add -D msw pnpm add -D eslint @typescript-eslint/eslint-plugin pnpm add -D prettier eslint-config-prettier pnpm add -D plop pnpm add -D tailwindcss postcss autoprefixer

๐Ÿƒโ€โ™‚๏ธ Getting Started

bash
# Clone or create your project git clone <your-repo> my-app cd my-app # Install dependencies pnpm install # Start development server pnpm dev # Run tests pnpm test # Generate new component pnpm generate # Build for production pnpm build

๐ŸŽ‰ What You've Accomplished

Congratulations! You've created a modern, scalable React starter template that includes:

  • โœ… Feature-based architecture for scalable code organization
  • โœ… Modern tooling with Vite, TypeScript, and React 19
  • โœ… Comprehensive testing setup with Vitest, Playwright, and MSW
  • โœ… Code generation for consistent development patterns
  • โœ… Production-ready build and deployment configuration
  • โœ… Developer experience optimizations for maximum productivity

This template provides a solid foundation for building modern React applications while maintaining flexibility for customization based on your specific project needs.

๐Ÿ”— Additional Resources

Vite Documentation

Fast build tool for modern web development

Visit

Vitest

Vite-native unit testing framework

Visit

Playwright

End-to-end testing framework

Visit

Plop.js

Code generation tool

Visit