📐 Enterprise Architecture & Technical Documentation

PEA Outsource Management System (OSM)

📄 เอกสารประกอบข้อเสนอทางเทคนิค 🏢 การไฟฟ้าส่วนภูมิภาค (PEA) 📅 มีนาคม 2569 🔖 Version 1.0
1. Enterprise Architecture 2. Microservices 3. Security & PDPA 4. Scalability 5. DevSecOps & CI/CD 6. API & Integration 7. Monitoring & Log 8. Deployment 9. DR & Backup

01 Enterprise Architecture Overview

ระบบ OSM ออกแบบตามหลัก Modern Application Development (12-Factor App) ตามที่ TOR ข้อ 4.3 กำหนด โดยใช้สถาปัตยกรรม Microservices บน Kubernetes (K8s) รองรับ Responsive Design ทั้ง PC, Smartphone, และ Tablet

Enterprise Architecture — Layered Diagram
🖥️ Client Layer
Web Browser (Chrome, Safari, Edge, Firefox)
Mobile PWA (iOS / Android)
Tablet (Responsive)
Search Suggestion
🌐 Edge Layer
Nginx Reverse Proxy
SSL/TLS Termination
Rate Limiting
WAF (Web App Firewall)
🔐 Auth & Gateway
API Gateway (Kong / Express)
Keycloak SSO (OIDC/OAuth2)
JWT Token Management
Active Directory Integration
⚙️ Microservices
Request Service
Contract Service
Payment Service
Evaluation Service
Notification Service
Report Service
User & Role Service
Audit Log Service
File Storage Service
🔗 Integration
HR Data Platform API
Smart Payment (SAP)
e-Procurement (e-GP)
Digisign API (Digital Signature)
PEA Email (SMTP)
Calendar API
💾 Data Layer
PostgreSQL (Primary DB)
Redis (Session + Cache)
S3-Compatible (File Storage)
Elasticsearch (Search + Log)
🏗️ Infrastructure
Kubernetes (K8s) Cluster
Docker Containers
Helm Charts
GitLab CI/CD Runner
Prometheus + Grafana
Vault (Secret Management)
📋 TOR Compliance: สถาปัตยกรรมข้างต้นครอบคลุมข้อ 4.3 (Modern Application Development / 12-Factor), ข้อ 4.4 (API Web Service Integration), ข้อ 4.6 (Responsive Web App), ข้อ 4.8 (DevSecOps/K8s), ข้อ 4.11 (Microservices), ข้อ 4.12 (SSO/Keycloak), ข้อ 4.14 (PostgreSQL)

02 Microservices Architecture

ระบบออกแบบเป็น 9 Microservices แต่ละ Service มีหน้าที่ชัดเจน (Single Responsibility) สื่อสารกันผ่าน REST API และ Event Bus (Message Queue) สามารถ Scale แต่ละ Service ได้อิสระ

Microservices Communication Diagram
👤
User Service
Auth, Role, Profile
📝
Request Service
ขอจ้าง/อนุมัติ Workflow
📄
Contract Service
สัญญา/เอกสาร/Variation
💳
Payment Service
เบิกจ่าย/SAP/e-Receipt
Evaluation Service
ประเมินผล/KPI
🔔
Notification Service
Email/Line/In-app
📊
Report Service
PDF/Word/Excel Export
📂
File Service
Upload/Preview/Storage
📋
Audit Log Service
Activity Logging (TOR 4.20)
↕ API Gateway (Kong / Express Gateway) ← → Message Queue (Redis Pub/Sub / RabbitMQ)

12-Factor App Compliance (TOR ข้อ 4.3)

