หน้าหลักสถาปัตยกรรมระบบ

เอกสารสถาปัตยกรรมและ flow ระบบ Admin Panel — แสดง Mermaid diagrams แบบ interactive

1. สถาปัตยกรรมระบบโดยรวม

Overview ของ Frontend (Nuxt 4 SPA) และ Backend (Bun API Server) พร้อม MongoDB

กำลังโหลด diagram...
📋 แสดงโค้ด Mermaid
graph TB
    Client["🖥️ Admin Browser<br/>(Nuxt 4 SPA)"]
    BunAPI["⚡ Bun API Server<br/>(REST API)"]
    MongoDB[("🍃 MongoDB")]
    LineOA["💚 Line OA API"]
    BotService["🤖 Bot Service<br/>(Statement Pull)"]
    BankAPI["🏦 Bank APIs"]

    Client -->|"HTTP/HTTPS"| BunAPI
    BunAPI --> MongoDB
    BunAPI --> LineOA
    BunAPI --> BotService
    BotService --> BankAPI
    BotService --> MongoDB

    style Client fill:#e0f2fe,stroke:#0284c7
    style BunAPI fill:#f0fdf4,stroke:#16a34a
    style MongoDB fill:#fef3c7,stroke:#d97706
    style LineOA fill:#dcfce7,stroke:#15803d
    style BotService fill:#f3e8ff,stroke:#9333ea
    style BankAPI fill:#fee2e2,stroke:#dc2626

2. Flow กระบวนการฝากเงิน

กระบวนการตั้งแต่ลูกค้าแจ้งฝากจนถึงเครดิตเข้า

กำลังโหลด diagram...
📋 แสดงโค้ด Mermaid
sequenceDiagram
    participant C as ลูกค้า
    participant LINE as Line OA
    participant SYS as ระบบ
    participant BOT as Bot
    participant BANK as ธนาคาร
    participant ADMIN as Admin

    C->>LINE: แจ้งฝากเงิน + สลิป
    LINE->>SYS: ส่ง Webhook
    BOT->>BANK: ดึงข้อมูลกระแสเงินสด
    BANK-->>BOT: Statement ใหม่
    BOT->>SYS: บันทึก Cash Flow

    SYS->>SYS: จับคู่อัตโนมัติ
    alt จับคู่สำเร็จ 100%
        SYS->>C: เพิ่มเครดิตอัตโนมัติ
    else จับคู่บางส่วน (40%+)
        SYS->>ADMIN: แจ้งเตือนรายการรอจัดการ
        ADMIN->>SYS: ยืนยันจับคู่
        SYS->>C: เพิ่มเครดิต
    else ไม่จับคู่ได้
        ADMIN->>SYS: อนุมัติด้วยตนเอง
        SYS->>C: เพิ่มเครดิต
    end

3. Flow กระบวนการถอนเงิน

กระบวนการถอนตั้งแต่ลูกค้าแจ้งถอนจนถึงการโอนเงิน

กำลังโหลด diagram...
📋 แสดงโค้ด Mermaid
flowchart TD
    A([ลูกค้าแจ้งถอน]) --> B{ตรวจสอบเงื่อนไข}
    B -->|ไม่ผ่าน| C[แจ้งเหตุผลปฏิเสธ]
    B -->|ผ่าน| D[บันทึกรายการถอน]
    D --> E{ถอนอัตโนมัติ?}
    E -->|ใช่| F[Bot โอนเงินอัตโนมัติ]
    E -->|ไม่ใช่| G[Admin โอนเงินด้วยตนเอง]
    F --> H{โอนสำเร็จ?}
    G --> H
    H -->|สำเร็จ| I[อัพเดตสถานะ + หักเครดิต]
    H -->|ล้มเหลว| J{จำนวนครั้ง retry?}
    J -->|< 3| K[Retry อัตโนมัติ]
    J -->|>= 3| L[แจ้ง Admin]
    K --> H
    I --> M([จบกระบวนการ])

    style A fill:#e0f2fe,stroke:#0284c7
    style M fill:#dcfce7,stroke:#16a34a
    style C fill:#fee2e2,stroke:#dc2626
    style L fill:#fef3c7,stroke:#d97706

4. การเลื่อนระดับลูกค้า

ระดับกลุ่มลูกค้าและเงื่อนไขการเลื่อนระดับ

กำลังโหลด diagram...
📋 แสดงโค้ด Mermaid
stateDiagram-v2
    [*] --> New: สมัครใหม่
    New --> Silver: ฝาก >= 50,000
    Silver --> Gold: เดิมพัน >= 2,000,000
    Gold --> Diamond: เดิมพัน >= 10,000,000
    Diamond --> Platinum: เดิมพัน >= 50,000,000
    Platinum --> Titanium: เงื่อนไขพิเศษ

    Silver --> New: ไม่เป็นไปตามเงื่อนไข
    Gold --> Silver: ไม่เป็นไปตามเงื่อนไข
    Diamond --> Gold: ไม่เป็นไปตามเงื่อนไข
    Platinum --> Diamond: ไม่เป็นไปตามเงื่อนไข

5. โครงสร้าง API (Bun Server)

Endpoints หลักของ Bun REST API

