An open API service indexing awesome lists of open source software.

https://github.com/trhgatu/inf-vite-frontend-template


https://github.com/trhgatu/inf-vite-frontend-template

axios es jwt reactjs redux-toolkit tailwindcss types vite

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

          

# โšก trhgatu-inf-vite-frontend-template

![Vite](https://img.shields.io/badge/Vite-5-646CFF?style=for-the-badge&logo=vite&logoColor=white)
![React](https://img.shields.io/badge/React-18-61DAFB?style=for-the-badge&logo=react&logoColor=white)
![TypeScript](https://img.shields.io/badge/TypeScript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
![Redux](https://img.shields.io/badge/Redux_Toolkit-764abc?style=for-the-badge&logo=redux&logoColor=white)

**A lightning-fast, production-ready Vite 5 template with React 18, TypeScript, Redux Toolkit, admin-first architecture, and automated CI/CD pipeline.**

[๐Ÿš€ Quick Start](#-quick-start) โ€ข [๐Ÿ“– Documentation](#-features) โ€ข [๐Ÿค Contributing](#-contributing) โ€ข [๐Ÿ’ฌ Support](#-support)

---

## โœจ Features

**โšก Performance**
- Vite 5 lightning-fast HMR
- React 18 concurrent features
- Optimized build pipeline
- Tree-shaking enabled

**๐Ÿ—๏ธ Architecture**
- Admin-first design
- Feature-based organization
- Modular folder structure
- Route protection system

**๐Ÿ” Authentication**
- Complete auth flow
- Protected routes
- Auth state persistence
- Form validation with Zod

**๐Ÿ› ๏ธ Developer Experience**
- TypeScript for type safety
- ESLint + Prettier
- GitHub Actions CI/CD
- Hot module replacement

---

## ๐Ÿง  Tech Stack

| Category | Technologies |
|----------|-------------|
| **Build Tool** | Vite 5 |
| **Framework** | React 18 |
| **Language** | TypeScript |
| **State Management** | Redux Toolkit, RTK Query |
| **HTTP Client** | Axios |
| **Validation** | Zod |
| **Routing** | React Router DOM |
| **Testing** | Vitest, React Testing Library |
| **Linting** | ESLint, Prettier |
| **CI/CD** | GitHub Actions |

---

## ๐Ÿ“ Project Structure

```
trhgatu-inf-vite-frontend-template/
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ features/ # Feature modules
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ auth/ # Authentication feature
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ hooks.ts # Auth hooks
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ services.ts # Auth API services
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ schemas.ts # Validation schemas
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ types.ts # Auth types
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ dashboard/ # Dashboard feature
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ users/ # User management
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“ errors/ # Error handling
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ layouts/ # Layout components
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ AdminLayout.tsx # Admin panel layout
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ AuthLayout.tsx # Authentication layout
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ routes/ # Routing configuration
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ AppRouter.tsx # Main router
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ ProtectedRoute.tsx # Route protection
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ AuthGate.tsx # Auth gate component
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ components/ # Reusable components
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ shared/ # Shared UI components
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“ forms/ # Form components
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ hooks/ # Custom hooks
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ useAuth.ts # Authentication hook
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ services/ # API services
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ api.ts # Axios configuration
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ endpoints.ts # API endpoints
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ store/ # Redux store
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ index.ts # Store configuration
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ provider.tsx # Redux provider
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“ slices/ # Redux slices
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ authSlice.ts # Auth state slice
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ appSlice.ts # App state slice
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ types/ # TypeScript definitions
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ api.ts # API types
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ common.ts # Common types
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ utils/ # Utility functions
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ helpers.ts # Helper functions
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ App.tsx # Main App component
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ main.tsx # Application entry point
โ”œโ”€โ”€ ๐Ÿ“ .github/workflows/ # GitHub Actions
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ ci.yml # CI/CD pipeline
โ”œโ”€โ”€ ๐Ÿ“„ vite.config.ts # Vite configuration
โ”œโ”€โ”€ ๐Ÿ“„ tsconfig.json # TypeScript configuration
โ”œโ”€โ”€ ๐Ÿ“„ .eslintrc.json # ESLint configuration
โ”œโ”€โ”€ ๐Ÿ“„ .prettierrc # Prettier configuration
โ”œโ”€โ”€ ๐Ÿ“„ .env.example # Environment variables template
โ””โ”€โ”€ ๐Ÿ“„ package.json # Dependencies & scripts
```

---

## ๐Ÿš€ Quick Start

### Prerequisites

Make sure you have the following installed:
- Node.js 18+
- npm, yarn, or pnpm

### Installation

1. **Clone the repository**
```bash
git clone https://github.com/trhgatu/trhgatu-inf-vite-frontend-template.git
cd trhgatu-inf-vite-frontend-template
```

2. **Install dependencies**
```bash
npm install
# or
yarn install
# or
pnpm install
```

3. **Set up environment variables**
```bash
cp .env.example .env.local
# Edit .env.local with your configuration
```

4. **Run the development server**
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

5. **Open your browser**

Navigate to [http://localhost:5173](http://localhost:5173) to see your application.

---

## ๐Ÿ” Authentication System

The template includes a comprehensive authentication system designed for admin panels:

- **Admin Login**: `/admin/login` with form validation
- **Route Protection**: `ProtectedRoute` and `AuthGate` components
- **State Persistence**: Auth state survives page refreshes
- **Type Safety**: Full TypeScript support
- **Validation**: Zod schema validation

### Usage Example

```typescript
import { useAuth } from '@/hooks/useAuth';

function AdminDashboard() {
const { user, isAuthenticated, login, logout } = useAuth();

if (!isAuthenticated) {
return

Redirecting to login...
;
}

return (

Welcome to Admin Panel, {user?.name}!


Logout

);
}
```

### Auth Flow

```typescript
// Login process
const handleLogin = async (credentials: LoginCredentials) => {
try {
const response = await authService.login(credentials);
dispatch(setAuth(response.data));
navigate('/admin/dashboard');
} catch (error) {
// Handle error
}
};
```

---

## ๐Ÿ—๏ธ Architecture Overview

### Feature-Based Organization

Each feature is self-contained with its own:
- **Components**: Feature-specific UI components
- **Hooks**: Custom hooks for business logic
- **Services**: API calls and data fetching
- **Types**: TypeScript interfaces
- **Schemas**: Validation schemas

### Layout System

- **AdminLayout**: Main admin panel layout with sidebar navigation
- **AuthLayout**: Clean layout for login/register pages
- **Responsive**: Mobile-first design approach

---

## โšก Performance Optimizations

### Vite 5 Features
- **Lightning Fast HMR**: Sub-second hot module replacement
- **Optimized Build**: Tree-shaking and code splitting
- **ES Modules**: Native ESM support
- **Plugin Ecosystem**: Rich plugin ecosystem

### React 18 Features
- **Concurrent Features**: Improved user experience
- **Automatic Batching**: Better performance
- **Suspense**: Better loading states

---

## ๐Ÿ› ๏ธ Available Scripts

| Command | Description |
|---------|-------------|
| `npm run dev` | Start development server |
| `npm run build` | Build for production |
| `npm run preview` | Preview production build |
| `npm run lint` | Run ESLint |
| `npm run lint:fix` | Fix ESLint issues |
| `npm run format` | Format code with Prettier |
| `npm run type-check` | Run TypeScript compiler |
| `npm run test` | Run tests with Vitest |

---

## ๐Ÿงช CI/CD Pipeline

Automated workflow with GitHub Actions (`.github/workflows/ci.yml`):

```yaml
โœ… Code Quality Checks
โ”œโ”€โ”€ ESLint validation
โ”œโ”€โ”€ Prettier formatting
โ”œโ”€โ”€ TypeScript compilation
โ””โ”€โ”€ Unit tests with Vitest

โœ… Build & Deploy
โ”œโ”€โ”€ Production build
โ”œโ”€โ”€ Build artifact caching
โ””โ”€โ”€ Deployment (when configured)
```

The pipeline runs on:
- Push to `main` branch
- Pull requests to `main`
- Manual workflow dispatch

---

## ๐Ÿ“ฆ Key Dependencies

### Core
- **vite**: ^5.0.0
- **react**: ^18.0.0
- **react-dom**: ^18.0.0
- **typescript**: ^5.0.0

### Routing & State
- **react-router-dom**: ^6.8.0
- **@reduxjs/toolkit**: ^1.9.0
- **react-redux**: ^8.1.0

### Validation & HTTP
- **zod**: ^3.22.0
- **axios**: ^1.5.0

### Development & Testing
- **vitest**: ^0.34.0
- **@testing-library/react**: ^13.4.0
- **eslint**: ^8.50.0
- **prettier**: ^3.0.0

---

## ๐ŸŽฏ Customization

### Adding New Features

1. **Create Feature Directory**
```bash
mkdir src/features/my-feature
cd src/features/my-feature
```

2. **Add Feature Files**
```
my-feature/
โ”œโ”€โ”€ components/
โ”œโ”€โ”€ hooks/
โ”œโ”€โ”€ services/
โ”œโ”€โ”€ types.ts
โ””โ”€โ”€ index.ts
```

3. **Create Redux Slice**
```typescript
// src/store/slices/myFeatureSlice.ts
import { createSlice } from '@reduxjs/toolkit';

export const myFeatureSlice = createSlice({
name: 'myFeature',
initialState: {},
reducers: {}
});
```

### Environment Configuration

Create `.env.local` for local development:

```env
VITE_API_URL=http://localhost:8000/api
VITE_APP_NAME=Admin Panel
VITE_APP_VERSION=1.0.0
```

### Styling Customization

The template uses CSS modules and styled-components patterns:

```typescript
// Component styling
const StyledButton = styled.button`
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
border-radius: 8px;
padding: 12px 24px;
color: white;
font-weight: 600;
cursor: pointer;

&:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}
`;
```

---

## ๐Ÿš€ Deployment

### Vercel (Recommended)
```bash
npm i -g vercel
vercel --prod
```

### Netlify
```bash
npm run build
# Upload dist/ folder to Netlify
```

### Docker
```dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 5173
CMD ["npm", "run", "preview"]
```

### Other Platforms
- **Railway**: One-click deployment
- **AWS S3**: Static hosting with CloudFront
- **GitHub Pages**: Free static hosting

---

## ๐Ÿงช Testing Strategy

### Unit Testing with Vitest
```typescript
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { LoginForm } from './LoginForm';

describe('LoginForm', () => {
it('renders login form correctly', () => {
render();
expect(screen.getByRole('button', { name: /login/i })).toBeInTheDocument();
});
});
```

### Integration Testing
```typescript
import { renderWithProviders } from '@/utils/test-utils';
import { AuthProvider } from '@/features/auth';

describe('Auth Integration', () => {
it('handles login flow correctly', async () => {
// Test implementation
});
});
```

---

## ๐Ÿค Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Development Workflow

1. **Fork the repository**
2. **Create your feature branch**
```bash
git checkout -b feature/amazing-feature
```
3. **Commit your changes**
```bash
git commit -m 'Add some amazing feature'
```
4. **Push to the branch**
```bash
git push origin feature/amazing-feature
```
5. **Open a Pull Request**

### Code Standards

- Follow TypeScript best practices
- Write meaningful commit messages
- Add tests for new features
- Update documentation when needed

---

## ๐Ÿ“š Learning Resources

### Vite Resources
- [Vite Official Guide](https://vitejs.dev/guide/)
- [Vite Plugin Ecosystem](https://vitejs.dev/plugins/)

### React & TypeScript
- [React 18 Documentation](https://react.dev/)
- [TypeScript Handbook](https://www.typescriptlang.org/docs/)

### State Management
- [Redux Toolkit Documentation](https://redux-toolkit.js.org/)
- [RTK Query Guide](https://redux-toolkit.js.org/rtk-query/overview)

---

## ๐Ÿ› Troubleshooting

### Common Issues

**Port already in use**
```bash
# Kill process on port 5173
npx kill-port 5173
```

**Module resolution errors**
```bash
# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
```

**Build failures**
```bash
# Check TypeScript errors
npm run type-check
```

---

## ๐Ÿ“ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

## ๐Ÿ’ฌ Support

- ๐Ÿ“ง **Email**: [trhgatu@example.com](mailto:trhgatu@example.com)
- ๐Ÿ› **Issues**: [GitHub Issues](https://github.com/trhgatu/trhgatu-inf-vite-frontend-template/issues)
- ๐Ÿ’ฌ **Discussions**: [GitHub Discussions](https://github.com/trhgatu/trhgatu-inf-vite-frontend-template/discussions)
- ๐Ÿ“– **Wiki**: [Project Wiki](https://github.com/trhgatu/trhgatu-inf-vite-frontend-template/wiki)

---

## ๐Ÿ™ Acknowledgments

- [Vite](https://vitejs.dev/) team for the blazing fast build tool
- [React](https://react.dev/) team for the amazing framework
- [Redux Toolkit](https://redux-toolkit.js.org/) for simplified state management
- [TypeScript](https://www.typescriptlang.org/) for making JavaScript better

---

**Built with โšก by [Infinity (trhgatu)](https://github.com/trhgatu)**

*"Every layout, every route, every pixel โ€“ a reflection of the warrior within."*

โญ **Star this repo if you found it helpful!**