Skip to content

Codebase Analysis

Quick Reference — Một trang tóm tắt toàn bộ project sau khi scan.

Hạng mụcGiá trị
TênBoxme Workforce Planner v2 (WFP MVP)
Stack chínhReact 18 + TypeScript + Vite + Tailwind + Supabase
State / DataZustand · TanStack Query · React Hook Form + Zod
UI primitivesRadix UI · lucide-react · Recharts
TestVitest (unit) · Playwright (E2E)
RoutingReact Router v6
DeployCloudflare Pages (prototype HTML) · Supabase (DB+Auth)
Ngôn ngữ giao diệnTiếng Việt

1. Cấu trúc thư mục

/Volumes/Data/Boxme/workforce/
├── index.html + js/              # Prototype HTML (deployed Cloudflare Pages)
├── wfp-v2/                       # MVP React app (production target)
│   ├── src/
│   │   ├── domain/               # Pure types (Zod schemas, entity contracts)
│   │   ├── engine/               # Pure compute (forecast, WLU) — KHÔNG side-effect
│   │   │   ├── forecast/         # historical-aggregator, generator
│   │   │   ├── wlu/              # calculator
│   │   │   └── cutoff.ts
│   │   ├── services/             # I/O layer (Supabase, xlsx, audit, review…)
│   │   ├── hooks/                # React Query hooks
│   │   ├── components/           # UI: layout, primitives, charts, review
│   │   ├── pages/                # Routes (planner/* admin/*)
│   │   ├── lib/                  # auth, scope, mock-store, env
│   │   └── router.tsx
│   ├── supabase/migrations/      # SQL schema
│   └── scripts/seed/             # Demo data seeders
├── architecture/                 # Contract docs (parallel-safety, TDD, boundaries)
├── openspec/changes/wfp-mvp/     # Active MVP plan (7 phase · 63 task)
├── HUONG-DAN-VAN-HANH.md         # Tài liệu vận hành non-tech hiện có
└── docs/                         # ← tài liệu mới (bạn đang đọc)

2. Module / Feature map

ModuleFile chínhTrách nhiệm
Authsrc/lib/auth.tsx, pages/Login.tsxSupabase auth, role guard
Scopesrc/lib/scope.tsxLưu warehouse + role hiện hành
Historical importservices/historicalImportService.ts, services/xlsxParser.ts, pages/admin/HistoryImport.tsxNhập 90 ngày đơn lịch sử (CSV/Excel/manual)
Adjustment intakeservices/adjustmentService.ts, pages/planner/SubmitAdjustment.tsxKAM gửi điều chỉnh forecast
Forecast engineengine/forecast/*, services/forecastService.tsTính baseline × monthly × event
WLU calculatorengine/wlu/calculator.tsQuy đổi đơn → workload minutes → headcount
Review & approveservices/reviewService.ts, pages/planner/ForecastReview.tsx, components/review/*Pipeline NEW → SEEN → ACCEPTED/REJECTED
Reportsservices/reportService.ts, pages/planner/ForecastWarehouse.tsx, CustomerDetail.tsxBáo cáo theo kho + khách
Configservices/configService.ts, pages/admin/{Config,NormsConfig,SeasonsConfig}.tsxTham số mùa, sự kiện, UPH
Audit logservices/auditService.ts, components/review/AuditTimeline.tsxInsert-only audit trail

3. Entry points & Routes

RouteTrangVai trò truy cập
/loginĐăng nhậpPublic
/Trang chủTất cả
/planner/forecastTổng quan dự báoPlanner, OPS, Admin, Auditor
/planner/forecast/reviewPhê duyệt yêu cầu KAMPlanner, OPS, Admin
/planner/forecast/customer · /:idForecast theo kháchPlanner, OPS, Admin, Auditor
/planner/forecast/warehouseBáo cáo khoPlanner, OPS, Admin, Auditor, WH Manager
/planner/override-importGửi điều chỉnh (KAM)KAM, Planner
/admin/history-importNhập dữ liệu lịch sửAdmin, OPS
/admin/warehousesQuản lý khoAdmin
/admin/config · /dinhmuc · /thamsoCấu hình tham sốAdmin

4. Forecast formula (cốt lõi)

forecast_qty(day) = round( baseline_avg(customer, warehouse, event_type)
                         × monthly_multiplier[month_of(day)]
                         × event_multiplier[event_type_of(day)] )

WLU/đơn (minutes)  = 60 / UPH_eff
UPH_eff            = harmonic_mean(UPH[group, pk_type], weight = product_mix)
total_workload_min = WLU × forecast_qty
headcount          = ceil(total_workload_min / shift_minutes)   # default 480

Tham chiếu: src/engine/forecast/generator.ts, src/engine/wlu/calculator.ts

5. Database (Supabase)

  • 10 bảng chính, mọi bảng có RLS, có created_at/updated_at/created_by
  • audit_log insert-only (revoke UPDATE/DELETE ở RLS)
  • Index chuẩn trên (warehouse_id, customer_id, date)
  • Schema chi tiết: xem Database

6. Dependencies (chọn lọc)

NhómPackageVì sao
Data@supabase/supabase-js, @tanstack/react-queryDB + cache
Formreact-hook-form, zod, @hookform/resolversForm + validation
UI@radix-ui/*, lucide-react, rechartsPrimitives & charts
FilesxlsxImport Excel/CSV
StatezustandLightweight stores

7. Test coverage (hiện trạng)

  • Unit (Vitest): tập trung engine/forecast/*engine/wlu/calculator.ts (pure functions)
  • E2E (Playwright): playwright.config.ts — placeholder cho smoke flow
  • Gate: npm run typecheck && npm test && npm run build PHẢI pass trước khi merge

8. Trạng thái MVP

7 phase · 63 task — xem openspec/changes/wfp-mvp/. Critical path 4 agent song song ~25 ngày làm việc.

9. Risks & gaps đã thấy

  • WLU calculator có một số function body còn rỗng (stub) — cần verify đã implement đủ cho MVP
  • Chưa có doc deployment cho phần React app (chỉ prototype HTML đang trên CF Pages)
  • audit_log cần test RLS revoke chặt chẽ
  • Demo seed snapshot phụ thuộc scripts/seed/demo-snapshot.ts — cần luôn cập nhật khi schema đổi

Xem tiếp Architecture · Database · Hướng dẫn kiểm thử MVP