Problem
src/backend/services/system_service.py (713 lines) contains the two highest-complexity functions in the codebase:
| Function |
CC |
Lines |
export_manifest |
39 |
~190 |
validate_manifest |
35 |
~165 |
configure_permissions |
23 |
~100 |
These functions have deeply nested conditionals for manifest field handling.
Proposed Solution
-
Extract validation rules into a ManifestValidator class with focused methods:
validate_agents(), validate_credentials(), validate_permissions()
- Each validates one section of the manifest
-
Extract export logic into composable exporters:
export_agent() — single agent to manifest dict
export_permissions() — permission matrix
export_credentials() — credential mapping
-
Extract configure_permissions into services/permission_service.py
Requires Tests First
These functions have no dedicated unit tests. Add tests before refactoring:
- Manifest with all fields populated
- Manifest with minimal fields
- Invalid manifest structures
- Permission configuration edge cases
Acceptance Criteria
Source
Refactor audit 2026-03-13
Problem
src/backend/services/system_service.py(713 lines) contains the two highest-complexity functions in the codebase:export_manifestvalidate_manifestconfigure_permissionsThese functions have deeply nested conditionals for manifest field handling.
Proposed Solution
Extract validation rules into a
ManifestValidatorclass with focused methods:validate_agents(),validate_credentials(),validate_permissions()Extract export logic into composable exporters:
export_agent()— single agent to manifest dictexport_permissions()— permission matrixexport_credentials()— credential mappingExtract
configure_permissionsintoservices/permission_service.pyRequires Tests First
These functions have no dedicated unit tests. Add tests before refactoring:
Acceptance Criteria
export_manifestCC < 15validate_manifestCC < 15configure_permissionsCC < 15system_service.py< 400 linesSource
Refactor audit 2026-03-13