System Architecture & Overview
HRS is built with modern web technologies following a client-server architecture with RESTful API communication. This page explores the system’s technical design and structure.Architecture Overview
High-Level Architecture
Frontend (Client)
React 18 Single Page Application
- TypeScript for type safety
- Vite for fast builds
- TailwindCSS for styling
- Radix UI components
Backend (API)
RESTful API Server
- Basic Authentication
- JSON data format
- CORS enabled
- Validation layer
State Management
Hybrid approach
- TanStack Query for server state
- React Context for auth state
- Session storage for credentials
Data Layer
Relational Database
- Students, Instructors, Horses
- Classes with relationships
- User accounts
Technology Stack
Frontend Technologies
Frompackage.json:1:
- Core Framework
- Build Tools
- Routing & State
- UI & Styling
React 18.3.1
- Modern React with Hooks
- Concurrent rendering
- Automatic batching
- Suspense support
- Strong typing throughout
- Interface definitions for all entities
- Type-safe API calls
- Enhanced IDE support
Key Libraries
Frompackage.json:45:
date-fns
Modern date utility library
- Date formatting and parsing
- Time calculations
- Locale support
- Lightweight and modular
ExcelJS
Professional Excel generation
- Advanced formatting
- Cell styling and colors
- Comments and formulas
- A4 print optimization
Recharts
Data visualization
- Bar charts for distributions
- Line charts for trends
- Pie charts for percentages
- Responsive and customizable
Zod
Schema validation
- Runtime type checking
- Form validation
- API response validation
- TypeScript integration
Application Structure
Project Organization
Routing Architecture
Fromsrc/App.tsx:30:
- Protected route wrapper for authentication
- Nested provider architecture
- Global notification systems (Toaster, Sonner)
- Idle timeout handler
- 404 catch-all route
API Architecture
RESTful API Design
Fromsrc/lib/api.ts:9:
API Endpoints
Error Handling
Fromsrc/lib/api.ts:157:
Authentication System
Basic Auth Implementation
Fromsrc/services/authService.ts:54:
User Model
Fromsrc/services/authService.ts:5:
Protected Routes
Fromsrc/components/auth/ProtectedRoute.tsx:
Idle Timeout
Fromsrc/components/auth/IdleHandler.tsx:
- 15-minute inactivity timeout
- Automatic logout
- Activity tracking (mouse, keyboard, touch)
- Warning before logout
State Management Strategy
Server State (TanStack Query)
- API data fetching
- Caching API responses
- Automatic refetching
- Optimistic updates
- Loading and error states
Client State (React Context)
Fromsrc/contexts/AuthProvider.tsx:
- Authentication state
- Current user information
- Login/logout actions
- Session management
Local Storage Strategy
Session Storage (temporary, cleared on tab close):authCredentials- Encoded Basic Authuser- Current user data (without password)
- Not used for sensitive data
- Could be used for user preferences
Data Model & Relationships
Entity Relationship Diagram
Type Definitions
Fromsrc/types/enums.ts:
Performance Optimizations
Code Splitting
- Route-based code splitting
- Lazy loading components
- Reduced initial bundle size
- Faster first paint
Query Caching
- TanStack Query automatic caching
- Stale-while-revalidate strategy
- Background refetching
- Reduced API calls
Build Optimization
- Vite’s optimized builds
- Tree shaking
- Minification
- Asset optimization
Responsive Design
- Mobile-first approach
- Responsive layouts
- Touch-friendly interfaces
- Adaptive components
Security Considerations
Deployment Architecture
- Minified JavaScript bundles
- Optimized CSS
- Asset hashing for cache busting
- Source maps for debugging
This architecture provides a solid foundation for a scalable, maintainable equestrian school management system with modern development practices and excellent user experience.