Core Architecture
Refine’s architecture is composed of several key layers:Component Hierarchy
The<Refine> component is the root of your application and initializes all provider contexts:
<Refine> component creates a nested context provider structure:
This nested structure ensures that all Refine hooks have access to the necessary contexts throughout your application.
Provider System
Providers are the core abstraction in Refine. Each provider implements a specific interface that Refine uses to interact with external services:Provider Types
| Provider | Purpose | Required |
|---|---|---|
| Data Provider | CRUD operations and API communication | Yes |
| Auth Provider | Authentication and authorization | No |
| Router Provider | Routing and navigation | No |
| Access Control Provider | Permission-based access control | No |
| Notification Provider | User notifications | No |
| i18n Provider | Internationalization | No |
| Live Provider | Real-time updates | No |
| Audit Log Provider | Change tracking and logging | No |
Only the Data Provider is required. All other providers are optional and add specific capabilities to your application.
React Query Integration
Refine leverages TanStack Query (React Query) for all data management:- Query management: All data fetching hooks (
useList,useOne, etc.) return React Query results - Caching: Automatic caching with intelligent cache key generation
- Optimistic updates: Built-in support for optimistic UI updates
- Background refetching: Automatic data synchronization
- Invalidation: Smart query invalidation on mutations
Hooks Layer
Refine provides a comprehensive set of hooks that abstract common operations:Data Hooks
useList- Fetch lists with pagination, filtering, sortinguseOne- Fetch single recordsuseCreate- Create new recordsuseUpdate- Update existing recordsuseDelete- Delete recordsuseCustom- Custom API calls
Auth Hooks
useLogin- Handle loginuseLogout- Handle logoutuseIsAuthenticated- Check authentication statususeGetIdentity- Get current user identityusePermissions- Get user permissions
UI Hooks
useTable- Table state managementuseForm- Form state managementuseModal- Modal state managementuseDrawer- Drawer state management
Navigation Hooks
useGo- Programmatic navigationuseBack- Navigate backuseParsed- Parse current routeuseResource- Get current resource
Mutation Modes
Refine supports three mutation modes that affect how UI updates are handled:Pessimistic (Default)
Waits for the server response before updating the UI:Optimistic
Updates UI immediately, rolls back on error:Undoable
Updates UI immediately with undo option:Resource System
Resources represent the entities in your application (posts, users, products, etc.). They define:- Name: Identifier used in API calls
- Routes: Paths for list, create, edit, show pages
- Meta: Additional configuration (labels, icons, permissions, etc.)
Type Safety
Refine is built with TypeScript and provides full type inference:Extension Points
Refine is designed to be extended:- Custom Providers: Implement provider interfaces for any backend
- Custom Hooks: Build on top of Refine’s primitives
- Meta Fields: Pass custom data through the meta object
- Custom Queries: Use
useCustomfor non-CRUD operations
Next Steps
Providers
Learn about the provider system in detail
Resources
Understand how resources work
Data Fetching
Deep dive into data management
Routing
Explore the routing system