SiamCafe.net Blog
Technology

Midjourney Prompt Clean Architecture

midjourney prompt clean architecture
Midjourney Prompt Clean Architecture | SiamCafe Blog
2026-05-30· อ. บอม — SiamCafe.net· 9,156 คำ

Midjourney Clean Architecture

Midjourney Prompt Clean Architecture Layers Entity Use Case Interface Framework Template Engineering Quality Control Production System

LayerResponsibilityComponentsDependencies
EntityBusiness RulesPromptTemplate QualityRule ImageResultNone
Use CaseApplication LogicGeneratePrompt ValidatePrompt RateImageEntity
InterfaceAdapterController Gateway RepositoryUse Case
FrameworkExternalAPI Server Discord Bot DatabaseInterface

Entity & Use Case

# === Clean Architecture for Prompt System ===

from dataclasses import dataclass, field

# === Entity Layer ===
@dataclass
class PromptTemplate:
    id: str
    category: str
    subject_template: str
    style: str
    medium: str
    lighting: str
    composition: str
    color_palette: str
    parameters: str
    negative: str

@dataclass
class QualityRule:
    rule_id: str
    name: str
    check: str
    severity: str

@dataclass
class GeneratedPrompt:
    template_id: str
    subject: str
    full_prompt: str
    word_count: int
    quality_score: float
    violations: list = field(default_factory=list)

# === Use Case Layer ===
def generate_prompt(template: PromptTemplate, subject: str) -> GeneratedPrompt:
    parts = [
        subject,
        template.style,
        template.medium,
        template.lighting,
        template.composition,
        template.color_palette,
    ]
    prompt_text = ", ".join(p for p in parts if p)
    if template.negative:
        prompt_text += f" --no {template.negative}"
    if template.parameters:
        prompt_text += f" {template.parameters}"

    return GeneratedPrompt(
        template_id=template.id,
        subject=subject,
        full_prompt=prompt_text,
        word_count=len(prompt_text.split()),
        quality_score=0.0,
    )

# Quality Rules
rules = [
    QualityRule("QR001", "Prompt Length", "10 <= word_count <= 60", "ERROR"),
    QualityRule("QR002", "Has Style", "style ไม่ว่าง", "WARNING"),
    QualityRule("QR003", "Has Parameters", "มี --ar --v --q", "WARNING"),
    QualityRule("QR004", "No Banned Words", "ไม่มีคำต้องห้าม", "ERROR"),
    QualityRule("QR005", "Has Negative", "มี --no สำหรับ unwanted", "INFO"),
]

# Templates
templates = [
    PromptTemplate("T001", "Product Photography",
        "{product} on {surface}",
        "professional product photography",
        "studio photograph",
        "soft studio lighting, gradient background",
        "centered, eye-level, shallow depth of field",
        "clean white and neutral tones",
        "--ar 1:1 --v 6 --q 2",
        "text watermark logo"),
    PromptTemplate("T002", "Landscape",
        "{scene} in {location}",
        "cinematic landscape photography",
        "digital photograph, 8K",
        "golden hour, dramatic sky",
        "wide angle, rule of thirds",
        "warm earth tones",
        "--ar 16:9 --v 6 --q 2 --s 750",
        "people cars buildings"),
]

print("=== Templates ===")
for t in templates:
    print(f"  [{t.id}] {t.category}")
    print(f"    Style: {t.style}")
    print(f"    Params: {t.parameters}")

# Generate Example
prompt = generate_prompt(templates[0], "luxury watch on marble surface")
print(f"\n=== Generated Prompt ===")
print(f"  {prompt.full_prompt}")
print(f"  Words: {prompt.word_count}")

Interface & API

# === Interface Layer - API Controller ===

# from fastapi import FastAPI, HTTPException
# from pydantic import BaseModel
#
# app = FastAPI()
#
# class PromptRequest(BaseModel):
#     template_id: str
#     subject: str
#     overrides: dict = {}
#
# class PromptResponse(BaseModel):
#     prompt: str
#     word_count: int
#     quality_score: float
#     violations: list
#
# @app.post("/api/generate", response_model=PromptResponse)
# async def generate(req: PromptRequest):
#     template = prompt_repo.get(req.template_id)
#     if not template:
#         raise HTTPException(404, "Template not found")
#     result = generate_prompt(template, req.subject)
#     result = validate_prompt(result, rules)
#     return PromptResponse(
#         prompt=result.full_prompt,
#         word_count=result.word_count,
#         quality_score=result.quality_score,
#         violations=result.violations,
#     )

@dataclass
class APIEndpoint:
    method: str
    path: str
    description: str
    input_data: str
    output: str

