DNA OS — Architecture Observer
READ ONLY · ไม่มีข้อมูลธุรกิจจริง · ข้อมูลทั้งหมดมาจาก static registry files
หน้านี้สร้างขึ้นสำหรับ AI ภายนอก (Gemini, ChatGPT, Claude ฯลฯ) เพื่อเข้าใจโครงสร้างระบบ DNA OS
ท่านสามารถวิเคราะห์และให้คำแนะนำเกี่ยวกับระบบนี้ได้ แต่ไม่สามารถส่งคำสั่งหรือแก้ไขข้อมูลได้ผ่านหน้านี้

ระบบคืออะไร

DNA OS — ระบบ ERP อัจฉริยะสำหรับธุรกิจคอนกรีต/ขนส่ง

หลักการ: AI เป็นแค่ตัวกลาง ไม่ใช่ศูนย์กลาง — ศูนย์กลางคือกฎและสถาปัตยกรรม

การเติบโต: ขยายจากคลังกฎและ Workflow ไม่ใช่จากการฝึก AI

Design Shift (2026-07): เปลี่ยนจาก "เอกสารเป็นศูนย์กลาง" → "ความสัมพันธ์และ Event เป็นศูนย์กลาง"

Partner → Timeline of Events → Documents (เอกสารคือ artifact ของ event ไม่ใช่ตัว event เอง)

Architecture Pipeline

Input GatewayV1-Input
lib/v1-input/รับ Event ทุกรูปแบบ (LINE, HTTP, Webhook) แปลงเป็น JSON — ห้ามเขียน DB
Business RulesV2-Rules
engines/validation/Dispatcher + Validation + กฎธุรกิจ — ทุก command ต้องผ่านที่นี่
Business EngineV3-Engines
engines/คำนวณ logic (ราคา, หนี้, ภาษี, timeline) — ห้าม hardcode, ห้ามเขียน DB
AI InterpreterV4-AI
services/ai/แปลภาษาธรรมชาติ → command เท่านั้น — ห้ามตัดสินใจ ห้ามเขียนตรงไปยัง DB
Presentation LayerV5-Presenter
presenter/จัด format ผลลัพธ์สำหรับแสดงผล — ห้าม import จาก Business Engine โดยตรง
Execution LayerV6-Executor
gateway/ประตูเดียวที่เขียน DB + ส่ง LINE + เรียก external services ได้
Decision PipelineCognitive
cognitive/Pipeline กลาง: Intent → Plan → Execute → Reflect
Security & AuthMiddleware
services/middleware/requireAuth + Sanitize — บังคับใช้กับทุก API route
Input Gateway → AI Interpreter → Business Rules (Dispatcher) → Business Engine → Execution Layer → DB
                                             ↑ ตรวจ registry + filter ทุก command

โครงสร้างฐานข้อมูล

partnerspk: uuid
คู่ค้า (ลูกค้า/ซัพพลายเออร์)
name, partner_type_label, phone, address, tax_id
documentspk: uuid
เอกสารทุกประเภท (invoice, receipt, DO, PO, QT ...)
document_type, document_number, status, partner_id, net_amount, issue_date, business_event_id
document_itemspk: uuid
รายการย่อยในเอกสาร
document_id, line_no, description, qty, unit_price
debt_trackingspk: uuid
ติดตามลูกหนี้รายคน
partner_id, principal_amount, fee_rate, interest_start_at
invoice_debtspk: uuid
หนี้ค้างชำระจาก invoice (คนละตารางกับ debt_trackings)
document_id, invoice_status, outstanding_amount, paid_amount
business_eventspk: uuid
เหตุการณ์ธุรกิจที่เกิดกับคู่ค้า (infrastructure สำหรับ Partner Timeline)
partner_id, event_type, event_date, title, metadata
jobspk: uuid
งานจัดส่ง/โปรเจกต์
partner_id, job_status, distance_km, required_quantity
line_eventspk: uuid
ข้อความ LINE ที่รับเข้าระบบ
event_type, group_id, message_id, raw_json
line_draft_documentspk: uuid
ร่างเอกสารที่ AI วิเคราะห์จาก LINE รออนุมัติ
doc_type, status, payload
app_configspk: text (title)
ตั้งค่าระบบ (ค่า business rule ทุกตัวอยู่ที่นี่)
title, data
material_typespk: uuid
ประเภทวัสดุ/สินค้า
name