FactorImplementation
I. CodebaseGitLab Monorepo / Multi-repo per service
II. Dependenciespackage.json / requirements.txt — locked versions
III. ConfigEnvironment Variables + Vault Secret Manager
IV. Backing ServicesPostgreSQL, Redis, S3, SMTP — attached via env config
V. Build, Release, RunDocker multi-stage build → Helm release → K8s rollout
VI. ProcessesStateless containers, session in Redis
VII. Port BindingEach service exposes HTTP port independently
VIII. ConcurrencyHorizontal Pod Autoscaler (HPA) per service
IX. DisposabilityFast startup/shutdown, graceful drain connections
X. Dev/Prod ParityDocker Compose (dev) = K8s (prod) same images
XI. Logsstdout → Fluentd → Elasticsearch → Kibana
XII. Admin ProcessesK8s Jobs / CronJobs for migrations, scripts

03 Data Security & PDPA Compliance

ระบบออกแบบ Security ตาม Defense-in-Depth หลายชั้น ครอบคลุมทั้ง Network, Application, Data, และ User Level พร้อมรองรับ พ.ร.บ. คุ้มครองข้อมูลส่วนบุคคล พ.ศ. 2562 (PDPA)

Security Architecture — Defense-in-Depth Model
🛡️ Layer 1: Network Security
Firewall • WAF • DDoS Protection • TLS 1.3 • VPN
🔐 Layer 2: Authentication
Keycloak SSO • OAuth2/OIDC • MFA • JWT • Session Mgmt
🔑 Layer 3: Authorization
RBAC (Super Admin / Admin / User) • API Key • Scope Control
📝 Layer 4: Application Security
OWASP Top 10 • SAST (SonarQube) • DAST • Code Review
💾 Layer 5: Data Security
AES-256 at-rest • TLS in-transit • Column Encryption • Key Rotation
👁️ Layer 6: Audit & Monitoring
Audit Log • SIEM • Intrusion Detection • Anomaly Alert

🔐 Authentication Flow (SSO — TOR ข้อ 4.12)

SSO Authentication Flow (Keycloak + Active Directory)
👤 User
Web Browser
🌐 OSM App
React Frontend
🔐 Keycloak
OIDC Provider
🏢 PEA AD
LDAP/Active Dir
✅ JWT Token
Access + Refresh
1. User คลิก "Login via SSO" → 2. Redirect ไป Keycloak → 3. Keycloak ยืนยัน AD → 4. ออก JWT Token → 5. Frontend เก็บ Token ส่งทุก API Call

📋 PDPA Compliance Framework (พ.ร.บ. 2562)

📜
NDA Agreement
บังคับลงนามก่อนเข้าถึงข้อมูล (TOR ภาคผนวก 1)
📑
DPA Agreement
Data Processing Agreement ระหว่าง PEA กับผู้พัฒนา (ภาคผนวก 2)
🔒
Data Minimization
เก็บเฉพาะข้อมูลที่จำเป็น ไม่เกินวัตถุประสงค์
🗑️
Right to Erasure
รองรับการขอลบข้อมูลส่วนบุคคลตามกฎหมาย
📊
Audit Trail
บันทึก Log ทุกกิจกรรม 90 วัน (TOR ข้อ 4.20)
🔏
Digital Signature
Digisign API สำหรับลงนามอิเล็กทรอนิกส์ (TOR ข้อ 4.18)

Security Scan Integration (TOR ข้อ 4.9)

ประเภทเครื่องมือจุดที่ Scanความถี่
SASTSonarQubeSource Code (ทุก Commit)ทุก CI Pipeline
DASTOWASP ZAPRunning Applicationสัปดาห์ละ 1 ครั้ง
SCASnyk / TrivyDependencies + Docker Imageทุก CI Pipeline
Secret ScanGitLeaksGit Repositoryทุก Commit
PentestManual + AutomatedFull Systemก่อน Go-Live + รายไตรมาส

04 System Scalability & Performance

ระบบออกแบบเพื่อรองรับการขยายตัว (Scale-out) ทั้ง Horizontal และ Vertical ตาม TOR ข้อ 4.8 (Kubernetes) และข้อ 15.9 (Performance Test)