endpoints = [
    APIEndpoint("POST", "/api/generate",
        "สร้าง Prompt จาก Template + Subject",
        "template_id, subject, overrides",
        "prompt, word_count, quality_score, violations"),
    APIEndpoint("POST", "/api/validate",
        "ตรวจสอบ Prompt ตาม Quality Rules",
        "prompt_text",
        "score, violations, suggestions"),
    APIEndpoint("GET", "/api/templates",
        "ดูรายการ Template ทั้งหมด",
        "category (optional filter)",
        "templates[]"),
    APIEndpoint("POST", "/api/templates",
        "สร้าง Template ใหม่",
        "category, style, medium, lighting, params",
        "template_id"),
    APIEndpoint("POST", "/api/rate",
        "ให้คะแนนผลลัพธ์ ใช้ปรับปรุง Template",
        "prompt_id, image_url, rating, feedback",
        "updated_score"),
]

print("=== API Endpoints ===")
for e in endpoints:
    print(f"  [{e.method}] {e.path}")
    print(f"    Desc: {e.description}")
    print(f"    Input: {e.input_data}")
    print(f"    Output: {e.output}")

Quality & A/B Testing

# === Prompt Quality & A/B Testing ===

@dataclass
class ABTest:
    test_id: str
    template_a: str
    template_b: str
    metric: str
    sample_size: int
    result: str

tests = [
    ABTest("AB001",
        "Cinematic + golden hour + warm tones",
        "Professional + studio lighting + neutral",
        "User Rating (1-5)",
        100,
        "Template A: 4.2 avg vs Template B: 3.8 avg → A wins"),
    ABTest("AB002",
        "--v 6 --q 2 --s 750",
        "--v 6 --q 2 --s 250",
        "Image Quality Score",
        50,
        "--s 750: sharper detail, --s 250: more creative → depends on use"),
    ABTest("AB003",
        "Multi-prompt: subject::2 style::1",
        "Single prompt: subject, style",
        "Subject Accuracy",
        75,
        "Multi-prompt 85% accuracy vs Single 72% → Multi wins"),
]

print("=== A/B Tests ===")
for t in tests:
    print(f"\n  [{t.test_id}]")
    print(f"    A: {t.template_a}")
    print(f"    B: {t.template_b}")
    print(f"    Metric: {t.metric} (n={t.sample_size})")
    print(f"    Result: {t.result}")

เคล็ดลับ

การประยุกต์ใช้ AI ในงานจริง ปี 2026

เทคโนโลยี AI ในปี 2026 ก้าวหน้าไปมากจนสามารถนำไปใช้งานจริงได้หลากหลาย ตั้งแต่ Customer Service ด้วย AI Chatbot ที่เข้าใจบริบทและตอบคำถามได้แม่นยำ Content Generation ที่ช่วยสร้างบทความ รูปภาพ และวิดีโอ ไปจนถึง Predictive Analytics ที่วิเคราะห์ข้อมูลทำนายแนวโน้มธุรกิจ

สำหรับนักพัฒนา การเรียนรู้ AI Framework เป็นสิ่งจำเป็น TensorFlow และ PyTorch ยังคงเป็นตัวเลือกหลัก Hugging Face ทำให้การใช้ Pre-trained Model ง่ายขึ้น LangChain ช่วยสร้าง AI Application ที่ซับซ้อน และ OpenAI API ให้เข้าถึงโมเดลระดับ GPT-4 ได้สะดวก

ข้อควรระวังในการใช้ AI คือ ต้องตรวจสอบผลลัพธ์เสมอเพราะ AI อาจให้ข้อมูลผิดได้ เรื่อง Data Privacy ต้องระวังไม่ส่งข้อมูลลับไปยัง AI Service ภายนอก และเรื่อง Bias ใน AI Model ที่อาจเกิดจากข้อมูลฝึกสอนที่ไม่สมดุล องค์กรควรมี AI Governance Policy กำกับดูแลการใช้งาน

Midjourney Prompt Engineering คืออะไร

เขียน Prompt สร้างภาพ Subject Style Medium Lighting Composition Color Parameters --ar --v --q --s Negative --no Multi-prompt ::

Clean Architecture คืออะไร

Entity Use Case Interface Framework Layer Dependency Rule Testable Flexible Maintainable Business Logic ไม่พึ่ง External System

ออกแบบ Prompt System อย่างไร

PromptTemplate QualityRule GeneratePrompt ValidatePrompt RateImage Controller Gateway Repository API Server Discord Bot Database

Template System ทำอย่างไร

Category Variable Preset Composition Pattern Database Version Control A/B Test Rating Product Landscape Portrait Logo Cinematic Minimal

สรุป

Midjourney Prompt Clean Architecture Entity Use Case Template Variable Quality Rules A/B Test API Gateway Repository Production System

📖 บทความที่เกี่ยวข้อง

Midjourney Prompt Microservices Architectureอ่านบทความ → Midjourney Prompt อ่านบทความ → Midjourney Prompt Hexagonal Architectureอ่านบทความ → Midjourney Prompt Monitoring และ Alertingอ่านบทความ →

📚 ดูบทความทั้งหมด →