ภาพรวมระบบ (System Overview)
หน้านี้สรุปภาพรวมฝั่ง Admin จาก route, menu, guard, permission, และ data source ที่พบในโค้ดจริงของ atp30-tos-frontend
โครงสร้างการทำงานหลัก
Shell และ Route Layer
Login Layer
- route เริ่มต้นอยู่ใน
LoginRoutes - ใช้
GuestGuardเพื่อกันผู้ใช้ที่ login แล้วไม่ให้ย้อนกลับมาหน้า login - ใช้
MinimalLayoutสำหรับหน้า authentication และหน้า maintenance
Application Layer
- route หลักของระบบอยู่ภายใต้
MainRoutes MainRoutesใช้AuthGuardครอบMainLayout- route รายโมดูลถูกแยกเป็นไฟล์ route ตามโดเมนของงาน เช่น customer, vehicle, trip-record, invoice, report
- route ทั้งก้อนถูกครอบด้วย
ErrorBoundaryในsrc/routes/index.tsx
กลุ่มเมนูหลักที่มีจริง
เมนูฝั่ง Admin ไม่ได้ถูกประกาศรวมใน route file แต่ถูกประกอบจาก menu-items แยกตามกลุ่มงาน
| กลุ่มเมนู | ไฟล์ config | เมนูย่อยหลัก |
|---|---|---|
Operations | src/menu-items/dashboard.ts | Dashboard, Oil Price, Trip Record, Trip History, Refuel, Vehicle Record, Standby, Histories |
Billing | src/menu-items/billing.ts | Customer Invoice, Contract Invoice, Driver Income |
Reports | src/menu-items/reports.ts | Income Report, Trip Report, Contract Invoice Report, Y-Ratio Report |
Setting | src/menu-items/settings.ts | Customers, Vehicles, Users, System Settings, Logout |
Permission ที่มีผลกับการมองเห็นเมนู
- เมนูแต่ละ item มี
permissionกำกับในmenu-items/*.ts - widget บางส่วนในหน้า dashboard ใช้
Authorizeซ่อน/แสดง component ตาม permission - card ระดับหน้าใช้
MainCard permission={...}ในบางหน้า - สรุปคือ route มีได้ แต่ผู้ใช้จะไม่เห็นเมนูหรือเนื้อหาบางส่วนถ้าไม่มี permission ตรงตามที่กำหนด
Route Matrix ที่ต้องเข้าใจ
| กลุ่ม | route สำคัญ | บทบาทของหน้า |
|---|---|---|
| Dashboard | /, /home | สรุป KPI และตัวเลขรวม |
| Customer | /customers, /customers/add, /customers/view/:id | จัดการข้อมูลลูกค้า |
| Contract | /customers/:customerId/contracts/create, /customers/:customerId/contracts/:contractId, /customers/:customerId/contracts/:contractId/edit | สร้าง ดู และแก้ไขสัญญา |
| Vehicles | /vehicles, /vehicles/add, /vehicles/edit/:id, /vehicles/view/:id | จัดการรถบริการ |
| Users | /users, /users/create, /users/edit/:id, /users/view/:id | จัดการผู้ใช้งาน |
| Operations | /oil-price, /trip-record, /trip-history, /refuel, /vehicle-record, /standby-task, /histories | ปฏิบัติการและข้อมูลภาคสนาม |
| Setting | /customers, /vehicles, /users, /areas, /contract-bus-companies, /vehicle-types, /roles, /fuel-cards, /holidays | ข้อมูลหลักและค่าตั้งต้นของระบบ |
| Billing | /customer-invoice, /contract-invoice, /driver-income | ตรวจและออกเอกสารการเงิน |
| Reports | /income-report, /trip-report, /contract-invoice-report, /y-ratio-report | รายงานเพื่อวิเคราะห์และ export |
Data Flow ที่สำคัญ
Master Data ไปสู่ Contract
- ข้อมูลลูกค้า, รถ, ประเภทรถ, ผู้ใช้งาน, พื้นที่ และบริษัทรถร่วม เป็นฐานของการสร้างสัญญา
- หน้า contract ถูกเปิดจาก route ภายใต้
customers/:customerId/...
Operations ไปสู่ Billing
- ข้อมูลเที่ยวรถ, งาน standby, refuel, และสมุดประจำรถ เป็นข้อมูลต้นทางที่ส่งผลต่อการคำนวณ
- ฝั่ง UI ของ billing ใช้ข้อมูลที่ backend สรุปมาแล้ว ไม่ได้คำนวณจาก form หน้าเดียว
Billing ไปสู่ Dashboard และ Reports
- Dashboard ใช้ข้อมูลสรุปจาก endpoint
/dashboard/ - Reports ใช้ route แยกของตนเอง เช่น
trip-report,income-report,contract-invoice-report,y-ratio-report
สิ่งที่ต้องจำจาก implementation
/homeกับ/ไปหน้าเดียวกันคือHomePageMainLayoutคือ shell หลักของระบบหลังผ่าน authenticationDashboardอยู่ภายใต้กลุ่มOperationsใน menu config จริง- หน้า contract ไม่ได้อยู่ใน menu หลัก แต่ถูกเข้าถึงจาก flow ของลูกค้า
- การมองเห็นเมนูและ widget ขึ้นอยู่กับ permission ไม่ใช่แค่มี route อย่างเดียว
อ้างอิงโค้ด
atp30-tos-frontend/src/routes/index.tsxatp30-tos-frontend/src/routes/LoginRoutes.tsxatp30-tos-frontend/src/routes/MainRoutes.tsxatp30-tos-frontend/src/routes/*.tsxatp30-tos-frontend/src/menu-items/index.tsatp30-tos-frontend/src/menu-items/dashboard.tsatp30-tos-frontend/src/menu-items/billing.tsatp30-tos-frontend/src/menu-items/reports.tsatp30-tos-frontend/src/menu-items/settings.tsatp30-tos-frontend/src/components/shared/Authorize.tsx