UI Abstraction Guidelines
This document outlines the three-level abstraction hierarchy for UI components in the Core package, designed to maximize code reusability while maintaining flexibility and developer efficiency.Overview
The UI abstraction follows a three-tier architecture:- Level 1: UI Components - Primitive building blocks (shadcn/ui or custom detail components)
- Level 2: Frontend Components - Reusable UI patterns with client-side logic
- Level 3: Backend-Controlled Components - Full-stack components with server-side integration
Level 1: UI Components (Primitive Building Blocks)
Purpose: Provide low-level, atomic UI elements that serve as the foundation for all higher-level components. Location:resources/js/core/components/ui/
Characteristics:
- Typically based on shadcn/ui
- Focus on visual presentation and basic interaction
Button, Input, Dialog, LoadingIcon, Card, Select
When to Create Level 1 Components
- New visual primitive not provided by shadcn/ui
- Small utility components (custom icons, loading states)
Level 2: Frontend Components (UI Pattern Wrappers)
Purpose: Encapsulate recurring UI patterns and frontend logic to reduce code duplication. Location:resources/js/core/components/
Characteristics:
- Compose multiple Level 1 components
- Contain client-side logic (state, validation, formatting)
- No direct backend communication (use callbacks)
Example: CoreConfirmDialog
CoreAvatar, DetailedLink, CoreSheet, CoreDialog
Implementation Pattern
Guidelines
- Compose Level 1 components
- Use callbacks for actions (no API calls)
- Handle loading/disabled states
- Strict TypeScript typing
- Accept className for customization
When to Create Level 2 Components
- Pattern appears multiple times across the application
- Standardizing a specific interaction
Level 3: Backend-Controlled Components (Full-Stack Components)
Purpose: Provide integrated frontend-backend solutions for complex features requiring server-side data management. Location:- Backend:
src/Tables/,src/Forms/ - Frontend:
resources/js/core/components/
- Consistent backend-frontend contract for data and actions
- Efficient server-side data preparation and validation
- Standardized UI patterns for complex features
Example: CoreTable (InertiaTable)
Backend:Guidelines
- Backend handles data fetching, validation, authorization
- Use TypeScript generation for backend types
- Validation in Form Requests (never inline)
- Use deferred props for expensive operations
When to Create Level 3 Components
- Server-side filtering, sorting, or pagination needed
- Data requires authorization or validation
- Multiple round-trips between client and server
Decision Tree
Best Practices
Naming Conventions
- Level 1: shadcn/ui names or single-word names (
Button,LoadingIcon) - Level 2:
Coreprefix (CoreAvatar,CoreConfirmDialog) - Level 3: Domain-specific or
Coreprefix (CoreTable,CoreForm)
Component Composition
Always prefer composition over duplication:Progressive Enhancement
- First use: Write inline code
- Second use: Extract to local component
- Third use: Consider Level 2 abstraction
- Frequent use + backend: Consider Level 3 abstraction
Summary
- Level 1: Building blocks (Button, Input, Dialog)
- Level 2: UI patterns (CoreConfirmDialog, DetailedLink)
- Level 3: Full-stack features (CoreTable, CoreForm)