อธิบาย Legacy Code ให้ทีมใหม่เข้าใจเร็ว พร้อม Flag จุดเสี่ยงและ Tech Debt
ให้ AI วิเคราะห์โค้ดเก่าที่ซับซ้อน สรุปการทำงาน ชี้จุดเสี่ยง และจัดทำ tech debt log พร้อม effort estimate เพื่อให้ทีมใหม่เริ่มต้นได้อย่างปลอดภัยและมีทิศทางชัดเจน
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
```
ถ้าคำตอบยังกว้างไป พิมพ์บอกมันตรงๆ ว่าขอเจาะจงกว่านี้ ไม่ต้องเริ่มพรอมต์ใหม่
ปรับ 2 ช่องให้ตรงกับงานของคุณ
ภาษาโปรแกรมหลักของ codebase เช่น Python, TypeScript, Java, Go
วาง source code ที่ต้องการให้ AI วิเคราะห์ตรงนี้
ผลลัพธ์ที่จะได้
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 อื่นในรายการ
ลองพรอมต์อื่นในแนวเดียวกัน
ดูพรอมต์ทั้งหมด
สร้าง Test Cases ครอบคลุมจาก Function Spec
สร้าง test suite จาก function specification ที่ครอบคลุมทั้ง happy path, edge cases และ adversarial inputs พร้อม rationale ของแต่ละ test และ runnable code ในภาษาและ framework ที่เลือก ช่วย developer เขียน test อย่างเป็นระบบและตรวจจับ bug ที่ซ่อนอยู่ได้อย่างมีประสิทธิภาพ

Code Review Checklist 5 มิติ: Correctness, Security, Performance, Style, Test Coverage
พรอมต์สำหรับ developer ที่ต้องการ code review เชิงลึก ครอบคลุม 5 มิติหลัก พร้อมระบบ status icon และ verdict สรุป ช่วยให้ review ได้ครบถ้วนและสม่ำเสมอทุกครั้ง

เขียน Architecture Decision Record (ADR) สำหรับการตัดสินใจทางเทคนิค
สร้าง ADR ที่ครบถ้วนและอ่านง่าย บันทึกบริบท ตัวเลือกที่พิจารณา เหตุผลการตัดสินใจ และ trade-off ที่ยอมรับ ช่วยให้ทีมปัจจุบันและนักพัฒนารุ่นต่อไปเข้าใจว่าทำไมจึงตัดสินใจเช่นนั้น