ประเภทเอกสาร

quotation
ใบเสนอราคา · prefix: QT
invoice
ใบแจ้งหนี้ · prefix: IV
receipt
ใบเสร็จรับเงิน · prefix: RE
delivery_order
ใบส่งของ · prefix: DO
purchase_order
ใบสั่งซื้อ · prefix: PO
payment_voucher
ใบสำคัญจ่าย · prefix: PV
debt_notice
ใบทวงหนี้ · prefix: DN

Command Registry

debt.listแสดงรายการหนี้ที่ยังค้างชำระ (สถานะ OPEN)
cognitive
debt.allแสดงรายการหนี้ทั้งหมด ทุกสถานะ
cognitive
debt.trackingsแสดงรายการติดตามหนี้ทั้งหมด (จากตาราง debt_trackings)
cognitive
debt.createสร้างรายการติดตามหนี้ใหม่ — ต้องผ่านขั้นตอน preview → execute
confirmcore
debt.findค้นหาลูกหนี้ตามชื่อ (แบบเทียบเคียงความคล้าย)
engines
invoice.listแสดงรายการใบแจ้งหนี้ (invoice) ทั้งหมด
cognitive
invoice.latestแสดงใบแจ้งหนี้ (invoice) ใบสุดท้าย
cognitive
invoice.createสร้างใบแจ้งหนี้ — ส่งต่อไปยัง Action API (ตามกฎข้อที่ 71)
confirmcognitive
invoice.findค้นหาใบแจ้งหนี้ตามเลขที่เอกสารหรือชื่อลูกค้า
engines
document.listแสดงรายการเอกสารทุกประเภท
cognitive
document.boqแสดงรายการใบเสนอราคา (BOQ)
cognitive
document.poแสดงรายการใบสั่งซื้อ (PO)
cognitive
document.doแสดงรายการใบส่งของ (DO)
cognitive
document.receiptแสดงรายการใบเสร็จรับเงิน
cognitive
document.createสร้างเอกสารใหม่ — ต้องผ่านขั้นตอน preview → execute
confirmcore
draft.listแสดงรายการร่างเอกสารที่มาจาก LINE และกำลังรอการอนุมัติ
cognitive
job.listแสดงรายการงานทั้งหมด
cognitive
job.activeแสดงรายการงานที่กำลังดำเนินการ (สถานะ IN_PROGRESS)
cognitive
job.assignสั่งงานคนขับ — AI ช่วยแปลภาษาพูดเป็นคำสั่งที่ระบบเข้าใจ
confirmservices
job.trackติดตามสถานะของงาน
services
partner.listแสดงรายการคู่ค้าทั้งหมด (ลูกค้าและผู้ขาย)
cognitive
partner.findค้นหาคู่ค้าตามชื่อ, เบอร์โทร, หรือรหัส
engines
material.listแสดงรายการประเภทวัสดุทั้งหมด
cognitive
pit.findค้นหาแหล่งวัสดุ เช่น บ่อดิน, โรงโม่, หรือท่าทราย
engines
drive.openเปิดโฟลเดอร์ Google Drive หลักของระบบ
cognitive
paymentบันทึกการชำระหนี้ — ต้องผ่านขั้นตอน preview → execute และมีการยืนยันตัวตน
confirmengines
pay.previewแสดงตัวอย่างข้อมูลก่อนยืนยันการชำระเงิน
services
pay.listดูประวัติรายการชำระเงิน (จากตาราง events)
services
doc.listดูรายการเอกสาร (เป็นชื่อเรียกแทน document.list สำหรับ AI)
services
doc.getดูรายละเอียดเอกสารตามหมายเลขที่ระบุ
services
quote.calcคำนวณราคาเสนอขาย (ผ่าน AI Bridge)
services
business.load_rulesโหลดกฎทางธุรกิจทั้งหมดจากตาราง app_configs
engines
business.calculate_priceคำนวณราคาขนส่งวัสดุ (รวมต้นทุน, ส่วนเพิ่ม, ค่าน้ำมัน, และค่าแรง)
engines
business.calculate_debtคำนวณยอดหนี้แบบครบวงจร (รวมเงินต้น, ดอกเบี้ย, และค่าทวงถาม)
engines
business.calculate_taxคำนวณภาษีมูลค่าเพิ่ม (VAT) และภาษีหัก ณ ที่จ่าย
engines
registry.loadโหลดทะเบียนข้อมูลทั้งหมดของระบบ (modules, drivers, events)
shared
registry.resolveค้นหาและคืนค่าโมดูลจากทะเบียนข้อมูล
shared
registry.list_modulesแสดงรายชื่อโมดูลทั้งหมดที่ลงทะเบียนไว้
shared
registry.list_driversแสดงรายชื่อไดรเวอร์ทั้งหมดที่ลงทะเบียนไว้
shared
registry.list_eventsแสดงรายชื่อเหตุการณ์ (events) ทั้งหมดที่ลงทะเบียนไว้
shared
registry.get_moduleดึงข้อมูลโมดูลจากทะเบียนตาม ID ที่ระบุ
shared
registry.get_driverดึงข้อมูลไดรเวอร์จากทะเบียนตามชื่อที่ระบุ
shared
registry.get_serviceดึงข้อมูลเซอร์วิสจากทะเบียนตามชื่อที่ระบุ
shared
registry.get_schemaดึงข้อมูล Schema จากทะเบียนตามชื่อที่ระบุ
shared
events.recentดึงประวัติเหตุการณ์ล่าสุด (ค่าเริ่มต้น 20 รายการ)
shared
events.by_traceดึงประวัติเหตุการณ์ตามรหัสติดตาม (Trace ID)
shared
ai.translateแปลภาษาไทยเป็นเจตนา (Intent), ข้อมูล (Entity), และคำสั่ง (Command) ที่ระบบรู้จัก
services
computer.app.launchสั่งเปิดโปรแกรมบน macOS (เช่น LINE, Chrome, VS Code)
core
computer.chat.readอ่านข้อความแชทจากโปรแกรมที่กำลังใช้งานอยู่
core
computer.chat.summarizeสรุปเนื้อหาจากแชทหรือข้อความที่อ่าน
core
computer.db.search_partnerค้นหาคู่ค้า (ทำงานตามขั้นตอน workflow)
core
computer.db.search_debtค้นหาหนี้ (ทำงานตามขั้นตอน workflow)
core
computer.db.load_invoiceโหลดข้อมูลใบแจ้งหนี้ (ทำงานตามขั้นตอน workflow)
core
computer.calc.priceคำนวณราคา (ทำงานตามขั้นตอน workflow)
core
computer.calc.distanceตรวจสอบระยะทาง (ทำงานตามขั้นตอน workflow)
core
computer.doc.generateสร้างเอกสาร (ทำงานตามขั้นตอน workflow)
confirmcore
computer.doc.previewดูตัวอย่างเอกสาร (ทำงานตามขั้นตอน workflow)
core
computer.line.sendส่งข้อความ LINE (ผ่านการควบคุมคอมพิวเตอร์)
confirmcore
computer.db.registerลงทะเบียนคู่ค้าใหม่ (ทำงานตามขั้นตอน workflow)
confirmcore
computer.email.sendส่งอีเมลผ่านโปรแกรม Apple Mail
confirmcore
computer.dev.deployสั่ง Deploy ระบบเวอร์ชันใหม่ผ่าน Terminal (vercel --prod)
confirmcore
computer.dev.pushสั่ง Push โค้ดล่าสุดผ่านโปรแกรม GitHub Desktop
confirmcore
computer.system.statusตรวจสอบสถานะของทุกโปรแกรมที่ลงทะเบียนไว้
core

