A complete base structure to kickstart React projects with TypeScript and Vite, pre-configured with best practices and essential tools for modern development.
- β‘ Vite - Lightning-fast build tool
- βοΈ React 19 - Latest React version
- π· TypeScript - Static typing
- π¨ Tailwind CSS - Utility-first CSS framework
- π£οΈ React Router DOM - Client-side routing
- π Axios - HTTP client
- π JWT Authentication - Complete authentication system
- πͺ JS Cookie - Cookie management
- π‘ Socket.io Client - Real-time communication
- π React Toastify - Elegant notifications
- π§ ESLint - Configured linting
- π₯ Firebase Integration - Ready for Firebase hosting
- π Hostinger Compatible - Hostinger deployment ready
- π Organized structure - Scalable architecture
βββ public/ # Static assets
βββ src/
β βββ assets/ # Static resources (images, icons)
β βββ configs/ # Application configurations
β βββ context/ # React Context API
β βββ hooks/ # Reusable custom hooks
β βββ pages/ # Page components
β β βββ auth/ # Authentication pages
β β βββ dashboard.tsx
β β βββ layout-secure.tsx
β β βββ not-found.tsx
β βββ services/ # Services (Clinet API)
β βββ types/ # TypeScript definitions
β βββ utils/ # Utility functions
β βββ App.tsx # Root component
βββ .env # Environment variables
βββ .firebaserc # Firebase project configuration
βββ firebase.json # Firebase hosting configuration
βββ package.json # Dependencies and scripts
βββ tailwind.config.js
βββ tsconfig.json # TypeScript configuration
βββ vite.config.ts # Vite configuration
- useAppContext - Access to global application context
- useConfirmation - Reusable confirmation modal
- useDeviceFingerprint - Unique device identification
- useScrollTop - Page scroll control
- useSecurePage - Protected route authentication
- Complete JWT system
- Route protection
- Session management
- Automatic token refresh
- Configured HTTP client (Axios)
- WebSocket ready (Socket.io)
- Authentication interceptors
- Global error handling
- Tailwind CSS configured
- Utility-first approach
- Responsive design ready
- Dark mode support
- Configured toast notifications
- Customizable positioning
- Available themes
- Firebase hosting integration
- Hostinger deployment ready
- Production build optimization
git clone https://github.com/raphaelvserafim/base-react-typescript-vite.git
cd base-react-typescript-vite
npm install
# or
yarn install
Create a .env
file in the project root:
VITE_LOGO=public/vite.svg
VITE_NAME=My App
VITE_API_BASE_URL=http://localhost:3001
VITE_SOCKET_URL=http://localhost:3001/socket
VITE_RECAPTCHA_SITE_KEY=your_recaptcha_site_key
VITE_FAVICON=public/vite.svg
npm run dev
# or
yarn dev
npm run build
# or
yarn build
npm run dev
- Start development servernpm run build
- Generate production buildnpm run lint
- Run lintingnpm run preview
- Preview production buildnpm run deploy:firebase
- Build and deploy to Firebase hosting
This template comes pre-configured for Firebase hosting deployment.
{
"hosting": {
"site": "your-site-name",
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
{
"projects": {
"default": "your-project-id"
}
}
- Install Firebase CLI (if not already installed):
npm install -g firebase-tools
- Login to Firebase:
firebase login
- Initialize Firebase (if not already done):
firebase init hosting
-
Update configuration files:
- Edit
firebase.json
and replace"your-site-name"
with your actual site name - Edit
.firebaserc
and replace"your-project-id"
with your Firebase project ID
- Edit
-
Deploy to Firebase:
npm run deploy:firebase
This template is also compatible with Hostinger hosting:
- Build the project:
npm run build
-
Upload the dist folder contents to your Hostinger public_html directory
-
Configure URL rewriting by adding this to your
.htaccess
file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
After setting up the project, you can:
- Customize the context in
src/context/provider.tsx
- Configure your routes in
src/App.tsx
- Adapt the services in
src/services/
- Define your types in
src/types/
- Create your pages in
src/pages/
- Configure Firebase or Hostinger for deployment
Technology | Version | Description |
---|---|---|
React | ^19.1.1 | UI library |
TypeScript | ~5.8.3 | JavaScript superset |
Vite | ^7.1.2 | Modern build tool |
Tailwind CSS | ^3.x | Utility-first CSS framework |
React Router DOM | ^7.8.2 | Client-side routing |
Axios | ^1.11.0 | HTTP client |
Socket.io Client | ^4.8.1 | WebSocket client |
React Toastify | ^11.0.5 | Toast notifications |
JWT Decode | ^4.0.0 | JWT decoding |
JS Cookie | ^3.0.5 | Cookie management |
Firebase | Latest | Hosting and backend services |
This project is licensed under the MIT License. See the LICENSE
file for more details.
Raphael Serafim
The global context is already configured to manage application state:
const { user, isAuthenticated, logout } = useAppContext();
Use the useSecurePage
hook to protect pages:
const MySecurePage = () => {
useSecurePage(); // Redirects if not authenticated
return <div>Protected content</div>;
};
Display notifications easily:
import { toast } from 'react-toastify';
toast.success('Operation completed successfully!');
toast.error('Error processing request');
Get unique device identification:
const { deviceId, generateFingerprint } = useDeviceFingerprint();
Style your components with utility classes:
const MyComponent = () => {
return (
<div className="bg-blue-500 text-white p-4 rounded-lg shadow-md hover:bg-blue-600 transition-colors">
<h1 className="text-2xl font-bold mb-2">Welcome</h1>
<p className="text-blue-100">Styled with Tailwind CSS</p>
</div>
);
};
Quick deployment to different platforms:
# Firebase deployment
npm run deploy:firebase
# Manual build for Hostinger
npm run build
# Then upload dist/ contents to public_html/
β If this template was helpful, consider giving the repository a star!