ERP kernel-v2 — System Docs
ERP สำหรับ SME ไทย บน Cloudflare Pages Functions + D1 — multi-tenant, money-safe (double-entry kernel), 16 modules · 242 tables · 442 API ops. เอกสารทั้งหมด generate จาก code จริง (schema → ER, dispatch → API surface) + process flow เขียนจากการอ่านโค้ดจริงทุก module.
diagram-as-code
ทุก diagram คือ Mermaid — diff ได้ใน git, regenerate ได้, ไม่ลากมือ. รูปแสดงขนาดจริง: เลื่อนในกรอบเพื่ออ่าน · ปุ่ม ⛶ = เต็มจอ · ลากมุมล่างขวาปรับขนาด.
System architecture
%%{init: {"theme":"base","themeVariables":{"darkMode":true,"background":"#1e1e1e","primaryColor":"#2d2d30","primaryBorderColor":"#569cd6","primaryTextColor":"#d4d4d4","lineColor":"#6796c6","secondaryColor":"#3a3d41","secondaryBorderColor":"#dcdcaa","tertiaryColor":"#252526","tertiaryBorderColor":"#569cd6","clusterBkg":"#252526","clusterBorder":"#569cd6","titleColor":"#569cd6"},"flowchart":{"useMaxWidth":false}}}%%
flowchart TB
CL["Client · POS · Web · Portal · Partner API"] --> GW["Pages Functions<br/>bolt_session JWT auth · company_id tenant scope"]
GW --> MOD["16 module Functions<br/>accounting · sales · purchasing · inventory · pos<br/>claims · crm · mfg · project · hr · marketing · fixed-assets"]
MOD --> K["Kernel — erp_document + erp_journal_entry<br/>atomic double-entry GL + stock subledger"]
MOD --> VA["Channel vault<br/>envelope encryption (per-tenant DEK)"]
VA --> EXT["Shopee · TikTok · Lazada · LINE OA<br/>GBPrimePay · Omise · 2C2P · PromptPay"]
K --> DB[("D1 · boltos-db<br/>242 tables")]
MOD --> DB
Modules
| Module | Tables | ดู |
|---|---|---|
| Accounting | 20 | GL · AR/AP · payment · close · budgeting · WHT · FX · bank recon |
| Sales | 16 | quotation → order → delivery → invoice |
| Purchasing | 31 | PR → PO → receipt → bill |
| Inventory & Warehouse | 12 | stock moves · onhand · avg-cost · WMS |
| POS | 15 | session · order · cash · terminals |
| Warranty & Claims | 14 | ประกัน · เคลม · RMA · ซ่อม/เปลี่ยน · supplier claim |
| CRM & Loyalty | 17 | opportunity · pipeline · points · rewards |
| Manufacturing | 14 | BOM · routing · work order · WIP |
| Project | 11 | project · task · timesheet · billing |
| HR | 13 | employee · attendance · leave · payroll |
| Marketing | 13 | campaign · audience · attribution |
| Fixed Assets | 3 | register · depreciation · disposal |
| Core / Kernel | 63 | company · party · item · document · journal · dimension |
How these docs stay true
- ER diagrams →
scripts/gen-erp-erd.mjsparsemigrations-v2/*.sql(242 tables, 701 FK) → Mermaid + data dictionary. Schema เปลี่ยน = รูปเปลี่ยนเอง. - API surface → parse dispatch ของแต่ละ module + full ReDoc (442 ops).
- Process flows → เขียนจากการอ่าน code จริง (dispatch + functions + status enums).
- theme = VS Code Dark+; deploy = Cloudflare Pages (฿0).