🧹 F70 — Dead Code Cleanup (FE+BE)

Gate 1 Artifact — Discovery Report & Dead Code Map | Baseline: v20.12.2 | 2026-05-15

Discovery ✓ → Gate 1 → Gate 2 F1/Plan → B4B → Risk → Implement → Gate 3 → Gate 4 → Gate 5

📊 Codebase Summary

FE Files
85
57 JS + 27 TPL + 1 JSON
FE Code LOC
~14,000
report-studio / report-viewer / dashboard
BE Files
79
17 PHP + 32 JSON + 29 DUPLICATE + 1 MD
BE Code LOC
~7,000
Controllers / Services / Tools / ORM
Dead Files (confirmed)
29+
29 duplicate + 2 unused classes + debug
Est. Dead LOC
~3,200+
~15% of total BE codebase

Zone 1 — BE Duplicate Directory

Toàn bộ HybReport/HybReport/ là nested duplicate. EspoCRM autoload từ custom/Espo/Modules/HybReport/ — nested dir không bao giờ được load.

Nested Path (DEAD)Real Path (ACTIVE)StatusEvidence
HybReport/Controllers/CReportDashboard.phpControllers/CReportDashboard.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Controllers/CReportWidget.phpControllers/CReportWidget.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Services/CReportDashboard.phpServices/CReportDashboard.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Services/CReportWidget.phpServices/CReportWidget.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Hooks/CReportDashboard/SyncToWidgets.phpHooks/CReportDashboard/SyncToWidgets.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Hooks/CReportWidget/ClearMeasureField.phpHooks/CReportWidget/ClearMeasureField.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/ORM/.../CountDistinct.phpORM/.../CountDistinct.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/ORM/.../Distinct.phpORM/.../Distinct.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Acl/CReportWidget.phpAcl/CReportWidget.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Helpers/MatrixTemplateHelper.phpHelpers/MatrixTemplateHelper.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Tools/Report/DateRange.phpTools/Report/DateRange.phpIdenticalSame namespace, wrong PSR-4 path
HybReport/Tools/Report/MatrixQueryBuilder.phpTools/Report/MatrixQueryBuilder.phpSTALE (older)Differs from parent — outdated version
HybReport/Tools/Report/PayloadParser.phpTools/Report/PayloadParser.phpSTALE (older)Differs from parent — outdated version
+ 16 JSON files (metadata, i18n, layouts) — all duplicates of Resources/

Zone 2 — BE Unused Code (Parent Dir)

FileIssueRiskEvidence
Tools/Report/DateRange.phpUnused classLowImported in Controller but never instantiated (0 hits for new DateRange / DateRange::)
Hooks/CReportWidget/ClearMeasureField.phpUnregistered hookLowNot in hooks.json; references non-existent entity fields (aggregateFunction, measureField, etc.)
Services/CReportWidget.php:109-114Debug code left inLow_f58Debug block with explicit TODO F58: Xóa block này
Controllers/CReportDashboard.phpUnused importLowuse DateRange — never referenced in body
Services/CReportDashboard.phpUnused importLowuse MatrixQueryBuilder — never referenced in body
Services/CReportWidget.phpUnused imports ×2Lowuse EntityManager, use Metadata — inherited, not direct
Tools/Report/PayloadParser.phpDead private methodLowparseReverseJoinLink() — defined but never called

Zone 3 — FE Dead Code (Cần scan sâu)

FE dùng AMD dynamic define() / require() — cần cross-reference kỹ hơn. Các suspect:

Suspect AreaReasonRiskAction
src/views/shared/renderers/ vs src/views/report-viewer/helpers/renderers/Possible overlap/migration remnantMediumCross-ref imports
Unused TPL filesTemplates not referenced by any viewMediumGrep template property in all .js
Unused helper JSHelpers not imported anywhereMediumGrep require/define deps
Commented blocks >5 linesLegacy code left behindLowRegex scan

📋 Proposed Phase Plan

PhaseScopeRiskEst. LOC RemovedVerify
P1Xóa toàn bộ HybReport/HybReport/ nested dirRất thấp~3,000Clear cache + full test
P2Xóa dead PHP: DateRange, ClearMeasureField, debug block, unused imports, dead methodThấp~200Clear cache + API test
P3FE deep scan + cleanup (shared renderers overlap, unused TPL/JS)Trung bìnhTBDBrowser test all views

🛡️ Safety Protocol