Skip to content

Refactor Roadmap

MỤC TIÊU

Tài liệu này giúp developer quyết định nên tiếp tục code (incremental) hay viết lại (rewrite) hệ thống.

Đánh giá hiện trạng

✅ Điểm mạnh (giữ lại)

Thành phầnGiá trị
Two-stage segmented modelGiải quyết intermittent demand tốt
40+ features engineeringComprehensive, domain-specific
5-layer workforce plannerNghiệp vụ chi tiết, tuân thủ luật
AutoML self-improvementUnique, LLM-powered
Config RegistryCentralized, DB-backed
509+ testsCoverage tốt cho frontend
i18n 3 ngôn ngữProduction-ready
Event calendarVN e-commerce domain knowledge

⚠️ Điểm yếu (cần fix/refactor)

Vấn đềImpactEffort
Frontend+Backend forecast logic trùng lặpHighLarge
Warehouse configs hardcodedMediumSmall
Config mutation không thread-safeHigh (concurrency)Medium
Memory pressure cho large datasetsHigh (scale)Medium
5 bugs đã biết (BUG-01 → BUG-05)MediumSmall
No API authenticationHigh (security)Small
RLS chưa enableMedium (security)Small

Option A: Incremental Refactor

Approach: Fix bugs → clean up → optimize → thêm features

Ưu tiên:

  1. Sprint 1 (1 tuần): Fix 5 bugs (BUG-01 → BUG-05)
  2. Sprint 2 (1 tuần): Move warehouse configs to DB (IMP-02)
  3. Sprint 3 (2 tuần): Thread-safe config (IMP-01) + feature caching (IMP-03)
  4. Sprint 4 (2 tuần): ML-primary forecast (IMP-08) → giảm trùng lặp frontend/backend
  5. Sprint 5 (1 tuần): API auth + RLS policies

Effort: ~7 tuần
Risk: Low
Best when: Hệ thống đang hoạt động tốt, cần cải thiện dần

Option B: Partial Rewrite

Approach: Giữ ML engine (Python) + viết lại frontend

Scope:

  • Giữ: Python backend (model, features, pipeline, backtester, automl)
  • Viết lại: Frontend React → Next.js App Router hoặc Remix
    • Loại bỏ frontend forecast engine
    • ML-primary architecture
    • SSR/RSC cho performance
    • Proper auth (clerk/supabase-auth)

Effort: ~3-4 tháng
Risk: Medium
Best when: Muốn modernize frontend, scale team

Option C: Full Rewrite

Approach: Viết lại toàn bộ với kiến trúc mới

Kiến trúc mới đề xuất:

Next.js (App Router) → tRPC → Python ML API → Supabase

                    Redis Cache

Effort: ~6+ tháng
Risk: High
Best when: Hệ thống cần scale lớn, team mới

Khuyến nghị

KHUYẾN NGHỊ: Option A (Incremental Refactor)

Hệ thống đã có giá trị nghiệp vụ sâu (5-layer workforce, VN labor law, e-commerce calendar, 40+ features). Viết lại sẽ mất nhiều domain knowledge đã encode trong code. Fix bugs, optimize, rồi thêm features là approach hiệu quả nhất.

Tài liệu liên quan

BoxMe Forecast — Tài liệu kỹ thuật nội bộ