Scalability Architecture — Auto-Scaling Strategy

↔️ Horizontal Scaling (Scale-Out)

Kubernetes HPA — Pod Autoscaler ตาม CPU/Memory

Min 2, Max 10 Pods ต่อ Service

Load Balancer — Round-robin distribution

Database Read Replica — PostgreSQL Streaming Replication

↕️ Vertical Scaling (Scale-Up)

Resource Requests/Limits — K8s Resource Quota

CPU: 0.5–2 cores / Memory: 512MB–2GB ต่อ Pod

PV Dynamic Provisioning — Storage auto-expand

PostgreSQL Tuning — shared_buffers, work_mem

Performance Targets (TOR ข้อ 15.9)

MetricTarget SLAวิธีวัด
Response Time (API)< 500ms (P95)Prometheus + Grafana
Page Load Time< 3 secondsLighthouse / WebPageTest
Concurrent Users≥ 500 usersk6 / JMeter Load Test
Uptime≥ 99.5%Uptime Kuma / StatusPage
Database Query< 200ms (P95)pg_stat_statements
File Upload< 5s (50MB file)Integration Test

Caching Strategy

🔴

Redis Cache

Session, JWT Token, Frequently-accessed data, Rate Limiter

🌐

Browser Cache

Static assets (JS/CSS/images), Service Worker for PWA offline

📄

CDN Cache

Static files, Generated reports (PDF/Excel), Image thumbnails

🗄️

Query Cache

PostgreSQL prepared statements, Materialized Views for dashboards

05 DevSecOps & CI/CD Pipeline

ตาม TOR ข้อ 4.8 ระบบต้องรองรับ Continuous Integration and Continuous Deployment (CI/CD) บน DevSecOps Platform (Kubernetes) โดยใช้ GitLab CI/CD เป็น Pipeline Runner

CI/CD Pipeline — DevSecOps Flow
📝 Code
Git Push
🔍 Lint
ESLint/Pylint
🧪 Test
Unit + E2E
🛡️ SAST
SonarQube
🐳 Build
Docker Image
🔒 Scan
Trivy Image
📦 Registry
Harbor/ECR
🚀 Deploy
K8s Helm
ทุก Commit ผ่าน Pipeline อัตโนมัติ: Code Quality → Security Scan → Build → Deploy — Fail Fast ถ้ามี Issue

Kubernetes Deployment Architecture (TOR ข้อ 4.8, 4.16)

Kubernetes Cluster Topology
Ingress Controller (Nginx) + TLS
*.osm.pea.co.th
Namespace: osm-prod
Production
Namespace: osm-uat
UAT/Staging
Namespace: osm-dev
Development
Pod: request-svc (2-5 replicas)
Pod: contract-svc (2-5 replicas)
Pod: payment-svc (2-3 replicas)
Pod: eval-svc
Pod: notif-svc
Pod: report-svc
Pod: audit-svc
PostgreSQL (StatefulSet, 3 replicas)
Primary + 2 Read Replica
Redis Cluster
3 nodes
Elasticsearch
3 nodes
📋 TOR ข้อ 4.16: ระบบรองรับ deploy ทั้ง Windows Server และ Ubuntu / RedHat / CentOS เนื่องจากใช้ Docker Container ที่รันได้บนทุก OS ที่มี Docker Engine

06 API & External Integration

ตาม TOR ข้อ 4.4 ต้องเชื่อมต่อ API Web Service กับระบบภายนอก 4 ระบบหลักของ PEA พร้อมรองรับการเชื่อมต่อเพิ่มเติมในอนาคต

