mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-20 07:00:09 +08:00
| .. | ||
| api | ||
| cache | ||
| preference | ||
| README.md | ||
Cherry Studio Shared Data
This directory contains shared type definitions and schemas for the Cherry Studio data management systems. These files provide type safety and consistency across the entire application.
📁 Directory Structure
packages/shared/data/
├── api/ # Data API type system
│ ├── index.ts # Barrel exports for clean imports
│ ├── apiSchemas.ts # API endpoint definitions and mappings
│ ├── apiTypes.ts # Core request/response infrastructure types
│ ├── apiModels.ts # Business entity types and DTOs
│ ├── apiPaths.ts # API path definitions and utilities
│ └── errorCodes.ts # Standardized error handling
├── cache/ # Cache system type definitions
│ ├── cacheTypes.ts # Core cache infrastructure types
│ ├── cacheSchemas.ts # Cache key schemas and type mappings
│ └── cacheValueTypes.ts # Cache value type definitions
├── preference/ # Preference system type definitions
│ ├── preferenceTypes.ts # Core preference system types
│ └── preferenceSchemas.ts # Preference schemas and default values
└── README.md # This file
🏗️ System Overview
This directory provides type definitions for three main data management systems:
API System (api/)
- Purpose: Type-safe IPC communication between Main and Renderer processes
- Features: RESTful patterns, error handling, business entity definitions
- Usage: Ensures type safety for all data API operations
Cache System (cache/)
- Purpose: Type definitions for three-layer caching architecture
- Features: Memory/shared/persist cache schemas, TTL support, hook integration
- Usage: Type-safe caching operations across the application
Preference System (preference/)
- Purpose: User configuration and settings management
- Features: 158 configuration items, default values, nested key support
- Usage: Type-safe preference access and synchronization
📋 File Categories
Framework Infrastructure - These are TypeScript type definitions that:
- ✅ Exist only at compile time
- ✅ Provide type safety and IntelliSense support
- ✅ Define contracts between application layers
- ✅ Enable static analysis and error detection
📖 Usage Examples
API Types
// Import API types
import type { DataRequest, DataResponse, ApiSchemas } from '@shared/data/api'
Cache Types
// Import cache types
import type { UseCacheKey, UseSharedCacheKey } from '@shared/data/cache'
Preference Types
// Import preference types
import type { PreferenceKeyType, PreferenceDefaultScopeType } from '@shared/data/preference'
🔧 Development Guidelines
Adding Cache Types
- Add cache key to
cache/cacheSchemas.ts - Define value type in
cache/cacheValueTypes.ts - Update type mappings for type safety
Adding Preference Types
- Add preference key to
preference/preferenceSchemas.ts - Define default value and type
- Preference system automatically picks up new keys
Adding API Types
- Define business entities in
api/apiModels.ts - Add endpoint definitions to
api/apiSchemas.ts - Export types from
api/index.ts
Best Practices
- Use
import typefor type-only imports - Follow existing naming conventions
- Document complex types with JSDoc
- Maintain type safety across all imports
🔗 Related Implementation
Main Process Services
src/main/data/CacheService.ts- Main process cache managementsrc/main/data/PreferenceService.ts- Preference management servicesrc/main/data/DataApiService.ts- Data API coordination service
Renderer Process Services
src/renderer/src/data/CacheService.ts- Renderer cache servicesrc/renderer/src/data/PreferenceService.ts- Renderer preference servicesrc/renderer/src/data/DataApiService.ts- Renderer API client