Skip to content

indraxyz/products-reactrouterv7-cloudflare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Product Management Application

product management application built with React 19, React Router v7, Vite, and Tailwind CSS v4, optimized for Cloudflare Pages deployment.

πŸš€ Tech Stack

  • React 19 - Latest React with concurrent features (useTransition, useOptimistic)
  • React Router v7 - Modern routing with lazy loading and error boundaries
  • Vite 7 - Next-generation frontend tooling
  • Tailwind CSS v4 - Utility-first CSS framework
  • TypeScript - Type-safe development with strict mode
  • Zod - Schema validation for forms and data
  • React Hook Form - Performant form management with validation
  • React Hot Toast - Beautiful toast notifications
  • Lucide React - Modern icon library
  • Cloudflare Pages - Edge deployment with Functions support

✨ Features

Product Management

  • βœ… Full CRUD Operations - Create, read, update, and delete products
  • πŸ” Advanced Filtering - Search by name, filter by category
  • πŸ“Š Sorting - Sort by price, name, discount, stock, or date (ascending/descending)
  • πŸ—‘οΈ Bulk Delete - Select and delete multiple products at once
  • 🏷️ Product Variants - Support for product variants with price and stock modifiers
  • πŸ“Έ Image Management - Multiple image URLs per product
  • 🏷️ Tags & Categories - Organize products with tags and categories
  • πŸ’° Discount Management - Set percentage-based discounts
  • βš–οΈ Weight Tracking - Track product weight in grams

User Experience

  • ⚑ Optimized Performance - Code splitting, lazy loading, and optimized builds
  • 🎨 Modern UI - Beautiful, responsive design with smooth animations
  • πŸŒ™ Dark Mode - Full dark mode support with theme persistence
  • πŸ”„ React 19 Features - Uses useTransition for non-urgent updates and useOptimistic for instant feedback
  • πŸ“± Responsive Design - Mobile-first approach with Tailwind CSS
  • πŸ”” Toast Notifications - User-friendly feedback for all actions
  • ⏳ Loading States - Proper loading indicators and skeletons
  • πŸ›‘οΈ Error Handling - Comprehensive error boundaries and error states

Developer Experience

  • πŸ“¦ Code Splitting - Route-based and component-based lazy loading
  • πŸ›‘οΈ Type Safety - Full TypeScript support with strict mode
  • πŸš€ Fast Development - Hot module replacement and fast refresh
  • πŸ§ͺ Form Validation - Zod schemas with React Hook Form integration
  • πŸ“ Mock Data - Pre-configured mock products for development
  • ☁️ Cloudflare Optimized - Configured for Cloudflare Pages deployment

πŸ“¦ Installation

# Install dependencies
pnpm install

Environment Variables (Optional)

The application works out of the box with default values. To customize, create a .env file:

VITE_APP_TITLE=Product Management
VITE_API_URL=https://api.example.com

πŸ› οΈ Development

# Start development server
pnpm dev

# Type check
pnpm type-check

# Lint code
pnpm lint

# Fix linting issues
pnpm lint:fix

# Build for production
pnpm build

# Preview production build
pnpm preview

πŸš€ Deployment

Cloudflare Pages

The project is configured for Cloudflare Pages deployment with optimized settings:

  1. Using Wrangler CLI:

    # Deploy to production
    pnpm deploy
    
    # Deploy to preview branch
    pnpm deploy:preview
    
    # Create a new Pages project
    pnpm pages:project:create
    
    # Test Pages Functions locally
    pnpm pages:dev
  2. Using GitHub Actions:

    • Push to main branch
    • GitHub Actions will automatically build and deploy
    • Configure secrets in GitHub:
      • CLOUDFLARE_API_TOKEN
      • CLOUDFLARE_ACCOUNT_ID
  3. Using Cloudflare Dashboard:

    • Connect your GitHub repository
    • Set build command: pnpm build
    • Set output directory: dist
    • Framework preset: React
    • Deploy!

Cloudflare Pages Functions

The project includes a middleware function (functions/_middleware.ts) that adds security headers to all responses. This works alongside the static _headers file for comprehensive security coverage.

React Router v7 on Cloudflare Pages

React Router v7 is fully configured for Cloudflare Pages:

  • SPA Routing: The _redirects file ensures all routes serve index.html, allowing React Router v7 to handle client-side routing
  • Middleware: Optimized to skip static assets and only process HTML responses
  • Code Splitting: Routes are lazy-loaded for optimal performance
  • Error Handling: Route-level error boundaries for graceful error handling

See CLOUDFLARE_REACT_ROUTER.md for detailed information about the React Router v7 + Cloudflare Pages setup.

πŸ“ Project Structure

src/
β”œβ”€β”€ components/              # Reusable UI components
β”‚   β”œβ”€β”€ ProductTable.tsx    # Main product table with selection
β”‚   β”œβ”€β”€ ProductForm.tsx     # Add/Edit product form with validation
β”‚   β”œβ”€β”€ ProductDetail.tsx   # Product detail drawer
β”‚   β”œβ”€β”€ ProductFilters.tsx  # Search, filter, and sort controls
β”‚   β”œβ”€β”€ DeleteModal.tsx     # Single product delete confirmation
β”‚   β”œβ”€β”€ DeleteMultipleModal.tsx  # Bulk delete confirmation
β”‚   β”œβ”€β”€ ThemeToggle.tsx     # Dark mode toggle
β”‚   β”œβ”€β”€ ErrorBoundary.tsx   # Error boundary component
β”‚   └── LoadingFallback.tsx # Loading state component
β”œβ”€β”€ routes/                 # React Router route components
β”‚   β”œβ”€β”€ index.tsx           # Router configuration
β”‚   └── home.tsx            # Home page route (main product management)
β”œβ”€β”€ hooks/                  # Custom React hooks
β”‚   β”œβ”€β”€ useProductManager.ts  # Main product management logic
β”‚   └── useTheme.ts         # Theme context hook
β”œβ”€β”€ lib/                    # Utility functions
β”‚   β”œβ”€β”€ env.ts              # Environment variables
β”‚   └── preload.ts          # Preload utilities
β”œβ”€β”€ types/                  # TypeScript type definitions
β”‚   └── Product.ts          # Product and filter types
β”œβ”€β”€ data/                   # Data and mock data
β”‚   └── mockProducts.ts     # Mock product data for development
β”œβ”€β”€ context/                # React context providers
β”‚   └── ThemeContext.tsx    # Theme context (dark/light mode)
β”œβ”€β”€ styles/                 # Global styles
β”‚   └── index.css           # Tailwind CSS and custom styles
└── assets/                 # Static assets
    β”œβ”€β”€ react.svg
    └── placeholder-image.svg

🎯 Key Optimizations

Performance

  • Code Splitting: Automatic route-based and component-based lazy loading
  • Lazy Loading: ProductDetail, ProductForm, and modals loaded on demand
  • Optimistic Updates: Using React 19's useOptimistic for instant UI feedback
  • Transition Management: Using useTransition for non-urgent updates (drawer opens, filters)
  • Memoization: Strategic use of useMemo and useCallback for expensive operations
  • Debounced Search: Search input debounced to reduce unnecessary filtering
  • Pagination: Virtual pagination with configurable items per page
  • Asset Optimization: Optimized build output with proper chunking and tree shaking

Developer Experience

  • Path Aliases: @/ for src/ directory (configured in tsconfig.json and vite.config.ts)
  • TypeScript: Strict mode with comprehensive type checking
  • ESLint: Code quality and consistency with TypeScript support
  • Hot Module Replacement: Fast development feedback with Vite HMR
  • Environment Variables: Type-safe environment configuration
  • Mock Data: Pre-configured mock products for immediate development

Cloudflare Optimizations

  • Headers Configuration: Security headers (CSP, XSS protection, frame options) and caching strategies
  • Redirects: SPA routing support via _redirects file
  • Middleware: Cloudflare Pages Functions middleware for dynamic header injection
  • Build Optimization: Optimized for Cloudflare's edge network
  • Asset Caching: Long-term caching for static assets (31536000s), no-cache for HTML

πŸ”§ Configuration

Environment Variables

The application uses environment variables for configuration. Create a .env file in the root:

VITE_APP_TITLE=Product Management
VITE_API_URL=https://api.example.com

Environment variables are type-safe and accessed via src/lib/env.ts.

Path Aliases

The project uses path aliases for cleaner imports (configured in tsconfig.json and vite.config.ts):

import { ProductTable } from "@/components/ProductTable";
import { useProductManager } from "@/hooks/useProductManager";
import type { Product } from "@/types/Product";

Tailwind CSS v4

Tailwind CSS v4 is configured via tailwind.config.js and src/styles/index.css. The project uses:

  • Custom color schemes
  • Dark mode support
  • Custom animations and transitions
  • Responsive utilities

πŸ“ Scripts

  • pnpm dev - Start development server
  • pnpm build - Build for production
  • pnpm build:analyze - Build with bundle analysis
  • pnpm preview - Preview production build
  • pnpm lint - Run ESLint
  • pnpm lint:fix - Fix ESLint issues
  • pnpm type-check - Type check without emitting
  • pnpm clean - Clean build artifacts
  • pnpm deploy - Build and deploy to Cloudflare

🎨 Styling

The project uses Tailwind CSS v4 with:

  • Custom Component Classes: Defined in src/styles/index.css
  • Dark Mode: Full dark mode support with system preference detection
  • Responsive Design: Mobile-first approach with breakpoint utilities
  • Custom Animations: Smooth transitions for drawers, modals, and interactions
  • Icon System: Lucide React icons for consistent iconography
  • Theme Context: React Context API for theme management across the app

πŸ”’ Security

Headers (via _headers and functions/_middleware.ts)

  • X-Frame-Options: DENY (prevents clickjacking)
  • X-Content-Type-Options: nosniff (prevents MIME sniffing)
  • X-XSS-Protection: 1; mode=block (XSS protection)
  • Referrer-Policy: strict-origin-when-cross-origin
  • Permissions-Policy: Restricts geolocation, microphone, camera

Input Validation

  • Zod Schemas: All form inputs validated with Zod schemas
  • React Hook Form: Client-side validation with server-ready schemas
  • Type Safety: TypeScript ensures type safety at compile time

Caching Strategy

  • Static Assets: Long-term caching (1 year) with immutable flag
  • HTML: No-cache with must-revalidate for always-fresh content

πŸ“„ License

MIT

About

product management application built with React 19, React Router v7, Vite, and Tailwind CSS v4, optimized for Cloudflare Pages deployment.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages