อธิบาย Legacy Code ให้ทีมใหม่เข้าใจเร็ว พร้อม Flag จุดเสี่ยงและ Tech Debt
ให้ AI วิเคราะห์โค้ดเก่าที่ซับซ้อน สรุปการทำงาน ชี้จุดเสี่ยง และจัดทำ tech debt log พร้อม effort estimate เพื่อให้ทีมใหม่เริ่มต้นได้อย่างปลอดภัยและมีทิศทางชัดเจน

คัดลอกพรอมต์ฉบับมีตัวแปร {{...}} ไปแก้ไขในเครื่องมือของคุณเอง
ตัวอย่างผลลัพธ์ที่จะได้
ก่อนเริ่มลงมือปรับพรอมต์ ดูตัวอย่างผลลัพธ์ที่คุณจะได้จริงเพื่อให้แน่ใจว่าพรอมต์นี้ตรงกับงานที่ต้องการ
1. Overview
โมดูลนี้จัดการการดึงข้อมูลผู้ใช้และประมวลผล order สำหรับระบบที่น่าจะเป็น e-commerce โดยเชื่อมต่อฐานข้อมูล MySQL โดยตรง ดีซีเรียไลซ์ payload ของ order และคำนวณส่วนลดตามหมวดหมู่สินค้า โดยรวมแล้วเป็น utility script ยุคแรกที่ยังไม่ถูก refactor ให้เป็น service layer ที่ถูกต้อง
2. Key Components
get_user_data(user_id)— ดึงข้อมูลทุก column ของผู้ใช้จาก tableusersด้วย user ID ที่รับมาprocess_orders(orders)— วนลูปรายการ order และดีซีเรียไลซ์payloadแต่ละรายการด้วยpicklecalculate_discount(items)— คำนวณส่วนลดรวมโดยเปรียบเทียบทุก item กับทุก item อื่นในรายการ
3. Data Flow
- Caller ส่ง
user_id(integer) เข้าget_user_data - ฟังก์ชันเปิด DB connection ใหม่ทุกครั้งที่ถูกเรียก แล้วสร้าง SQL string โดยต่อ string ตรงๆ
- ผลลัพธ์ถูก return เป็น tuple of tuples โดยไม่มี ORM หรือ DTO
process_ordersรับ list of dicts โดยแต่ละpayloadเป็น binary blob ที่ผ่าน pickle- Object ที่ดีซีเรียไลซ์แล้วถูก append เข้า
resultsหากเกิด error ทุกชนิดจะถูกละเว้นเงียบๆ
ปรับให้เข้ากับงานของคุณ
แก้ค่าตัวแปรด้านล่าง พรอมต์ฉบับสมบูรณ์จะอัปเดตอัตโนมัติ พร้อมคัดลอกไปวางใน Claude หรือ ChatGPT ได้ทันที
ภาษาโปรแกรมหลักของ codebase เช่น Python, TypeScript, Java, Go
วาง source code ที่ต้องการให้ AI วิเคราะห์ตรงนี้
Analyse the code below and produce a structured report with the following sections:
## 1. Overview (2–4 sentences)
Summarise what this code does and its role in the system.
## 2. Key Components
List the main functions, classes, or modules. For each, write one sentence explaining its responsibility.
## 3. Data Flow
Describe how data enters, transforms, and exits this code. Use a numbered step list.
## 4. Risk Flags
Identify any of the following and explain the specific risk for each:
- Silent failures / bare except / swallowed errors
- Race conditions or concurrency issues
- Hard-coded credentials, secrets, or environment-specific values
- Unbounded loops or O(n²)+ complexity hotspots
- Direct database calls in business logic (no abstraction layer)
- Missing null/boundary checks
## 5. Tech Debt Log
For each debt item, provide:
| # | Location | Issue | Suggested Fix | Effort |
|---|----------|-------|---------------|--------|
(Effort: Low / Medium / High)
## 6. Onboarding Tips
Three bullet points a new developer must know before touching this code.
Constraints:
- Be specific: reference line numbers or function names whenever possible.
- Do not rewrite the code. Explain and flag only.
- If something is ambiguous or requires runtime context to judge safely, say so explicitly rather than guessing.
```CODE TO REVIEW```
import MySQLdb
import pickle
DB_HOST = "192.168.1.100"
DB_USER = "root"
DB_PASS = "P@ssw0rd123"
def get_user_data(user_id):
db = MySQLdb.connect(DB_HOST, DB_USER, DB_PASS, "users_db")
cursor = db.cursor()
cursor.execute("SELECT * FROM users WHERE id = " + str(user_id))
rows = cursor.fetchall()
db.close()
return rows
def process_orders(orders):
results = []
for order in orders:
try:
data = pickle.loads(order['payload'])
results.append(data)
except:
pass
return results
def calculate_discount(items):
total = 0
for i in range(len(items)):
for j in range(len(items)):
if items[i]['category'] == items[j]['category']:
total += items[i]['price'] * 0.1
return total
```
เข้าใจเทคนิคที่ซ่อนอยู่
คลิกที่ส่วนไฮไลต์ในพรอมต์เพื่อกระโดดไปดูคำอธิบายเทคนิคแต่ละจุด ใช้ความเข้าใจนี้เพื่อปรับพรอมต์อื่นของคุณเองในภายหลัง
Analyse the code below and produce a structured report with the following sections:
## 1. Overview (2–4 sentences)
Summarise what this code does and its role in the system.
## 2. Key Components
List the main functions, classes, or modules. For each, write one sentence explaining its responsibility.
## 3. Data Flow
Describe how data enters, transforms, and exits this code. Use a numbered step list.
## 4. Risk Flags
Identify any of the following and explain the specific risk for each:
- Silent failures / bare except / swallowed errors
- Race conditions or concurrency issues
- Hard-coded credentials, secrets, or environment-specific values
- Unbounded loops or O(n²)+ complexity hotspots
- Direct database calls in business logic (no abstraction layer)
- Missing null/boundary checks
## 5. Tech Debt Log
For each debt item, provide:
| # | Location | Issue | Suggested Fix | Effort |
|---|----------|-------|---------------|--------|4
(Effort: Low / Medium / High)
## 6. Onboarding Tips
Three bullet points a new developer must know before touching this code.
Constraints:
- Be specific: reference line numbers or function names whenever possible.
- Do not rewrite the code. Explain and flag only.5
- If something is ambiguous or requires runtime context to judge safely, say so explicitly rather than guessing.6
```CODE TO REVIEW```
{{code}}
```
แตะส่วนที่ไฮไลต์เพื่อดูคำอธิบายเทคนิคแต่ละจุด · {{ }} คือตัวแปรที่ปรับได้
"You are a senior software engineer conducting a legacy code onboarding review."
การกำหนด role ที่ชัดเจนทำให้ AI เลือกมุมมองและน้ำเสียงที่เหมาะสม แทนที่จะตอบแบบกว้างๆ AI จะวิเคราะห์ในฐานะวิศวกรผู้มีประสบการณ์ที่เข้าใจความเสี่ยงในโค้ดจริง
"Your audience is a new team member who is familiar with {{programming_language}} but has never seen this codebase before."
การบอก audience ให้ AI ทราบช่วยปรับระดับของคำอธิบายให้พอดี ไม่ต้องอธิบาย syntax พื้นฐาน แต่ต้องอธิบาย business logic และ convention เฉพาะของ codebase นี้
"## 1. Overview (2–4 sentences) ## 2. Key Components ## 3. Data Flow ## 4. Risk Flags ## 5. Tech Debt Log ## 6. Onboarding Tips"
การกำหนด section ทั้ง 6 ล่วงหน้าบังคับให้ AI ครอบคลุมทุกมิติที่จำเป็นสำหรับ onboarding และทำให้ output สามารถนำไปใส่ใน wiki หรือ PR description ได้ทันทีโดยไม่ต้องแก้ไขโครงสร้าง
"| # | Location | Issue | Suggested Fix | Effort | |---|----------|-------|---------------|--------|"
การให้ table template พร้อม column headers บังคับให้ AI สรุป tech debt ในรูปแบบที่ประเมินงานได้จริง แทนที่จะเขียนเป็น paragraph ยาวที่ยากต่อการ prioritise
"Do not rewrite the code. Explain and flag only."
การห้ามชัดเจนป้องกัน AI จากการ hallucinate โดยการเขียน refactored version ที่อาจมี bug ใหม่หรือเปลี่ยน behavior โดยไม่ตั้งใจ ทำให้ผลลัพธ์ใช้เป็น review document ได้อย่างปลอดภัย
"If something is ambiguous or requires runtime context to judge safely, say so explicitly rather than guessing."
คำสั่งนี้ลด hallucination โดยตรง เพราะ AI มักมีแนวโน้มตอบให้ครบแม้ไม่มีข้อมูลเพียงพอ การบอกให้ยอมรับความไม่แน่ใจทำให้ผลลัพธ์น่าเชื่อถือกว่าสำหรับการตัดสินใจด้านวิศวกรรม
เห็นความต่างระหว่างพรอมต์ทั่วไปกับพรอมต์ที่ใช้เทคนิค
คนส่วนใหญ่เริ่มต้นด้วยคำสั่งสั้น ๆ แบบพรอมต์ที่ใช้กันทั่วไป แต่ผลลัพธ์มักไม่ตรงใจและต้องถามซ้ำหลายรอบ พรอมต์แบบที่ใช้เทคนิคข้างต้นช่วยแก้ปัญหานี้
อธิบาย code นี้ให้หน่อย
กำหนด role เป็น senior engineer, ระบุ audience และ language ที่รู้จัก, บังคับ output เป็น 6 sections พร้อม risk flags และ tech debt table ที่มี effort estimate, ห้าม rewrite code และสั่งให้ยอมรับความไม่แน่ใจอย่างชัดเจน


