| name | Code Scaffold |
| description | Generate โครงสร้างไฟล์ + API stubs + DB migration + test stubs จาก SystemFlow + Dev Handoff Package ไม่ใช่ full code แต่ให้ Dev มี starting point |
PMO Skill: Code Scaffold
Purpose: แปลง Dev Handoff Package เป็น boilerplate code ที่ Dev เอาไปต่อได้ทันที
ไม่ใช่ full implementation แต่ให้โครงสร้างที่ถูกต้องตั้งแต่เริ่ม
1. Prerequisites
ก่อนรัน scaffold ต้องมี:
- Dev Handoff Package (จาก
pmo-dev-handoff) — Data Model, API Spec, Component Inventory
- Tech Stack Info — language, framework, database, ORM (ถาม user ถ้ายังไม่มี)
- Coding Standards (จาก
pmo-coding-standards ถ้ามี) — naming convention, folder structure
2. Output Structure
2.1 สร้าง Folder Structure
{project-code}-scaffold/
├── README.md <- Setup instructions
├── docker-compose.yml <- Local dev environment
├── .env.example <- Environment variables template
│
├── backend/
│ ├── src/
│ │ ├── models/ <- DB models from Data Model spec
│ │ │ └── {entity}.{ext} <- One file per entity
│ │ ├── routes/ <- API routes from API Spec
│ │ │ └── {resource}.{ext} <- One file per resource
│ │ ├── services/ <- Business logic stubs
│ │ │ └── {module}.{ext} <- One file per module
│ │ ├── middleware/ <- Auth, validation, error handling
│ │ └── config/ <- DB config, app config
│ ├── tests/
│ │ ├── unit/ <- Unit test stubs
│ │ └── integration/ <- Integration test stubs
│ └── migrations/ <- DB migration files
│
├── frontend/
│ ├── src/
│ │ ├── pages/ <- Pages from Component Inventory
│ │ ├── components/ <- Shared components
│ │ ├── hooks/ <- Custom hooks
│ │ ├── services/ <- API client
│ │ └── types/ <- TypeScript interfaces
│ └── tests/
│
└── docs/
├── API.md <- API documentation (from spec)
└── DB-SCHEMA.md <- Database schema (from Data Model)
2.2 Tech Stack Templates
| Stack | Backend | Frontend | DB | ORM |
|---|
| Python + React | FastAPI / Django | Next.js / React | PostgreSQL | SQLAlchemy / Prisma |
| Node + React | Express / NestJS | Next.js / React | PostgreSQL | Prisma / TypeORM |
| Go + React | Gin / Echo | Next.js / React | PostgreSQL | GORM |
| Custom | ถาม user | ถาม user | ถาม user | ถาม user |
3. Scaffold Generation Rules
3.1 DB Models (from Data Model)
สำหรับแต่ละ entity ใน Data Model:
- สร้าง model file พร้อม fields + types + relationships
- ใส่ TODO comment ที่ต้อง implement: validation rules, computed fields
- สร้าง migration file สำหรับ initial schema
ตัวอย่าง (Python/SQLAlchemy):
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
email = Column(String(255), unique=True, nullable=False)
role = Column(String(50), nullable=False)
status = Column(String(20), default="active")
created_at = Column(DateTime, default=func.now())
3.2 API Routes (from API Spec)
สำหรับแต่ละ endpoint ใน API Spec:
- สร้าง route file พร้อม method + path + request/response schema
- ใส่ stub function ที่ return placeholder response
- ใส่ TODO comment อ้างอิง SystemFlow step ที่เกี่ยว
3.3 Frontend Pages (from Component Inventory)
สำหรับแต่ละ page ใน Component Inventory:
- สร้าง page component พร้อม layout skeleton
- ใส่ placeholder สำหรับแต่ละ component ที่ระบุใน inventory
- ใส่ TODO comment อ้างอิง Wireframe
3.4 Test Stubs
สำหรับแต่ละ module:
- สร้าง test file พร้อม describe/it blocks ตาม Test Cases จาก TaskBoard
- Happy path + Alternative + Exception cases (stub only, ยังไม่มี assertion)
4. Traceability
ทุกไฟล์ที่ generate ต้องมี header comment:
// Generated by PMO-Template Code Scaffold
// Project: {project-code}
// Source: Dev Handoff Package v{date}
// Module: {module-name} [Ref: MOM#{X}]
// TODO items reference SystemFlow steps
5. Output Location
Scaffold output บันทึกใน: {ProjectFolder}/Scaffold/
เป็น AI-Managed folder (เพิ่มใหม่ใน v2.0.0)
6. DB Scaffolding (v2.1.0)
| Artifact | รายละเอียด |
|---|
| Migration | Initial schema จาก Data Model (Prisma/Alembic/GORM/TypeORM), up + down |
| Seed | Sample data ตาม test cases, แยก dev/staging |
| Analyze | Index recommendations จาก relationships, TODO สำหรับ query optimize |
7. Service Boilerplate (v2.1.0)
| Pattern | Stub ที่สร้าง |
|---|
| Auth | JWT + refresh token + middleware |
| Email | Provider abstraction (SendGrid/SES/Resend) |
| File upload | Multipart + storage abstraction |
| Queue/Job | Async job processor (Bull/Celery) |
| Cache | Redis/Memcached abstraction |
| Logger | Structured logging (Winston/Loguru/Zap) |
8. Workflow
- อ่าน Dev Handoff Package
- ถาม tech stack ถ้ายังไม่มี
- Load
pmo-coding-standards (รวม language + security rules)
- Generate folder structure + models + routes + pages + tests
- Generate DB migrations + seed + analyze templates (v2.1.0)
- Generate service boilerplate ตามที่ handoff ระบุ (v2.1.0)
- รัน
pmo-security-scan quick check (v2.1.0)
- Log Activity Log
- แจ้ง user สรุป + จำนวนไฟล์ + TODO items