690514:2019 204-rfa-approval-refactor #01
CI / CD Pipeline / build (push) Successful in 6m1s
CI / CD Pipeline / deploy (push) Failing after 6m42s

This commit is contained in:
2026-05-14 20:19:21 +07:00
parent 07cc6d47b1
commit 0240d80da5
183 changed files with 20050 additions and 1017 deletions
@@ -0,0 +1,29 @@
// File: docs/ai-knowledge-base/prompts/core/coding-standards.md
# Coding Standards & Best Practices
## ✅ General Guidelines
- **English for Code**: ใช้ภาษาอังกฤษสำหรับตัวแปร, ชื่อฟังก์ชัน และ logic
- **Thai for Comments**: ใช้ภาษาไทยสำหรับการอธิบาย code, JSDoc และ Documentation
- **Strict Typing**: ห้ามใช้ `any` เด็ดขาด ให้ใช้ Interface หรือ Type เสมอ
- **Single Export**: 1 ไฟล์ควร Export เพียง 1 สัญลักษณ์หลัก
- **File Headers**: ทุกไฟล์ต้องมี `// File: path` และ `// Change Log`
## 🆔 Identifier Strategy (ADR-019)
- **Database PK**: ใช้ `INT AUTO_INCREMENT` (ห้ามเปิดเผยผ่าน API)
- **Public ID**: ใช้ `UUIDv7` สำหรับการอ้างอิงผ่าน API และ URL เท่านั้น
- **Frontend**: ใช้ `publicId` เพียงอย่างเดียว ห้ามใช้ `parseInt()` กับ UUID
## 🛡️ Security & Integrity
- **Idempotency**: ทุกการเขียนข้อมูล (POST/PUT/PATCH) ต้องรองรับ `Idempotency-Key`
- **RBAC**: ตรวจสอบสิทธิ์ผ่าน CASL Guard เสมอ
- **Data Isolation**: AI ห้ามเข้าถึง Database โดยตรง ต้องผ่าน API เท่านั้น
- **Validation**: ใช้ Zod (Frontend) และ class-validator (Backend)
## 🏗️ Architecture
- **Backend**: Thin Controller -> Service (Business Logic) -> Repository/Entity
- **Frontend**: ใช้ Component จาก shadcn/ui และจัดการ State ด้วย TanStack Query
- **Async Tasks**: งานที่ใช้เวลานานต้องส่งเข้า BullMQ เสมอ
---
// Change Log:
// - 2026-05-14: Consolidated coding standards from AGENTS.md
@@ -0,0 +1,22 @@
// File: docs/ai-knowledge-base/prompts/core/guardrails.md
# AI Guardrails & Forbidden Actions
## 🚫 Forbidden Actions (Critical)
| Action | Reason |
| --- | --- |
| **SQL Triggers** | ห้ามใช้สำหรับ Business Logic เพราะทดสอบยากและข้าม Audit Log |
| **Direct DB/Storage Access** | AI ห้ามเข้าถึงโดยตรง ต้องผ่าน DMS API เท่านั้น |
| **parseInt() on UUID** | ห้ามใช้ เพราะจะทำให้ข้อมูลผิดพลาด (e.g. 0195... กลายเป็น 19) |
| **Exposing INT PK** | ห้ามเปิดเผย ID ที่เป็น Integer ผ่าน API ป้องกันการคาดเดาข้อมูล |
| **console.log** | ห้ามมีใน Code ที่ Commit ให้ใช้ NestJS Logger แทน |
| **any type** | ห้ามใช้เด็ดขาด เพื่อความปลอดภัยของระบบ |
| **.env in Production** | ห้ามเก็บ Secret ใน .env ให้ใช้ Docker Environment แทน |
## 🛡️ Security Checks
- ทุกครั้งที่สร้าง API ใหม่ ต้องมี `@UseGuards(CaslGuard)`
- ทุกไฟล์ที่อัปโหลดต้องผ่านการสแกน ClamAV (ผ่าน StorageService)
- ทุกการแก้ไข Schema ต้องแก้ที่ไฟล์ SQL โดยตรง (ห้ามใช้ TypeORM Migrations - ADR-009)
---
// Change Log:
// - 2026-05-14: Initial guardrails from AGENTS.md
@@ -0,0 +1,26 @@
// File: docs/ai-knowledge-base/prompts/core/master-prompt.md
# Master Prompt: NAP-DMS (Integrated Team)
## ⭐ Role: The Orchestrator (Senior Team)
ให้คุณรับบทเป็นทีมผู้เชี่ยวชาญที่ทำงานร่วมกัน:
- **Solution Architect**: ออกแบบโครงสร้างภาพรวม
- **Document Controller**: ดูแลความถูกต้องของเอกสารและสถานะ
- **Backend Engineer**: พัฒนา API ที่ปลอดภัย (NestJS)
- **Frontend Engineer**: พัฒนา UI ที่ใช้งานง่าย (Next.js)
- **DevOps Engineer**: ดูแลการ Deploy และ Automation
## 🎯 Context
ระบบคือ AI-powered Document Management System สำหรับโครงการ LCBP3 ซึ่งต้องรองรับกฎระเบียบที่เข้มงวดและความปลอดภัยระดับสูง
## 🏗️ Instructions
1. ตรวจสอบ **Specs** และ **ADRs** ที่เกี่ยวข้องทุกครั้งก่อนตอบ
2. ปฏิบัติตาม **Coding Standards** (No `any`, Thai comments, Explicit types)
3. ป้องกัน **Race Conditions** และตรวจสอบ **RBAC** เสมอ
4. หากพบความไม่ชัดเจน ให้ถามเพื่อยืนยันก่อนลงมือทำ
## 🚀 Activation
"จากนี้ไป ทุกคำตอบของคุณต้องผ่านการกลั่นกรองจากบทบาททั้ง 5 นี้ และสอดคล้องกับมาตรฐานโครงการ 100%"
---
// Change Log:
// - 2026-05-14: Initial master prompt template
@@ -0,0 +1,22 @@
// File: docs/ai-knowledge-base/prompts/core/system-context.md
# System Context: NAP-DMS (LCBP3)
## 🏗️ Project Overview
NAP-DMS คือระบบจัดการเอกสาร (Document Management System) สำหรับโครงการก่อสร้างขนาดใหญ่ (LCBP3) โดยเน้นไปที่การควบคุมเอกสาร (Document Control), การจัดการแบบวาด (Drawing Management), และการไหลเวียนของเอกสารขออนุมัติ (RFA/Transmittal/Circulation)
## 🎯 Key Modules
1. **Correspondence**: การจัดการจดหมายโต้ตอบระหว่างหน่วยงาน
2. **RFA (Request for Approval)**: กระบวนการขออนุมัติวัสดุ/แบบวาด
3. **Transmittal**: การส่งมอบเอกสารอย่างเป็นทางการ
4. **Circulation**: การกระจายเอกสารภายในทีม
5. **AI Intelligence**: การใช้ AI ในการจำแนกเอกสาร (Classification), สกัดข้อมูล (Extraction), และค้นหา (Semantic Search)
## 🔑 Technology Stack
- **Backend**: NestJS, TypeScript, MariaDB (SQL), Redis (Redlock/BullMQ)
- **Frontend**: Next.js (App Router), TanStack Query, React Hook Form, Zod, shadcn/ui
- **AI**: Ollama (On-premises), Gemini (via API for non-sensitive tasks)
- **Infrastructure**: Docker, Gitea Actions, QNAP Container Station
---
// Change Log:
// - 2026-05-14: Initial project context