Business Coverage

งานขาย / เสนอราคาcovered
Commands: business.calculate_price, calc.price, calc.distance
งานจัดซื้อcovered
Commands: partner.list, partner.find
ลูกหนี้ / ติดตามหนี้covered
Commands: debt.list, debt.all, debt.trackings, debt.create, business.calculate_debt
ภาษี / VAT / หัก ณ ที่จ่ายcovered
Commands: business.calculate_tax
ขนส่ง / จัดส่งวัสดุcovered
Commands: job.list, job.active
เอกสาร / ใบเสนอราคา / ใบแจ้งหนี้covered
Commands: document.list, document.create, invoice.list, invoice.create, receipt.create
LINE / Email / แจ้งเตือนcovered
Commands: line.send, line.read
คลังสินค้า / สต๊อกวัสดุnot_covered
Gap: ยังไม่มี module สำหรับจัดการคลังสินค้า / สต๊อก
บุคลากร / คนขับรถ / ช่างnot_covered
Gap: ยังไม่มี module สำหรับจัดการบุคลากร
ซ่อมบำรุง / เครื่องจักรpartial
Gap: มี kis-webhook สำหรับรับ event จากเครื่องจักร แต่ยังไม่มี engine จัดการซ่อมบำรุง
บัญชี / งบการเงินnot_covered
Gap: ยังไม่มี module สำหรับบัญชี/งบการเงิน
ความสัมพันธ์ธุรกิจ / Business Timelinecovered
Commands: partner.list, partner.timeline
Gap: business_events ยังว่างอยู่ (phase 1 ใช้ documents เป็นหลัก) — phase 2 คือ event capture จาก LINE + manual note
Design: เอกสารคือ artifact ของ event ไม่ใช่ตัว event เอง — ศูนย์กลางคือ partner + timeline