กำลังโหลด diagram...
📋 แสดงโค้ด Mermaid
graph LR
    API["/api"] --> DASH["/dashboard"]
    API --> CUST["/customers"]
    API --> DEP["/deposit"]
    API --> WD["/withdraw"]
    API --> TR["/transfer"]
    API --> NM["/non-match + /credit"]
    API --> REP["/reports"]
    API --> VS["/validate-statement"]
    API --> DS["/divide-shift"]
    API --> BANKS["/banks"]
    API --> CHATS["/chats"]
    API --> GRP["/groups"]

    DASH --> D1["GET /summary"]
    DASH --> D2["GET /transactions-chart"]
    DASH --> D3["GET /channels"]

    CUST --> C1["GET / POST"]
    CUST --> C2["GET/PUT /:id"]
    CUST --> C3["POST /:id/credit"]

    DEP --> DEP1["GET /accounts"]
    DEP --> DEP2["GET/POST /transactions"]
    DEP --> DEP3["PUT /transactions/:id/match"]

    style API fill:#1e40af,color:#fff
    style DASH fill:#0284c7,color:#fff
    style CUST fill:#059669,color:#fff
    style DEP fill:#d97706,color:#fff
    style WD fill:#dc2626,color:#fff

6. State Management (Pinia Stores)

โครงสร้าง Pinia stores สำหรับ Nuxt 4

กำลังโหลด diagram...
📋 แสดงโค้ด Mermaid
graph TD
    AUTH["useAuthStore<br/>Admin info & permissions"]
    DASH_S["useDashboardStore<br/>Stats, charts, channels"]
    CUST_S["useCustomerStore<br/>List, filters, pagination"]
    DEP_S["useDepositStore<br/>Transactions, bank accounts"]
    WD_S["useWithdrawStore<br/>Transactions, bank accounts"]
    TR_S["useTransferStore<br/>Transfer records"]
    CR_S["useCreditStore<br/>Credit adjustments"]
    BANK_S["useBankStore<br/>All bank accounts"]
    CHAT_S["useChatStore<br/>Chats & messages"]
    NOTIF_S["useNotificationStore<br/>System notifications"]

    AUTH --> DASH_S
    AUTH --> CUST_S
    AUTH --> DEP_S
    AUTH --> WD_S
    AUTH --> TR_S
    AUTH --> CR_S
    AUTH --> BANK_S
    AUTH --> CHAT_S
    AUTH --> NOTIF_S

    style AUTH fill:#7c3aed,color:#fff
    style NOTIF_S fill:#0ea5e9,color:#fff

7. โครงสร้างโปรเจกต์ Nuxt 4

Directory structure ของ Nuxt 4 SPA

กำลังโหลด diagram...
📋 แสดงโค้ด Mermaid
graph TD
    ROOT["📁 dashboard/"]
    APP["📁 app/"]
    ASSETS["📁 assets/css/"]
    COMPS["📁 components/"]
    LAYOUTS["📁 layouts/"]
    PAGES["📁 pages/"]
    STORES["📁 stores/"]
    COMP_TYPES["📁 modal/ table/ filter/ widget/"]
    PAGE_TYPES["📁 customers/ deposit/ reports/ settings/ docs/"]

    ROOT --> APP
    APP --> ASSETS
    APP --> COMPS
    APP --> LAYOUTS
    APP --> PAGES
    APP --> STORES
    COMPS --> COMP_TYPES
    PAGES --> PAGE_TYPES

    style ROOT fill:#1f2937,color:#fff
    style APP fill:#374151,color:#fff
    style COMPS fill:#065f46,color:#fff
    style PAGES fill:#1e3a5f,color:#fff
    style STORES fill:#5b21b6,color:#fff

📄 Pages / Routes Reference

#Routeชื่อหน้าสถานะ
1/ภาพรวม✓ พร้อมใช้
2/customersรายงานลูกค้า✓ พร้อมใช้
3/settings/groupsตั้งค่ากลุ่ม✓ พร้อมใช้
4/depositฝาก✓ พร้อมใช้
5/deposit/manageกดจัดการ✓ พร้อมใช้
6/withdrawถอน✓ พร้อมใช้
7/transferโอนเงิน✓ พร้อมใช้
8/non-matchยอดลอย / เครดิต✓ พร้อมใช้
9/reports/summaryรายงานสรุป✓ พร้อมใช้
10/validate-statementเปรียบเทียบ STM✓ พร้อมใช้
11/divide-shiftตัดกะงาน✓ พร้อมใช้
12/banksบัญชีทั้งหมด✓ พร้อมใช้
13/chatsChats (Line OA)✓ พร้อมใช้

🔌 API Endpoints (Bun Server) — Summary

Dashboard

  • /api/dashboard/summary
  • /api/dashboard/transactions-chart
  • /api/dashboard/channels

Customers

  • /api/customers
  • /api/customers/:id
  • /api/customers/:id/credit

Deposit

  • /api/deposit/accounts
  • /api/deposit/transactions
  • /api/deposit/transactions/:id/match

Withdraw

  • /api/withdraw/accounts
  • /api/withdraw/transactions
  • /api/withdraw/transactions/:id/confirm

Transfer

  • /api/transfer/transactions
  • /api/transfer/create
  • /api/transfer/:id/confirm

Banks

  • /api/banks
  • /api/banks/:id
  • /api/banks/deleted