Skip to content

A complete base structure to kickstart React projects with TypeScript and Vite, pre-configured with best practices and essential tools for modern development.

Notifications You must be signed in to change notification settings

raphaelvserafim/base-react-typescript-vite

Repository files navigation

Base React TypeScript Vite

A complete base structure to kickstart React projects with TypeScript and Vite, pre-configured with best practices and essential tools for modern development.

πŸš€ Features

  • ⚑ 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

πŸ“¦ Project Structure

β”œβ”€β”€ 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

πŸ› οΈ Included Custom Hooks

  • useAppContext - Access to global application context
  • useConfirmation - Reusable confirmation modal
  • useDeviceFingerprint - Unique device identification
  • useScrollTop - Page scroll control
  • useSecurePage - Protected route authentication

βš™οΈ Pre-configured Settings

Authentication

  • Complete JWT system
  • Route protection
  • Session management
  • Automatic token refresh

Communication

  • Configured HTTP client (Axios)
  • WebSocket ready (Socket.io)
  • Authentication interceptors
  • Global error handling

Styling

  • Tailwind CSS configured
  • Utility-first approach
  • Responsive design ready
  • Dark mode support

Notifications

  • Configured toast notifications
  • Customizable positioning
  • Available themes

Deployment

  • Firebase hosting integration
  • Hostinger deployment ready
  • Production build optimization

πŸš€ Getting Started

1. Clone or download the project

git clone https://github.com/raphaelvserafim/base-react-typescript-vite.git
cd base-react-typescript-vite

2. Install dependencies

npm install
# or
yarn install

3. Configure your environment variables

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

4. Start the development server

npm run dev
# or
yarn dev

5. Build for production

npm run build
# or
yarn build

πŸ“‹ Available Scripts

  • npm run dev - Start development server
  • npm run build - Generate production build
  • npm run lint - Run linting
  • npm run preview - Preview production build
  • npm run deploy:firebase - Build and deploy to Firebase hosting

πŸ”₯ Firebase Integration

This template comes pre-configured for Firebase hosting deployment.

Firebase Configuration

1. Configure firebase.json

{
  "hosting": {
    "site": "your-site-name",
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

2. Configure .firebaserc

{
  "projects": {
    "default": "your-project-id"
  }
}

Firebase Deployment Steps

  1. Install Firebase CLI (if not already installed):
npm install -g firebase-tools
  1. Login to Firebase:
firebase login
  1. Initialize Firebase (if not already done):
firebase init hosting
  1. 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
  2. Deploy to Firebase:

npm run deploy:firebase

🌐 Hostinger Deployment

This template is also compatible with Hostinger hosting:

Hostinger Deployment Steps

  1. Build the project:
npm run build
  1. Upload the dist folder contents to your Hostinger public_html directory

  2. 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>

🎯 Next Steps

After setting up the project, you can:

  1. Customize the context in src/context/provider.tsx
  2. Configure your routes in src/App.tsx
  3. Adapt the services in src/services/
  4. Define your types in src/types/
  5. Create your pages in src/pages/
  6. Configure Firebase or Hostinger for deployment

πŸ”§ Tech Stack

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

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for more details.

πŸ‘¨β€πŸ’» Author

Raphael Serafim


πŸ’‘ Usage Tips

Context API

The global context is already configured to manage application state:

const { user, isAuthenticated, logout } = useAppContext();

Protected Routes

Use the useSecurePage hook to protect pages:

const MySecurePage = () => {
  useSecurePage(); // Redirects if not authenticated
  return <div>Protected content</div>;
};

Notifications

Display notifications easily:

import { toast } from 'react-toastify';

toast.success('Operation completed successfully!');
toast.error('Error processing request');

Device Fingerprint

Get unique device identification:

const { deviceId, generateFingerprint } = useDeviceFingerprint();

Tailwind CSS Styling

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>
  );
};

Deployment Commands

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!

About

A complete base structure to kickstart React projects with TypeScript and Vite, pre-configured with best practices and essential tools for modern development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published