Workflow Registry

การสร้างใบเสนอราคา
รับข้อมูลจากผู้ใช้, คำนวณราคา, สร้างเอกสาร, และแสดงผล
Trigger: ถูกเรียกใช้ผ่านคำสั่ง quote.calc
Steps: AI แปลภาษา → เครื่องยนต์คำนวณ → จัดรูปแบบการแสดงผล → สร้างเอกสาร
การตรวจสอบหนี้ค้างชำระ
ทำงานอัตโนมัติตามเวลาเพื่อตรวจสอบหนี้ที่ครบกำหนดและเปลี่ยนสถานะ
Trigger: ถูกเรียกใช้อัตโนมัติทุกวัน
Steps: ตัวตั้งเวลาตรวจสอบหนี้ → ตัวเปลี่ยนสถานะหนี้
การตอบราคาผ่าน LINE
รับข้อความจาก LINE, วิเคราะห์ด้วย AI, คำนวณราคา, และส่งข้อความตอบกลับ
Trigger: ถูกเรียกใช้ผ่าน Webhook ของ LINE
Steps: AI Gemini วิเคราะห์ข้อความ → เครื่องยนต์คำนวณราคา → API สำหรับส่งข้อความ LINE

ความสามารถระบบ (Existence Registry)

visionavailable
macOS Screenshot, Browser Canvas, LINE Image
gpsavailable
Google Maps API, Browser Geolocation, Vehicle GPS
voicenot_available
ยังไม่มี Voice Input/Output
cameranot_available
ยังไม่มี Camera API
messagingavailable
LINE Messaging API, LINE Notify, Email SMTP
paymentpartial
Manual via invoice_payments
ยังไม่มี auto payment gateway
printeravailable
macOS Print Dialog, PDF Export
sensorpartial
KIS Webhook (IoT)
รับ event ได้ แต่ยังไม่ส่งคำสั่งกลับ
databaseavailable
Supabase PostgreSQL, Supabase Realtime
ai_textavailable
OpenAI GPT, Google Gemini, Local Keyword Match
file_systemavailable
macOS Finder, Node.js fs
terminalavailable
macOS Terminal, zsh
browseravailable
Google Chrome, Safari
calendaravailable
macOS Calendar
plcnot_available
ยังไม่มี PLC/Modbus/OPC-UA
mqttnot_available
ยังไม่มี MQTT broker
robot_armnot_available
ยังไม่มี Robot Controller

