Overview
MotorDesk uses a component-driven architecture with React and TypeScript. Components are organized by feature domain and follow consistent patterns for styling, props, and composition.Component Organization
Components are organized into two main categories:UI Components
Reusable, presentational components in
src/components/ui/These are low-level, generic components used throughout the application.Feature Components
Domain-specific components organized by featureHigher-level components for specific business domains like customers, vehicles, products.
UI Components
Thesrc/components/ui/ directory contains foundational, reusable components:
Button Component
A versatile button component with multiple variants and states. Location:src/components/ui/Button.tsx
Primary
variant="primary"Blue background, main call-to-action buttonsSecondary
variant="secondary"Light gray, secondary actionsSuccess
variant="success"Green, confirmation/save actionsDanger
variant="danger"Red, destructive actionsGhost
variant="ghost"Transparent, subtle actionsOutline
variant="outline"Bordered, alternative secondary styleInput Component
A controlled text input with consistent styling across the application. Location:src/components/ui/Input.tsx
- Uses
forwardReffor ref forwarding (required for form libraries) - Consistent height (38px) across all inputs
- Automatic background color for readonly states
- Focus ring for accessibility
- Disabled state styling
FormField Component
A wrapper component that combines labels with form inputs. Location:src/components/ui/FormField.tsx
- Consistent label styling across forms
- Automatic spacing between label and input
- Accessible label association
- Composable with any form control
Feature Components
Feature components are organized by business domain:Component Structure by Domain
Customer Components
Customer Components
- FormModal: Add and edit operations
- DetailsModal: Read-only view
- DeleteModal: Confirmation dialog
Vehicle Components
Vehicle Components
- License plate entry
- Owner/driver assignment
- Vehicle type selection
- Usage tracking
Product Components
Product Components
- Product information
- Pricing
- SUNAT codes
- Inventory tracking
Sales Components
Sales Components
- Invoice creation
- Payment processing
- Document generation
Layout Components
Layout Components
Authentication Components
Authentication Components
MainLayout Component
The main application layout with sidebar navigation and top bar. Location:src/components/layout/MainLayout.tsx
Key Features:
- Sidebar navigation with icons
- Branch/location selector
- User profile display
- Logout functionality
- Nested routing with
<Outlet />
Home- DashboardTruck- VehiclesPackage- ProductsUsers- CustomersFileText- Sales/InvoicesBarChart3- ReportsSettings- ConfigurationLogOut- Logout
Component Patterns
Modal Pattern
All modals follow a consistent pattern:Controlled Component Pattern
All form inputs are controlled components:Composition Pattern
Components compose smaller components:Styling Approach
MotorDesk uses a hybrid styling approach:TailwindCSS Utility Classes
TailwindCSS Utility Classes
Primary styling method using Tailwind’s utility classes:Benefits:
- Rapid development
- Consistent design system
- Small bundle size (purged unused classes)
CSS Modules
CSS Modules
Used for complex layouts and component-scoped styles:Benefits:
- Scoped styles (no naming conflicts)
- Better for complex layouts
- CSS features (animations, media queries)
Combining Approaches
Combining Approaches
You can combine both methods:
Icons
The project uses Lucide React for icons:Plus- Add actionsEdit/Pencil- Edit actionsTrash- Delete actionsSearch- Search functionalityX- Close/cancelCheck- Confirm/successAlertCircle- Warnings/errorsLoader2- Loading states (animated)
Accessibility
Components follow accessibility best practices:Best Practices
Component Size
Keep components small and focused. If a component exceeds 200 lines, consider splitting it.
Props Interface
Always define TypeScript interfaces for props. Extend HTML attributes when possible.
Default Props
Use default parameters instead of
defaultProps:Ref Forwarding
Use
forwardRef for form components to support refs.Memoization
Use
React.memo for expensive components that receive stable props.Key Props
Always provide stable keys in lists:
Testing Components
When testing components, focus on:- User interactions: Clicks, typing, form submission
- Rendering: Does it render with correct props?
- Accessibility: Keyboard navigation, screen readers
- Edge cases: Empty states, loading states, errors
Next Steps
- Learn about Custom Hooks that power these components
- Review Project Structure for file organization
- Explore the API Reference for detailed component APIs
