PEAK Dashboard — Workflow & Architecture

Streamlit dashboard วิเคราะห์ข้อมูลยอดขาย/ซื้อ/สต็อกจาก PEAK Account ของ Smart Solution Computer พร้อมรายงานผ่าน Telegram; ถอดแชต AI บนเว็บแล้ว

🔗 Links

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│  Mac (local)                                                 │
│  └─ push_token_mac.sh   (ดึง token ใหม่ จาก Chrome cookies) │
│     └─ rsync → VPS /opt/peak-dashboard/data/                │
└─────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌─────────────────────────────────────────────────────────────┐
│  VPS — Docker Container (peak-dashboard)                    │
│                                                              │
│  ├─ cron                                                     │
│  │  ├─ 03:00 UTC  daily_fetch.py → build_features.py        │
│  │  └─ 07:00 UTC  daily_fetch.py → build_features.py (retry)│
│  │                                                           │
│  ├─ daily_fetch.py     → pull sale/purchase/inventory API    │
│  │                       → master_*.parquet                  │
│  │                                                           │
│  ├─ build_features.py  → pre-compute feature store           │
│  │                       → ai_customer_360.parquet           │
│  │                       → ai_product_360.parquet            │
│  │                       → ai_daily_kpi.parquet              │
│  │                       → ai_brand_metrics.parquet          │
│  │                       → ai_schema.json                    │
│  │                                                           │
│  ├─ FastAPI   (:8000)  → REST endpoints                      │
│  └─ Streamlit (:8501)  → Dashboard + AI Chat                 │
│        └─ ai_chat.py → OpenRouter (Claude Haiku 4.5)         │
│              └─ ai_tools.py (15 tools, fast-path via FS)     │
└─────────────────────────────────────────────────────────────┘

📁 Key Files

File หน้าที่
app.py Streamlit main dashboard
api.py FastAPI endpoints
daily_fetch.py ดึงข้อมูลจาก PEAK API → master_*.parquet
build_features.py Pre-compute feature store (ai_*.parquet)
fetch_ar.py ดึง AR (ลูกหนี้คงค้าง) → master_ar.parquet — ExportInvoice + financeType=1 + tableStatus=3
ai_chat.py Orchestrator — OpenRouter + tool-calling loop
ai_tools.py 15 tools + fast-path feature store
shared_utils.py Loaders, brand detection, classification, payment score
token_refresher.py PEAK token management
Dockerfile Python 3.11 + Playwright + Thai fonts
entrypoint.sh cron + FastAPI + Streamlit boot
crontab.txt daily_fetch + build_features schedule
deploy.sh rsync + docker compose build + health check

🤖 AI Chat — 31 Tools (Phase 2 สมบูรณ์)

🎯 Phase 2 — Strategic Insights (2026-04-28 eve):

🎨 Phase 2 Pages (premium dark theme):