Iii Architecture Patterns

作者 iii-hqf95eab270f73无许可证18K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Use when composing iii primitives into backend architectures: durable workflows, reactive backends, agentic pipelines, event-driven CQRS, effect pipelines, and trigger-transform-action automation.

AI 生成的概览

指导选择并实现 iii 后端架构模式,如持久化工作流、CQRS 和智能体流水线。

功能
该技能将后端需求映射到 iii 架构模式,包括持久化工作流、响应式后端、智能体后端、事件驱动 CQRS、效果流水线和触发器-转换-动作自动化。它提供模式映射表、选择规则,以及 TypeScript、Python 和 Rust 的代码示例,展示如何组合函数、触发器、工作器、状态、队列、流和发布/订阅等 iii 原语。它产出的是架构指导与实现草图,而非可直接运行的产物。
适用场景
当任务规模超过单个函数或触发器、需要完整后端模式时使用。它适合描述产品行为的请求,例如工作流、智能体系统、响应式应用、CQRS、效果流水线或自动化链。它不适用于精确的触发器配置、引擎配置或特定包的 SDK 语法,这些由其他技能覆盖。
运行要求
不附带脚本,仅为说明性指令。示例假定存在 iii 运行时与 SDK(TypeScript 用 iii-sdk,Python 用 iii,Rust 用 iii_sdk),以及正在运行的 iii 工作器端点,例如 ws://localhost:49134。

Architecture Patterns

Use this skill when the task is larger than one function or trigger. Pick the pattern from the requirement, then implement it with Function, Trigger, Worker, state, queues, streams, and pub/sub.

Pattern Map

RequirementPatterniii shape
Sequential work with retries, DLQ, step trackingDurable workflowFunctions chained through named queues, progress in state
Keep views, metrics, cache, or clients in syncReactive backendState triggers plus stream/pubsub side effects
Specialized AI agents hand work to each otherAgentic backendOne function per agent, queue handoffs, shared state
Commands publish events and projections update independentlyEvent-driven CQRSCommand functions, event log in state, subscribe triggers
Pure, traceable compositionEffect pipelineSmall functions composed synchronously with trigger()
Webhook/cron automation chainsLow-code automationTrigger, transform, action nodes chained by enqueue

Durable Workflow

Use named queues when steps need different retry, FIFO, or concurrency policy.

TypeScript

typescript
import { registerWorker, TriggerAction } from "iii-sdk";
const iii = registerWorker("ws://localhost:49134", { workerName: "order-workflow" });
async function track(orderId: string, step: string, status: string) {  await iii.trigger({    function_id: "state::update",    payload: { scope: "orders", key: orderId, ops: [{ type: "merge", path: ["steps"], value: { [step]: status } }] },  });}
iii.registerFunction("orders::validate", async (order) => {  await track(order.id, "validate", "done");  return iii.trigger({    function_id: "orders::charge",    payload: order,    action: TriggerAction.Enqueue({ queue: "order-payment" }),  });});
iii.registerFunction("orders::charge", async (order) => {  await track(order.id, "payment", "done");  return iii.trigger({    function_id: "orders::ship",    payload: order,    action: TriggerAction.Enqueue({ queue: "order-ship" }),  });});

Python

python
from iii import register_worker
iii = register_worker("ws://localhost:49134")
def track(order_id, step, status):    iii.trigger({        "function_id": "state::update",        "payload": {            "scope": "orders",            "key": order_id,            "ops": [{"type": "merge", "path": ["steps"], "value": {step: status}}],        },    })
def validate(order):    track(order["id"], "validate", "done")    return iii.trigger({        "function_id": "orders::charge",        "payload": order,        "action": {"type": "enqueue", "queue": "order-payment"},    })
iii.register_function("orders::validate", validate)

Rust

rust
use iii_sdk::TriggerAction;use iii_sdk::protocol::TriggerRequest;use serde_json::json;
async fn enqueue_charge(iii: iii_sdk::IIIClient, order: serde_json::Value) -> Result<serde_json::Value, iii_sdk::Error> {    iii.trigger(TriggerRequest {        function_id: "state::update".into(),        payload: json!({            "scope": "orders",            "key": order["id"],            "ops": [{ "type": "merge", "path": ["steps"], "value": { "validate": "done" } }]        }),        action: None,        timeout_ms: None,    }).await?;
    iii.trigger(TriggerRequest {        function_id: "orders::charge".into(),        payload: order,        action: Some(TriggerAction::Enqueue { queue: "order-payment".into() }),        timeout_ms: None,    }).await}

Reactive Backend

Use state triggers when the requirement says "after create/update, do this", "avoid polling", or "push live updates".

typescript
iii.registerFunction("todos::on-change", async (event) => {  await iii.trigger({    function_id: "stream::send",    payload: { stream_name: "todos-live", group_id: "default", data: event.new_value },    action: TriggerAction.Void(),  });});
iii.registerTrigger({  type: "state",  function_id: "todos::on-change",  config: { scope: "todos" },});

Agentic Backend

Model each agent as a function with one responsibility. Store shared context in state and hand off work through named queues.

typescript
iii.registerFunction("agents::researcher", async (task) => {  await iii.trigger({    function_id: "state::set",    payload: { scope: "research", key: task.id, value: { findings: [] } },  });  return iii.trigger({    function_id: "agents::critic",    payload: task,    action: TriggerAction.Enqueue({ queue: "agent-tasks" }),  });});

Event-Driven CQRS

Commands validate and publish domain events. Projections subscribe independently and write query-optimized state.

typescript
iii.registerFunction("cmd::add-inventory-item", async (input) => {  const event = { type: "inventory.item-added", itemId: input.itemId, quantity: input.quantity };  await iii.trigger({    function_id: "state::set",    payload: { scope: "inventory-events", key: `${Date.now()}-${input.itemId}`, value: event },  });  await iii.trigger({ function_id: "publish", payload: { topic: event.type, data: event } });  return { accepted: true };});
iii.registerTrigger({  type: "subscribe",  function_id: "proj::inventory-list",  config: { topic: "inventory.item-added" },});

Selection Rules

  • Use sync composition for short effect pipelines where the caller needs the final result.
  • Use enqueue for unreliable, slow, or must-complete steps.
  • Use pub/sub for independent fan-out where each subscriber can tolerate event-style delivery.
  • Use state triggers for derived views and side effects that should run automatically after writes.
  • Use cron triggers for scheduled maintenance and periodic starts.
  • Keep each function small enough to test independently.

When to Use

  • Use this skill for complete backend patterns: workflows, agentic systems, reactive apps, CQRS, effect pipelines, and automation chains.
  • Use this when the request describes product behavior rather than a single SDK API call.

Boundaries

  • For exact trigger config, function registration syntax, custom triggers, channels, and HTTP-invoked functions, use iii-core-primitives.
  • For engine ports, adapters, engine-owned workers, and RBAC (rbac-proxy), use iii-engine-config; queue retry and FIFO policy live with the queue worker's docs.
  • For package-specific SDK syntax, use iii-sdk-reference.
  • Worker-backed capability details live with the worker docs, not as top-level iii skills.

来源与署名

来源:iii-hq/iii位于skills/iii-architecture-patterns提交f95eab2

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架