Skip to content

workflow-api Deep Dive

สำคัญ — ชื่อ repo กับตัว package ไม่ตรงกัน workflow-api (canonical branch: uat, ~153 tracked files) มีชื่อ package ใน package.json ว่า ai-pms-nest พร้อม description "AI-Powered Performance Management System with NestJS" (workflow-api/package.json (branch: uat):2,4)

โค้ดจริง ไม่มี workflow engine เอนกประสงค์ตามชื่อ repo — มี 3 domain module ที่ไม่เกี่ยวกันโดยตรง:

  1. embedding — AI embedding ของหลักสูตรฝึกอบรม (course) ผ่าน LLM router ภายนอก เพื่อจัดกลุ่ม/แนะนำหลักสูตร (PMS)
  2. health-checkup — ตั้งค่าโปรแกรมตรวจสุขภาพประจำปี + eligibility simulator (HR benefit)
  3. ipd — IPD (in-patient) billing batch ระหว่างโรงพยาบาลเครือข่าย (จุฬาฯ / สมเด็จ ณ ศรีราชา) กับฝ่ายบัญชี/SABC

ทั้งสาม module เชื่อมต่อฐานข้อมูลของ service อื่น (vtrc, dbHRMI_Center, dbHRMI_Center_NBC, benefit) โดยตรงผ่าน TypeORM หลาย connection — ดู 03 Persistence และ CORR-WORKFLOW-01

Stack

ส่วนค่าหลักฐาน
FrameworkNestJS 10 (@nestjs/core ^10.4.20)workflow-api/package.json (branch: uat):24-27
Node engine22.xworkflow-api/package.json (branch: uat):20-22
Package managerpnpm@10.13.1workflow-api/package.json (branch: uat):19
ORMTypeORM ^0.3.27 — 6 named connectionsworkflow-api/src/core/database/database.module.ts (branch: uat):9-199
Loggernest-winston + winston-daily-rotate-fileworkflow-api/package.json (branch: uat):37,44-45
Authไม่มี JWT guard — decode payload ไม่ verify signatureworkflow-api/src/main.ts (branch: uat):9-82, jwt-actor.util.ts:1-4,33-47
Export docsdocx ^9.7.1, exceljs ^4.4.0workflow-api/package.json (branch: uat):32,34
HTTP to LLMnative fetch (Node 22) ผ่าน LlmServiceworkflow-api/src/integrations/llm/llm.service.ts (branch: uat):58-65
DB driverspg ^8.16.3 + mssql ^11.0.1workflow-api/package.json (branch: uat):35,39

Entry point และพอร์ต

  • Entry: workflow-api/src/main.ts (branch: uat):9NestExpressApplication, CORS เปิด, validateRequest() pipe, HttpErrorFilter, global prefix `${BASE_PATH}api/v1`
  • Static assets: /workflow-api/./uploads (main.ts:21-23)
  • พอร์ต: PORT default 8000 (main.ts:25, .env.example:2)
  • BASE_PATH=workflow-api/ (.env.example:5) → HTTP path /workflow-api/api/v1/*
  • PUBLIC_API_URL=https://workflow-api.vtrcsupport.com (.env.example:6)
  • Swagger: SWAGGER_PATH default api-docs และ mirror ที่ {BASE_PATH}/api-docs (main.ts:26,71-74)
  • Swagger description ระบุชัดว่า signature ไม่ถูก verify ใน service นี้ (main.ts:42)

Database topology (6 connections)

NameEngineDefault DBใช้โดย
postgresPostgreSQLpms_ai schema (env DB_PMS_*)embedding / course
vtrcMSSQLvtrcIPD billing tables ใน schema ของ legacy core
hrmiMSSQLdbHRMI_Centerจับคู่พนักงาน IPD
hrmi_nbcMSSQLdbHRMI_Center_NBCHRMI สาย NBC
benefitMSSQL (read host)benefitอ่านสิทธิประโยชน์ / health config
benefit_writeMSSQL (write host)benefitเขียน audit healthCheckLogs + health mutations

หลักฐาน — workflow-api/src/core/database/database.module.ts (branch: uat):9-199

Deploy artifact

  • Multi-stage Dockerfile บน node:22-alpine, corepack + pnpm, EXPOSE 8000, CMD ["node", "dist/main.js"] (workflow-api/Dockerfile (branch: uat):1-30)
  • หมายเหตุ: package.json script start:prod คือ node dist/main แต่ Dockerfile ใช้ dist/main.js — ทั้งสองชี้ไปไฟล์ build เดียวกันหลัง nest build

สิ่งที่ควรรู้ก่อนอ่านบทถัดไป

  1. ไม่มี useGlobalGuards — การ "auth" คือ decode JWT แล้วอนุมาน role จาก sourceDB (SEC-WORKFLOW-01)
  2. ไฟล์ service ใหญ่เกิน: ipd-batch.service.ts ~2753 บรรทัด, embedding.service.ts ~2527, health-program-config.service.ts ~1398
  3. .env.example มี secret จริงฝังอยู่ (AI router key, DB passwords) — SEC-WORKFLOW-02; เอกสารนี้ ไม่ คัดลอกค่า secret
  4. ทีมกำหนดโครงสร้างเองใน .cursor/rules/backend-clean-architecture.mdccore/ / common/ / integrations/ / modules/

สารบัญ

บทหัวข้อ
01Repository map
02Core pipeline — IPD, embedding, health-checkup
03Persistence (6 connections) + LLM + audit
04Scorecard + debt register