# think-extends **Repository Path**: topextend/think-extends ## Basic Information - **Project Name**: think-extends - **Description**: No description available - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-06 - **Last Updated**: 2025-04-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ThinkPHP Hierarchical Architecture Extension Enterprise-grade hierarchical architecture solution for ThinkPHP 6.x/8.x ## 🎯 Project Overview This extension provides a complete hierarchical architecture implementation for ThinkPHP, including the following core components: - **Controller Layer**: Handles HTTP requests and responses, provides standardized output format - **Service Layer**: Encapsulates core business logic, handles transactions and workflows - **Repository Layer**: Data access abstraction layer, provides unified data operation interface - **Model Layer**: Data entity definition, includes basic CRUD operations - **Middleware**: Handles cross-cutting concerns like authentication, logging etc. ## 🏗️ Architecture Advantages 1. **Separation of Concerns**: Clear responsibilities for each layer, avoiding code coupling 2. **Testability**: Each layer can be tested independently, facilitating unit testing 3. **Maintainability**: Business changes only require modifying corresponding layer code 4. **Extensibility**: New features can be added without affecting existing architecture ## 🛠️ Core Features ### Controller Layer Features - Standardized JSON response format - Automatic exception catching and handling - Request parameter auto-validation - User identity auto-injection - Operation log auto-recording ### Service Layer Features - Distributed transaction management - Business operation logging - Data validation and transformation - Business process orchestration - Third-party service integration ### Repository Layer Features - Pagination query encapsulation - Query result caching - Batch operation support - Data access abstraction - Multiple data source support ### Model Layer Features - Automatic timestamp maintenance - Soft delete support - Field type conversion - Data permission control - Safe field filtering ## 📚 Usage Guide ### Installation ```bash composer require topextend/think-extend ``` # Architecture Flow HTTP Request → Middleware → Controller → Service → Repository → Model ### Architecture Diagram graph TD A[HTTP Request] --> B[Middleware] B --> C[Controller] C --> D[Service] D --> E[Repository] E --> F[Model] ### Feature Matrix Layer Key Features Example Methods Controller Standardized responses, Exception handling success(), fail() Service Transaction management, Data validation transaction(), log() Repository Pagination, Caching paginate(), withCache() Model Timestamps, Soft deletes safeUpdate(), scopeStatus() ## 📝 Code Examples ### Controller Example ```php use think\admin\Controller; class User extends Controller { public function index() { $data = $this->request->post(); $result = $this->serviceUser->getUserList($data); return $result ? $this->success($result) : $this->error('Failed to get user list'); } } ``` ### Service Example ```php use think\admin\Service; class User extends Service { public function getUserList($data) { return $this->repositoryUser->getUserList($data); } } ``` ### Repository Example ```php use think\admin\Repository; class User extends Repository { public function getUserList($data) { return $this->modelUser->where('status', 1)->paginate(); } } ``` ### Model Example ```php use think\admin\Model; class User extends Model { public function scopeStatus($query, $status) { return $query->where('status', $status); } } ``` ## 📈 Performance Tips 1. Use repository caching appropriately 2. Avoid calling service methods in loops 3. Prefer model batch methods for bulk operations 4. Optimize complex queries using query builder ## 🤝 Contribution Guide Welcome to submit Pull Requests or Issues for feedback