refactor(file-manager): Modularize file management into domain-specific services
Summary
This MR refactors the File Manager service into domain-specific modules following Single Responsibility Principle. The agent-related file operations are now separated into dedicated controllers and services.
Motivation
- Maintainability: Single 700+ line controller was becoming difficult to maintain
- Scalability: Each domain can evolve independently
- Testability: Smaller, focused services are easier to unit test
- Security: Centralized reserved path validation
Changes
Architecture
| Before | After |
|---|---|
| 1 controller (700+ lines) | 5 focused controllers |
| 1 service interface | 5 domain-specific interfaces |
| Mixed responsibilities | Clear separation by domain |
New Components
-
Controllers:
AgentKnowledgeBaseController,AgentDocumentController,AgentAttachmentController,AgentWorkflowTemplateController - Services: Corresponding service interfaces and implementations
-
Helpers:
PathHelper,FileAccessLogHelper,ReservedPathValidator - Constants: 5 path constant classes organized by domain
API Endpoints Migration
| Old Endpoint | New Endpoint |
|---|---|
/api/file-manager/upload/general-agent-families-kb |
/api/file-manager/agent/knowledge-base/general/upload |
/api/file-manager/upload/specific-agent-family-kb |
/api/file-manager/agent/knowledge-base/specific/upload |
/api/file-manager/upload/specific-agent-knowledge-documents |
/api/file-manager/agent/documents/upload |
/api/file-manager/upload/agent-message-attachments |
/api/file-manager/agent/attachments/upload |
/api/file-manager/upload/main-n8n-workflow-template-agent-family |
/api/file-manager/agent/workflow-templates/main/upload |
/api/file-manager/upload/notification-n8n-workflow-template-agent-family |
/api/file-manager/agent/workflow-templates/notification/upload |
Error Handling
- Expanded
BusinessErrorCodefrom 5 to 50+ codes - Categorized by range: Workflows (001-060), Validation (061-100), Path (101-120), Upload (121-150), Download (151-170), etc.
Breaking Changes
Testing
-
Unit tests for new service implementations -
Integration tests for new endpoints -
Verify reserved path validation blocks unauthorized uploads -
Verify backward compatibility for core file operations
Checklist
-
Code follows project conventions -
Swagger documentation updated -
No hardcoded strings (using constants) -
Error codes standardized