Giao diện
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ần | Giá trị |
|---|---|
| Two-stage segmented model | Giải quyết intermittent demand tốt |
| 40+ features engineering | Comprehensive, domain-specific |
| 5-layer workforce planner | Nghiệp vụ chi tiết, tuân thủ luật |
| AutoML self-improvement | Unique, LLM-powered |
| Config Registry | Centralized, DB-backed |
| 509+ tests | Coverage tốt cho frontend |
| i18n 3 ngôn ngữ | Production-ready |
| Event calendar | VN e-commerce domain knowledge |
⚠️ Điểm yếu (cần fix/refactor)
| Vấn đề | Impact | Effort |
|---|---|---|
| Frontend+Backend forecast logic trùng lặp | High | Large |
| Warehouse configs hardcoded | Medium | Small |
| Config mutation không thread-safe | High (concurrency) | Medium |
| Memory pressure cho large datasets | High (scale) | Medium |
| 5 bugs đã biết (BUG-01 → BUG-05) | Medium | Small |
| No API authentication | High (security) | Small |
| RLS chưa enable | Medium (security) | Small |
Option A: Incremental Refactor
Approach: Fix bugs → clean up → optimize → thêm features
Ưu tiên:
- Sprint 1 (1 tuần): Fix 5 bugs (BUG-01 → BUG-05)
- Sprint 2 (1 tuần): Move warehouse configs to DB (IMP-02)
- Sprint 3 (2 tuần): Thread-safe config (IMP-01) + feature caching (IMP-03)
- Sprint 4 (2 tuần): ML-primary forecast (IMP-08) → giảm trùng lặp frontend/backend
- 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 CacheEffort: ~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
- Bugs đã biết — Danh sách bugs cần fix
- Cải tiến đề xuất — Improvements
- Kiến trúc — Kiến trúc hiện tại
- Quyết định thiết kế — ADRs