คดีที่ 26: ผ่าพิมพ์เขียว ruflo — ถอดรหัสสถาปัตยกรรม AI ยุคใหม่ (71.9k Stars)
🕵️♂️ ปมคดีและที่มา: ทำไมวงการถึงต้องจับตามอง?
ทำไมโปรเจกต์ ruvnet/ruflo ถึงได้รับความนิยมและมียอดกด Star ทะลุ 71.9k บน GitHub?
เบื้องหลังความสำเร็จนี้ไม่ใช่แค่การเป็นเครื่องมือสำเร็จรูป แต่คือการแก้ปัญหาทางวิศวกรรมที่เจ็บปวด: สถาปัตยกรรมโอเพ่นซอร์สเทคโนโลยี AI ยุคใหม่
📊 ตารางเปรียบเทียบเชิงลึก: วิธีดั้งเดิม vs สถาปัตยกรรมสมัยใหม่
| มิติการเปรียบเทียบ | สถาปัตยกรรมเดิม (Traditional Approaches) | สถาปัตยกรรม {clean_name} |
|---|---|---|
| ความยืดหยุ่น | ผูกติดกับ Cloud Provider รายใหญ่ | Modular Engine รองรับทั้ง Local และ API มาตรฐาน |
| ประสิทธิภาพ Token | บริโภค Context สูง ขาดการแคชที่ดี | ออกแบบ Layer แยก Context และ Execution ออกจากกัน |
| ความง่ายในการ Integrate | ต้องเขียน Custom Glue Code มหาศาล | เชื่อมต่อผ่าน Standardized Protocols (MCP/REST) |
🔍 แกะรอยสถาปัตยกรรมระบบ (Deep Architecture Breakdown)
พิมพ์เขียวสถาปัตยกรรมเบื้องหลังระบบนี้ ถูกออกแบบมาเพื่อแก้ปัญหาคอขวดด้านประสิทธิภาพและความปลอดภัย:
flowchart TD
subgraph 👤 User & Agent Layer
User["👨💻 Developer / AI Agent"] -->|"Task / Intent"| Router["⚡ Protocol Router (MCP / CLI)"]
end
subgraph 🧠 Core Intelligence Engine
Router --> Engine["⚙️ ruflo Engine"]
Engine --> Decision["🎯 Intelligent Decision Core"]
Engine --> Memory["💾 Persistent Session & Cache"]
end
subgraph 🛠️ Execution & Tooling
Decision --> Tools["🔧 Specialized Execution Modules"]
Tools --> Output["📊 Filtered & Optimized Results"]
end
Output -->|"Clean Context"| User
3 เสาหลักของการออกแบบระบบ (System Design Pillars):
- Decoupled Execution & Protocol-First: สื่อสารผ่านโปรโตคอลมาตรฐาน ทำให้ถอดเปลี่ยนสมองกล (LLM) ได้อิสระโดยไม่ต้องเขียน Logic การเชื่อมต่อ Tool ใหม่
- Context & Token Economy: ป้องกันไม่ให้ Output ดิบขนาดมหึมาทะลักเข้าสู่หน้าต่างบริบท ช่วยลดอาการ Hallucination และประหยัดค่าใช้จ่าย
- Resilience & State Continuity: มีกลไก Handle Exception และบันทึก State ความคืบหน้า เพื่อให้การทำงานแบบ Multi-step สามารถรันต่อได้จนจบภารกิจ
💻 ผ่ารหัสลับของจริง (Source Code Autopsy)
จากการผ่าโครงสร้าง Repo ของจริง เราพบชิ้นส่วนโค้ดสำคัญที่เป็นหัวใจของการขับเคลื่อนระบบ:
📄 ผ่าไฟล์จริง: package.json
{
"name": "claude-flow",
"version": "3.40.0",
"workspaces": [
"v3/@claude-flow/codex",
"v3/@claude-flow/mcp",
"v3/@claude-flow/plugin-agent-federation",
"v3/@claude-flow/security"
],
"description": "Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
"main": "dist/index.js",
"type": "module",
"bin": {
"claude-flow": "bin/cli.js"
},
"homepage": "https://github.com/ruvnet/claude-flow#readme",
"bugs": {
"url": "https://github.com/ruvnet/claude-flow/issues",
"email": "[email protected]"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/ruvnet"
},
"files": [
"bin/**",
"v3/@claude-flow/cli/bin/**",
"v3/@claude-flow/cli/dist/**/*.js",
"v3/@claude-flow/cli/dist/**/*.d.ts",
"!v3/@claude-flow/cli/dist/**/*.map",
"v3/@claude-flow/cli/package.json",
"v3/@claude-flow/cli/catalog-manifest.json",
"v3/@claude-flow/shared/dist/**/*.js",
"v3/@claude-flow/shared/dist/**/*.d.ts",
"!v3/@claude-flow/shared/dist/**/*.map",
"v3/@claude-flow/shared/package.json",
"v3/@claude-flow/guidance/dist/**/*.js",
"v3/@claude-flow/guidance/dist/**/*.d.ts",
"!v3/@claude-flow/guidance/dist/**/*.map",
"v3/@claude-flow/guidance/package.json",
".claude-plugin/**",
".claude/**",
"!.claude/**/*.db",
"!.claude/**/*.map",
"!.claude/worktrees/**",
"!.claude/projects/**",
"!.claude/scheduled_tasks.lock",
"!.claude/sessions/**",
"README.md",
"LICENSE"
],
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc",
"build:ts": "cd v3/@claude-flow/cli && npm run build || true",
"prepublishOnly": "node scripts/prepare-root-publish.mjs",
"test": "vitest",
"test:ui": "vitest --ui",
"test:security": "vitest run v3/__tests__/security/",
"lint": "cd v3/@claude-flow/cli && npm run lint || true",
"security:audit": "npm audit --audit-level high",
"security:fix": "npm audit fix",
"security:test": "npm run test:security",
"v3:domains": "npm run build:domains",
"v3:swarm": "npm run start:swarm",
"v3:security": "npm run security:audit && npm run security:test"
},
"dependencies": {
"@claude-flow/cli-core": "3.7.0-alpha.5",
"@claude-flow/codex": "3.0.3",
"@claude-flow/mcp": "3.0.0-alpha.10",
"@claude-flow/neural": "3.0.0-alpha.9",
"@claude-flow/plugin-agent-federation": "1.0.0-alpha.18",
"@claude-flow/security": "3.0.0-alpha.14",
"@claude-flow/shared": "3.0.0-alpha.8",
"@iarna/toml": "^2.2.5",
"@noble/ed25519": "2.3.0",
"@ruvector/rabitq-wasm": "0.1.0",
"ajv": "^8.20.0",
"bcryptjs": "^3.0.3",
การทำงานทางวิศวกรรม:
- โค้ดส่วนนี้ทำหน้าที่เป็นแกนกลางในการควบคุม Flow ของข้อมูล
- แยกหน้าที่การทำงานชัดเจน (Separation of Concerns) ทำให้สเกลเครื่องมือใหม่ๆ เข้าสู่ระบบได้ทันทีโดยไม่ต้องแก้ Core Engine
📄 ผ่าไฟล์จริง: Cargo.toml
[workspace]
resolver = "2"
members = [
"v3/crates/ruflo-federation-peer",
"v3/crates/ruflo-agntcy",
]
exclude = [
"v3/plugins/gastown-bridge",
]
# ruflo is primarily TypeScript; this workspace manifest exists so the
# repo-scorecard analyzer sees ruflo's Rust components (federation peer
# binary, gastown-bridge plugin) without traversing deep subdirs.
#
# `v3/plugins/gastown-bridge` is deliberately in `exclude`, not `members`:
# it declares its own nested `[workspace]` (a separate WASM-focused
# workspace — see its own Cargo.toml) for `wasm/gastown-formula-wasm` and
# `wasm/ruvector-gnn-wasm`. Cargo refuses to resolve ANY member of this
# (parent) workspace — old or new — while a listed member path is itself
# another workspace root ("multiple workspace roots found in the same
# workspace"). `exclude` keeps the directory out of Cargo's member-set
# resolution (so `cargo check`/`cargo test` on every other crate here
# works) while still leaving it in the repo tree at the same path for the
# scorecard analyzer to find.
การทำงานทางวิศวกรรม:
- โค้ดส่วนนี้ทำหน้าที่เป็นแกนกลางในการควบคุม Flow ของข้อมูล
- แยกหน้าที่การทำงานชัดเจน (Separation of Concerns) ทำให้สเกลเครื่องมือใหม่ๆ เข้าสู่ระบบได้ทันทีโดยไม่ต้องแก้ Core Engine
📄 ผ่าไฟล์จริง: CLAUDE.md
# Claude Code Configuration - Ruflo V3
> Public release train: `@claude-flow/cli`, `claude-flow`, and `ruflo`.
> Use package manifests and the registry as version truth; do not copy stale
> version or capability counts into agent guidance.
## Behavioral Rules (Always Enforced)
- Do what has been asked; nothing more, nothing less
- NEVER create files unless they're absolutely necessary for achieving your goal
- ALWAYS prefer editing an existing file to creating a new one
- NEVER proactively create documentation files (*.md) or README files unless explicitly requested
- NEVER save working files, text/mds, or tests to the root folder
- Never continuously check status after spawning a swarm — wait for results
- ALWAYS read a file before editing it
- NEVER commit secrets, credentials, or .env files
## Capability Brain and Governed Implementation
Ruflo is the coordination ledger and policy decision point. Claude Code
executes code, tests, commands, and file changes. A Ruflo coordination call
records work; it does not perform the implementation.
When registered, call
`guidance_brain({ mode: "recommend", task: "..." })` before complex Ruflo
work. Use its live registry rather than guessing tool names. Treat
`registered`, `configured`, `reachable`, `healthy`, and `authorized` as
separate facts. If unavailable, continue with compatible guidance tools, CLI
discovery, and these repository instructions.
Use this loop: recall → inspect → route → plan → execute → test → validate →
benchmark → optimize → receipt → handoff → separately authorized publish.
## File Organization
- NEVER save to root folder — use the directories below
- Use `/src` for source code files
- Use `/tests` for test files
- Use `/docs` for documentation and markdown files
- Use `/config` for configuration files
- Use `/scripts` for utility scripts
- Use `/examples` for example code
## Project Architecture
- Follow Domain-Driven Design with bounded contexts
- Keep files under 500 lines
- Use typed interfaces for all public APIs
- Prefer TDD London School (mock-first) for new code
- Use event sourcing for state changes
- Ensure input validation at system boundaries
### Key Packages
| Package | Path | Purpose |
|---------|------|---------|
| `@claude-flow/cli` | `v3/@claude-flow/cli/` | CLI entry point (26 commands) |
| `@claude-flow/codex` | `v3/@claude-flow/codex/` | Dual-mode Claude + Codex collaboration |
| `@claude-flow/guidance` | `v3/@claude-flow/guidance/` | Governance control plane |
| `@claude-flow/hooks` | `v3/@claude-flow/hooks/` | 17 hooks + 12 workers |
| `@claude-flow/memory` | `v3/@claude-flow/memory/` | AgentDB + HNSW search |
| `@claude-flow/security` | `v3/@claude-flow/security/` | Input validation, CVE remediation |
## Concurrent Automated Development
- Parallelize independent research, tests, reviews, and non-overlapping
implementation.
- Never allow two writers in one worktree. Give every writing agent an isolated
worktree and explicit file ownership.
- Read-only agents may share a checkout; writing agents may not.
- Only the integration owner edits shared manifests and lockfiles or reconciles
overlapping changes.
- Continue independent local work after spawning agents; wait only when a real
dependency blocks progress. Do not repeatedly poll.
- A lease or work claim coordinates ownership; it never grants authority.
- Bind tests, benchmarks, policy decisions, and handoffs to an exact clean
commit or immutable dirty-worktree snapshot.
- Darwin, Flywheel, MetaHarness, memory, and neural systems may propose and
evaluate candidates, but cannot self-promote or expand tools, network,
secrets, spend, concurrency, or release authority.
การทำงานทางวิศวกรรม:
- โค้ดส่วนนี้ทำหน้าที่เป็นแกนกลางในการควบคุม Flow ของข้อมูล
- แยกหน้าที่การทำงานชัดเจน (Separation of Concerns) ทำให้สเกลเครื่องมือใหม่ๆ เข้าสู่ระบบได้ทันทีโดยไม่ต้องแก้ Core Engine
📄 ผ่าไฟล์จริง: AGENTS.md
# Claude Flow V3 - Agent Guide
> **For OpenAI Codex CLI** - Agentic AI Foundation standard
> Skills: `$skill-name` | Config: `.agents/config.toml`
---
## 📢 TL;DR - READ THIS FIRST
╔═══════════════════════════════════════════════════════════════════════════╗ ║ 1. claude-flow = LEDGER (tracks state, stores memory, coordinates) ║ ║ 2. Codex = EXECUTOR (writes code, runs commands, creates files) ║ ║ 3. NEVER stop after calling claude-flow - IMMEDIATELY continue working ║ ║ 4. If you need something BUILT/EXECUTED, YOU do it, not claude-flow ║ ║ 5. ALWAYS search memory BEFORE starting: memory search –query “task” ║ ║ 6. ALWAYS store patterns AFTER success: memory store –namespace patterns║ ╚═══════════════════════════════════════════════════════════════════════════╝
**Workflow (Use MCP Tools):**
1. `memory_search(query="task keywords")` → LEARN from past patterns (score > 0.7 = use it)
2. `swarm_init(topology="hierarchical")` → coordination record (instant)
3. **YOU write the code / run the commands** ← THIS IS WHERE WORK HAPPENS
4. `memory_store(key="pattern-x", value="what worked", namespace="patterns")` → REMEMBER for next time
---
## Ruflo Policy-Governed Concurrent Codex Workflow
Ruflo is the coordination ledger and policy decision point. Codex agents are
the executors. Coordination records do not write code or run tests.
Use `guidance_brain({ mode: "recommend", task: "..." })` to select Ruflo
capabilities from the live MCP registry. A registered tool is not necessarily
configured, reachable, healthy, or authorized. If it is unavailable, continue
with compatible guidance tools, CLI discovery, and repository instructions.
1. Recall relevant AgentDB memory and ADRs.
2. Inspect source, runtime, dependencies, policy, and health.
3. Route to the smallest capable topology, agents, skills, and tools.
4. Plan acceptance criteria, safety envelope, ownership, and validation.
5. Execute with Codex workers in isolated scopes; Ruflo records coordination.
6. Test focused, regression, and failure paths.
7. Validate types, security, policy, compatibility, and artifact integrity.
8. Benchmark a source-bound candidate against a source-bound baseline.
9. Optimize only measured bottlenecks without weakening safety.
10. Bind claims and evidence into exact source/build receipts.
11. Reconcile handoffs and disclose unresolved limitations.
12. Publish only through a separately authorized release gate.
Hard invariants:
- Never run two writers in one worktree.
- Delegation may only reduce tools, servers, namespaces, network, spend,
concurrency, expiry, and depth.
- Policy denial cancels dependent work before side effects.
- MetaHarness may evaluate candidates concurrently, but only ADR-322A may
promote them and MetaHarness may never expand its own SafetyEnvelope.
- Do not commit, push, merge, release, or remove worktrees unless authorized.
- Existing installations migrate in `legacy` policy mode; use `observe` before
switching to `enforce`.
Repository harness integration:
- If tracked repository instructions define a collaboration harness, start its
session only after assigning an isolated worktree.
- Inspect existing claims, acquire exact paths/resources/ports, renew leases,
check acknowledged inbox messages at integration boundaries, and release ownership on
handoff or exit.
- A repository lease coordinates ownership; it does not grant authorization.
Protected work still requires the ADR-324/325 action capability and current
fencing epoch.
- In-memory reference adapters demonstrate semantics; they are not distributed,
restart-durable release authorities.
- Heartbeats and lease expiry establish liveness; a PID is diagnostic only.
- `HEAD` alone is not an exact source-state identity in a dirty worktree.
Release evidence must bind a clean commit or an immutable snapshot of tracked
and untracked changes.
การทำงานทางวิศวกรรม:
- โค้ดส่วนนี้ทำหน้าที่เป็นแกนกลางในการควบคุม Flow ของข้อมูล
- แยกหน้าที่การทำงานชัดเจน (Separation of Concerns) ทำให้สเกลเครื่องมือใหม่ๆ เข้าสู่ระบบได้ทันทีโดยไม่ต้องแก้ Core Engine
💰 3 พิมพ์เขียวสร้างรายได้จริงจากสถาปัตยกรรมนี้
-
Enterprise Security & Architecture Consulting (รับงานที่ปรึกษาองค์กร)
- องค์กรขนาดใหญ่ต้องการนำ AI Agent มาใช้ แต่ติดปัญหา Data Leak และการควบคุม Tool Calling
- นำสถาปัตยกรรม FastMCP / Sandboxed Context ไปติดตั้งแบบ On-premise ค่าบริการเริ่มต้น 150,000 - 300,000 บาท/โปรเจกต์
-
Specialized AI Automation Micro-SaaS (สร้างบริการเฉพาะทาง)
- พัฒนาบริการ Agent สำหรับตรวจสอบช่องโหว่เว็บ (Bug Bounty as a Service) หรือเครื่องมือคุม Context สำหรับทีม Dev
- ตั้งราคาแบบ Subscription รายเดือน ($29 - $99/เดือน/ผู้ใช้)
-
Developer Tools & Workflow Optimization Retainer
- ให้บริการตรวจสอบและ Optimize สถาปัตยกรรม Token Consumption ให้แก่บริษัท Startup หรือ Tech Agency
- ช่วยลดค่า API OpenAI / Anthropic จากหลักแสนเหลือหลักหมื่นบาทต่อเดือน โดยคิดส่วนแบ่งจากยอดเงินที่ช่วยประหยัดได้ (Cost-Saving Share 20-30%)
💬 ร่วมสืบคดีและแลกเปลี่ยนความรู้ด้าน AI Engineering กับเราได้ที่เพจ Facebook: นักสืบอัลกอริทึม
ชอบคดีนี้ไหม? ส่งต่อให้เพื่อนในวงการ Dev!
แชร์บทความวิเคราะห์สถาปัตยกรรม AI & โค้ดจริงที่นำไปใช้สร้างเงินได้ทันที
ร่วมอภิปรายคดีลับ (Case Discussion)
มีข้อสงสัย บัค หรือไอเดียต่อยอดสถาปัตยกรรมนี้? แลกเปลี่ยนกับเพื่อนสาย Dev ได้ด้านล่าง:
