Tech Stack
The SnackBase admin UI is built with modern, production-ready technologies:| Technology | Version | Purpose |
|---|---|---|
| React | 19.2.0 | UI framework |
| TypeScript | 5.9.3 | Type safety |
| Vite | 7.2.4 | Build tool and dev server |
| React Router | 7.11.0 | Client-side routing |
| TailwindCSS | 4.1.18 | Utility-first styling |
| Radix UI | Latest | Accessible component primitives |
| ShadCN | Latest | Pre-built component library |
| TanStack Query | 5.90.12 | Server state management |
| Zustand | 5.0.9 | Client state management |
| Zod | 4.2.1 | Schema validation |
| Axios | 1.13.2 | HTTP client |
| React Hook Form | 7.69.0 | Form state management |
Project Structure
Architecture Overview
The frontend follows a layered architecture with clear separation of concerns:State Management
Global State: Zustand
Authentication state is managed insrc/stores/auth.store.ts:
- Token stored in localStorage with key
auth-storage - Persist middleware for session persistence
restoreSession()verifies token validity on app load- Automatic logout on 401 responses
Server State: TanStack Query
All data from the API is managed by TanStack Query:API Service Layer
All services follow a consistent pattern insrc/services/:
Axios Configuration
Thelib/api.ts file configures the Axios instance:
Authentication Flow
Login Flow
Protected Routes
TheProtectedRoute component wraps routes that require authentication:
Usage in App.tsx
All admin routes are under the/admin prefix:
Components & Patterns
ShadCN Components
ShadCN provides pre-built, accessible components. Never edit ShadCN components directly insrc/components/ui/.
To add new ShadCN components:
Component Composition Pattern
Build complex components by composing ShadCN primitives:Dialog-Based CRUD Operations
Most CRUD operations use ShadCN Dialog components:Routing
All routes are under the/admin prefix:
Styling
SnackBase uses TailwindCSS 4 with the new@tailwindcss/vite plugin.
Theme Configuration
Theme is configured insrc/App.css:
Common Patterns
| Pattern | Classes | Usage |
|---|---|---|
| Card | bg-white rounded-lg shadow-sm border p-6 | Container for content |
| Button Group | flex gap-2 | Horizontal button layout |
| Grid | grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 | Responsive grid |
| Section Spacing | space-y-4 | Vertical spacing |
Development Workflow
Environment Setup
Create a.env file in the ui directory:
Running the Dev Server
http://localhost:5173 with:
- Hot Module Replacement (HMR)
- Fast refresh
- TypeScript checking
Build for Production
Best Practices
1. Component Organization
- Keep components focused and single-purpose
- Extract reusable logic into custom hooks
- Co-locate related components in feature folders
2. Type Safety
- Always define TypeScript interfaces for API responses
- Use Zod schemas for runtime validation
- Avoid
anytype - useunknownif truly unknown
3. Error Handling
- Always handle loading and error states from TanStack Query
- Show user-friendly error messages
- Use the
handleApiError()utility fromlib/api.ts
4. Performance
- Use TanStack Query’s caching to avoid redundant requests
- Implement pagination for large datasets
- Lazy load components with React.lazy()