A production-ready React frontend boilerplate with pre-configured Google OAuth, routing, state management, and modern tooling. Skip the setup and start building your next project immediately.
- React 19 - Latest React with modern features
- Vite - Lightning-fast build tool and dev server
- Tailwind CSS 4 - Utility-first CSS framework with latest version
- React Router DOM 7 - Client-side routing with latest features
- Google OAuth Integration - Ready-to-use Google authentication with
@react-oauth/google - Protected Routes - Route protection with customizable authentication checks
- Context-based Auth Management - Centralized authentication state
- Security Features - Right-click and shortcut key protection (Ctrl+U, Ctrl+S)
- ESLint - Code linting with React-specific rules
- Hot Module Replacement - Instant updates during development
- Environment Management - Centralized configuration with error handling
- TypeScript Support - Ready for TypeScript integration
- Loading Screens - Beautiful animated loading components
- Toast Notifications - React Hot Toast integration
- 404 Error Page - Styled not found page with navigation
- Responsive Design - Mobile-first responsive layouts
- useGoogleAuth - Google OAuth integration hook
- useLocalStorage - Persistent state management with cross-tab synchronization
- useNavigation - Section-based navigation utilities
- useLoading - Global loading state management
- Axios Instance - Pre-configured HTTP client with interceptors
- Scroll Management - Automatic scroll-to-top on route changes
- Lazy Loading - Code splitting for optimal performance
- Suspense Boundaries - Proper loading states for lazy components
- Centralized State - Context-based state management
- Optimized Builds - Vite's optimized production builds
frontend-boilerplate/
βββ public/ # Static assets
βββ src/
β βββ components/ # Reusable UI components
β β βββ LoadingBar.jsx # Animated loading spinner
β β βββ LoadingScreen.jsx # Full-screen loading overlay
β βββ context/ # React Context providers
β β βββ AuthContext.jsx # Authentication state management
β β βββ LoadingContext.jsx # Loading state management
β βββ hooks/ # Custom React hooks
β β βββ useGoogleOAuth.js # Google authentication hook
β β βββ useLoading.js # Loading state hook
β β βββ useLocalStorage.js # Persistent state hook
β β βββ useNavigation.js # Navigation utilities hook
β βββ pages/ # Route components
β β βββ Home.jsx # Home page component
β β βββ NotFound.jsx # 404 error page
β βββ utilis/ # Utility functions and configurations
β β βββ AxiosInstance.jsx # Pre-configured Axios client
β β βββ config.js # Environment variables management
β β βββ RenderProtectedRoute.jsx # Route protection component
β β βββ ScrollToTop.jsx # Auto-scroll utility
β βββ App.jsx # Main application component
β βββ main.jsx # Application entry point
β βββ index.css # Global styles (Tailwind imports)
βββ .env.sample # Environment variables template
βββ eslint.config.js # ESLint configuration
βββ package.json # Project dependencies and scripts
βββ vite.config.js # Vite configuration
βββ README.md # This file
- Node.js (v18 or higher)
- npm or yarn
- Google Cloud Console project (for OAuth)
- Clone the repository
git clone <your-repo-url>
cd frontend-boilerplate- Install dependencies
npm install- Environment Setup
cp .env.sample .env- Configure environment variables
Open
.envand fill in your values:
VITE_GOOGLE_CLIENT_ID=your-google-client-id-here
VITE_BACKEND_URL=your-backend-url-here
VITE_AUTH_URL=your-auth-service-url-here- Start development server
npm run devnpm run dev- Start development server with HMRnpm run build- Build for productionnpm run preview- Preview production build locallynpm run lint- Run ESLint for code quality checks
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized JavaScript origins (e.g.,
http://localhost:5173) - Add authorized redirect URIs
VITE_GOOGLE_CLIENT_ID=your-google-oauth-client-idimport { useGoogleAuth } from './hooks/useGoogleOAuth';
const LoginButton = () => {
const { handleGoogleLogin } = useGoogleAuth();
return (
<button onClick={handleGoogleLogin}>
Sign in with Google
</button>
);
};Use the RenderProtectedRoute component to protect routes:
import RenderProtectedRoute from './utilis/RenderProtectedRoute';
const ProtectedPage = () => (
<RenderProtectedRoute
condition={isAuthenticated}
renderPage={<YourProtectedComponent />}
fallback="/login"
errorMessage="Please login to access this page"
devMode={false} // Set to true to bypass protection in development
/>
);- Latest Tailwind CSS 4.x with Vite plugin
- Custom animations and components
- Responsive design utilities
- Dark mode support ready
Global styles are imported in src/index.css:
@import "tailwindcss";The app uses React Context for state management:
- AuthContext - Authentication state
- LoadingContext - Global loading states
import { useLocalStorageState } from './hooks/useLocalStorage';
const [userData, setUserData] = useLocalStorageState('user', null);Pre-configured Axios instance with:
- Base URL from environment
- Credentials included
- JSON content type headers
import axiosInstance from './utilis/AxiosInstance';
const fetchData = async () => {
const response = await axiosInstance.get('/api/data');
return response.data;
};Handles Google OAuth flow with error handling and navigation.
Persistent state with cross-tab synchronization and error handling.
Section-based navigation with smooth scrolling.
Global loading state management.
npm run buildEnsure all required environment variables are set:
VITE_GOOGLE_CLIENT_IDVITE_BACKEND_URLVITE_AUTH_URL
- Create component in
src/pages/ - Add lazy import in
App.jsx - Add route in the Routes component
- Create hook file in
src/hooks/ - Follow the existing naming convention
- Include error handling and TypeScript support
- Update
AuthContext.jsxfor additional auth states - Modify
useGoogleOAuth.jsfor custom OAuth flows - Adjust
RenderProtectedRoute.jsxfor custom protection logic
- Ensure variables start with
VITE_ - Restart development server after changes
- Check
.envfile is in root directory
- Verify client ID is correct
- Check authorized domains in Google Console
- Ensure backend URL is accessible
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Vite Team - For the amazing build tool
- React Team - For the fantastic framework
- Tailwind CSS - For the utility-first CSS approach
- Google OAuth - For seamless authentication integration
Happy Coding! π
This boilerplate is designed to save you hours of initial setup and let you focus on building amazing features.