ระบบภายนอกProtocolวัตถุประสงค์ข้อกำหนด TOR
🏢 HR Data PlatformREST APIดึงข้อมูลพนักงาน ตำแหน่ง หน่วยงานข้อ 4.4
📧 PEA Email (SMTP)SMTP/IMAPแจ้งเตือน, ส่งรายงาน, OTPข้อ 4.4, 4.10
💳 Smart Payment (SAP)REST / RFCเบิกจ่ายเงิน, e-Receipt, e-Tax Invoiceข้อ 4.4
🏛️ e-Procurement (e-GP)REST APIเชื่อมข้อมูลจัดซื้อจัดจ้างภาครัฐข้อ 2.12, 4.4
✍️ Digisign APIREST APIลงลายเซ็นดิจิทัล (Digital Signature)ข้อ 4.18
🔐 Keycloak SSOOIDC/OAuth2Single Sign-On + AD Integrationข้อ 4.12

API Gateway Architecture

API Gateway — Request/Response Flow
📱 Client
Web/Mobile
🔐 API Gateway
Auth + Rate Limit
🔀 Service Router
Path-based routing
⚙️ Microservice
Business Logic
💾 Database
PostgreSQL
// ตัวอย่าง API Endpoint Structure (RESTful) GET /api/v1/requests // รายการคำขอจ้างทั้งหมด POST /api/v1/requests // สร้างคำขอจ้างใหม่ GET /api/v1/requests/:id // รายละเอียดคำขอจ้าง PUT /api/v1/requests/:id/approve // อนุมัติคำขอจ้าง POST /api/v1/contracts // สร้างสัญญา POST /api/v1/payments // สร้างใบเบิกจ่าย POST /api/v1/evaluations // บันทึกผลประเมิน GET /api/v1/reports/monthly // รายงานประจำเดือน POST /api/v1/signature/sign // ส่งลงนามดิจิทัล (Digisign) // Authentication POST /api/v1/auth/login // Login (Local) GET /api/v1/auth/sso/callback // SSO Callback (Keycloak) POST /api/v1/auth/refresh // Refresh Token

07 Monitoring, Logging & Alerting

ตาม TOR ข้อ 4.15 (Monitoring Integration) และข้อ 4.20 (Audit Log) ระบบต้องมีการ Monitor ครบถ้วนทั้ง Infrastructure, Application, และ Business Metrics

Observability Stack — Metrics, Logs, Traces
📊
Metrics
Prometheus + Grafana
• CPU / Memory / Disk
• Request latency (P50/P95)
• Error rate per service
• Active connections
• Custom business metrics
📋
Logs
ELK Stack (Elasticsearch + Kibana)
• Application logs
• Audit trail (TOR 4.20)
• Error tracking
• Security events
• API request/response log
🔗
Traces
Jaeger / OpenTelemetry
• Distributed tracing
• Request flow mapping
• Service dependency
• Latency breakdown
• Error propagation

🔔 Alert Rules (TOR ข้อ 4.17)

AlertConditionช่องทางแจ้งSeverity
CPU HighCPU > 80% for 5 minPEA Email + LineCritical
Memory HighMemory > 85%PEA Email + LineCritical
Error Rate>1% of requests 5xxPEA Email + GrafanaWarning
Disk FullDisk > 90%PEA EmailCritical
Pod CrashLoopPod restart > 3 in 5 minPEA Email + LineCritical
สัญญาใกล้หมด30 วันก่อนหมดอายุPEA Email + In-appInfo
SSL Cert Expiry30 วันก่อนหมดPEA EmailWarning

08 Deployment Recommendation

จากการวิเคราะห์ TOR ข้อ 22 (สถานที่ส่งมอบ: 200 ถ.งามวงศ์วาน นนทบุรี) และข้อ 4.8 (Kubernetes) แนะนำ 3 ทางเลือกในการ Deploy โดยเรียงตามความเหมาะสม

✅ แนะนำ: Option A — PEA On-Premise Data Center + Kubernetes
เหมาะสมที่สุดเนื่องจาก PEA มี Data Center เอง ข้อมูลอยู่ภายในองค์กร ตอบ Security/PDPA ได้ดี และเป็นไปตาม TOR

