6.3 KiB
Task B.1 – Foundation Stabilization & Production Isolation
Context
Task B Foundation Layer เสร็จแล้ว
ปัจจุบันระบบมี:
- Organization Context
- Membership Context
- Permission Layer
- Branch Scope
- Master Options
- Document Sequence
- Audit Log Helper
เป้าหมายของ Task B.1 คือทำให้ Foundation พร้อมใช้งานจริงก่อนเริ่ม Task C (Customer + Contact)
สิ่งที่ต้องอ่านก่อน
อ่านและยึดตาม:
docs/implementation/task-a-template-audit.md
docs/implementation/task-b-template-audit.md
Layout.md
AGENTS.md
.agents/skills/kiranism-shadcn-dashboard
src/auth.ts
src/lib/auth/**
src/db/schema.ts
src/features/products/**
src/features/users/**
ใช้ products และ users เป็น production reference
เป้าหมาย
ทำ 2 เรื่องหลัก:
- Foundation Stabilization
- Production Isolation
โดยยังไม่เริ่ม Customer Module
Part A: Foundation Stabilization
A.1 Review Foundation Tables
ตรวจสอบ schema ใหม่ที่เพิ่มจาก Task B
msOptions
documentSequences
trAuditLogs
ตรวจสอบ:
- unique constraint
- indexes
- foreign keys
- organizationId consistency
- soft delete support
หากพบจุดที่ควรปรับปรุง
ให้เขียนเป็น Migration Note
ห้ามแก้ schema โดยไม่จำเป็น
A.2 Create Foundation Seed
สร้าง seed script
ตัวอย่าง path:
src/db/seeds/foundation.seed.ts
Seed เฉพาะ foundation data
crm_branch
สำนักงานใหญ่
Factory
Service
crm_customer_status
active
inactive
suspended
crm_customer_type
company
individual
crm_enquiry_status
new
qualifying
requirement
follow_up
converted
closed_lost
cancelled
crm_quotation_status
draft
pending_approval
approved
rejected
sent
accepted
lost
cancelled
revised
crm_product_type
crane
dockdoor
solarcell
crm_currency
THB
USD
EUR
crm_payment_term
cash
credit_30
credit_60
crm_priority
low
normal
high
urgent
crm_lead_channel
website
referral
sales
facebook
line
other
A.3 Seed Document Sequences
Seed initial document types
customer
contact
enquiry
quotation
approval
Mapping
CUS
CON
ENQ
QT
APV
Requirements:
- idempotent
- run ซ้ำได้
- ไม่สร้างข้อมูลซ้ำ
- ใช้ organizationId จาก database
- ห้าม hardcode organizationId
หากไม่พบ organization
ให้ throw error พร้อมข้อความชัดเจน
A.4 Verify Foundation Services
ตรวจสอบ service ที่สร้างใน Task B
auth-context
organization-context
permission
branch-scope
master-options
document-sequence
audit-log
ตรวจสอบ:
- naming consistency
- return type consistency
- error handling
- organization-first design
หากพบปัญหา
ให้แก้เฉพาะ foundation layer
Part B: Production Isolation
เป้าหมาย
แยก legacy CRM mock ออกจาก production path
เพื่อให้ Task C เริ่มบน production architecture เท่านั้น
B.1 Audit Existing CRM Module
ตรวจสอบ
src/features/crm/**
src/app/dashboard/crm/**
จำแนกเป็น:
Production-ready
ใช้ต่อได้
Legacy Mock
ยังใช้
- mock data
- in-memory state
- placeholder service
- fake API
B.2 Move Mock Out of Production Path
ห้ามลบไฟล์
ให้ย้ายไป:
src/features/crm-mock/**
หรือ
src/features/crm-demo/**
แล้วแต่ convention ที่เหมาะกับโปรเจ็ค
B.3 Route Isolation
Production route:
/dashboard/crm
Mock route:
/dashboard/crm-demo
Requirements:
- ห้าม production route import mock service
- ห้าม production route import mock API
- ห้าม production component พึ่ง mock state
B.4 Import Audit
ตรวจสอบ import ทั้งระบบ
ค้นหา:
mock-api
mock-api-users
crm mock service
fake data
in-memory store
ถ้ายังถูก import ใน production path
ให้แก้
B.5 Compile Error Cleanup
แก้เฉพาะ:
type errors
missing imports
unused exports
broken references
ห้าม:
- เปลี่ยน business flow
- rewrite CRM module
- เริ่ม Customer production
Deliverables
สร้างเอกสาร
docs/implementation/task-b1-foundation-stabilization.md
ต้องมี:
Foundation Review
- schema review
- seed review
- service review
Production Isolation Review
- production modules
- demo modules
- route separation
Risks
- remaining mock dependencies
- migration concerns
Task C Readiness
ห้ามทำ
Customer CRUD
Contact CRUD
Enquiry CRUD
Quotation CRUD
Approval Workflow
Dashboard KPI
PDF Generator
Reporting
Notification
ห้ามรัน
npm run build
npm run lint
npm run test
pnpm build
pnpm lint
pnpm test
จนกว่าจะได้รับคำสั่ง
Output ที่ต้องการ
หลังทำเสร็จให้สรุป:
- Files Added
- Files Modified
- Seed Scripts Added
- Mock Modules Moved
- Production Routes Verified
- Remaining Risks
- Task C Readiness
Definition of Done
✔ Foundation tables reviewed
✔ Foundation seed script created
✔ Document sequence seed created
✔ Foundation services reviewed
✔ Mock CRM isolated from production path
✔ Production route no longer depends on mock services
✔ Compile issues related to isolation fixed
✔ Task C can begin safely
✔ No Customer module created
✔ No Quotation module created