กฎเหล็ก (Constitution)

  • 1.ห้าม hardcode ข้อมูลธุรกิจ — ทุกค่าจาก DB via app_configs
  • 2.ห้าม mock/fake/demo data ใน source code
  • 3.ทุก write ต้อง confirmed จากมนุษย์ (Rule 72)
  • 4.AI ห้ามเปลี่ยนสถานะการเงิน (Rule 73, 83)
  • 5.ทุก API route ต้องมี requireAuth
  • 6.ทุก Module ต้อง register ใน module-registry.json
  • 7.ทุก Command ต้อง register ใน command-registry.json
  • 8.Shadow Command (ไม่อยู่ใน registry) ถูกปฏิเสธเสมอ
  • 9.V2-V5 ห้าม import @supabase/supabase-js — เฉพาะ V6
  • 10.V5 ห้าม import จาก V3 โดยตรง

Module Registry (สรุป)

api41 modules
ui28 modules
cognitive37 modules
registry17 modules

ท่อเชื่อม AI ภายนอก (External AI Pipe)

DNA OS เปิด API ให้ AI ภายนอก (Gemini, ChatGPT, Claude, หรือ app ใดก็ได้) เรียก query commands ผ่าน token
1
อ่านโครงสร้างระบบ
วาง URL หน้า Observer (/observer) ลงในแชท AI เพื่อให้รู้ว่า DNA OS มีอะไรบ้าง
READ ONLY · ไม่ต้อง token
2
ดึง Tool Spec
GET /api/v1/spec — ได้รายการ commands ทั้งหมดในรูปแบบ OpenAI function-calling
Public · Cache 5 min
3
สร้าง Token
ไปที่ /admin/api-tokens → สร้าง token ผูกกับอีเมลของท่าน
ต้อง login
4
เรียก Query
POST /api/v1/query + Header: X-DNA-Token: <token> + Body: {command, args}
Read-only commands เท่านั้น
ตัวอย่าง request
POST /api/v1/query
X-DNA-Token: your-token-here
Content-Type: application/json

{ "command": "debt.list", "args": {} }

// Response
{
  "ok": true,
  "command": "debt.list",
  "user": "your@email.com",
  "data": [ ...InvoiceDebt[] ]
}
ข้อจำกัด (Guard)
  • • Write commands (requires_confirmation: true) ถูกบล็อก — ต้องทำจาก /admin UI เท่านั้น (Rule 72)
  • • Shadow Command (ไม่อยู่ใน registry) ถูกปฏิเสธเสมอ
  • • Token ผูกกับ user_email — revoke ได้ทันทีจาก /admin/api-tokens
  • • ข้อมูลจริงของธุรกิจ: อ่านได้ผ่าน token เท่านั้น ไม่ผ่านหน้า Observer นี้
DNA OS · Architecture Observer · READ ONLY
ข้อมูลนี้มาจาก static registry files เท่านั้น ไม่มีการเชื่อมต่อฐานข้อมูล
ต้องการ query ข้อมูลจริง → ใช้ /api/v1/query พร้อม token จาก /admin/api-tokens