Option A: PEA On-Premise (แนะนำ) ⭐

On-Premise Deployment Architecture
🌐 Internet / PEA Network
Users access via browser
🛡️ PEA Firewall + WAF
Network perimeter security
⚖️ Load Balancer (F5 / HAProxy)
TLS termination + traffic routing
☸️ Kubernetes Cluster (3 Master + 3 Worker Nodes)
K8s v1.28+ — Rancher / kubeadm
📦 OSM Application Pods (9 Services × 2-5 replicas)
🔐 Keycloak Pod + PostgreSQL
💾 Storage: SAN/NAS + PostgreSQL (Primary+Replica) + Redis + Elasticsearch

Server Specification (Minimum)

RoleจำนวนCPURAMStorageOS
K8s Master34 vCPU8 GB100 GB SSDUbuntu 22.04 / RHEL 8
K8s Worker38 vCPU16 GB200 GB SSDUbuntu 22.04 / RHEL 8
PostgreSQL Primary18 vCPU32 GB500 GB SSDUbuntu 22.04
PostgreSQL Replica24 vCPU16 GB500 GB SSDUbuntu 22.04
Redis + Elasticsearch14 vCPU16 GB200 GB SSDUbuntu 22.04
GitLab CI Runner14 vCPU8 GB200 GB SSDUbuntu 22.04
รวม11 VMs60 vCPU144 GB3 TB

Option B: Hybrid (On-Premise + Cloud)

🏢 On-Premise

Database (PostgreSQL), Keycloak SSO, File Storage — ข้อมูลสำคัญอยู่ภายในเครือข่าย PEA

☁️ Cloud (AWS/Azure/GCP)

Application Pods (EKS/AKS/GKE), CDN, Monitoring — ใช้ managed K8s ลดภาระดูแล infra

Option C: Full Cloud (PDPA-Compliant)

Deploy ทั้งหมดบน Cloud Provider ที่มี Data Center ใน Thailand (AWS Bangkok / Azure Southeast Asia) — เหมาะกรณี PEA ไม่มี On-Premise K8s infrastructure พร้อม

🚀 Deployment Process (TOR ข้อ 4.1.4)

Deployment Pipeline — Zero-Downtime Rolling Update
📝 Merge to
main branch
🧪 Auto Test
+ Scan
🐳 Build
Docker Image
📦 Deploy
to UAT
✅ UAT
Approval
🚀 Rolling
Deploy Prod
Zero-downtime: K8s Rolling Update ทำให้ Pod ใหม่ขึ้นก่อน แล้วค่อย terminate Pod เก่า — ผู้ใช้ไม่รู้สึกว่าระบบ restart

09 Disaster Recovery & Backup

Backup Strategy

ประเภทความถี่Retentionวิธีการ
Database (Full)ทุกวัน 02:0030 วันpg_dump + compression → NAS
Database (WAL)ทุก 5 นาที7 วันWAL archiving + PITR
File Storageทุกวัน90 วันrsync to backup NAS
K8s Configทุกวัน30 วันVelero backup → S3
GitLab Repoทุกวันไม่จำกัดGit mirror to DR site

Recovery Objectives

RPO (Recovery Point Objective)

5 นาที
สูญเสียข้อมูลไม่เกิน 5 นาที (WAL streaming)

RTO (Recovery Time Objective)

30 นาที
กู้คืนระบบเต็มรูปแบบภายใน 30 นาที

HA (High Availability)

99.5%
Uptime ≥ 99.5% ตลอดปี (downtime ≤ 43.8 ชม.)

📌 หมายเหตุ: เอกสารฉบับนี้เป็นส่วนหนึ่งของข้อเสนอทางเทคนิค สำหรับรายละเอียดเพิ่มเติมในแต่ละหัวข้อ สามารถจัดทำเอกสาร Technical Specification แยกได้ตามที่ PEA ต้องการ