System Architecture
This document specifies the technical design, non-negotiable architectural laws, and runtime mechanics of the Shukoi framework.
1. High-Level System Topology
Shukoi acts as an abstraction bridge between declarative business actions and the heterogeneous runtime and protocol environments of modern distributed computing:
text
┌────────────────────────────────────────┐
│ Shukoi Action Engine │
│ (defineAction + Strict TypeBox) │
└───────────────────┬────────────────────┘
│
┌───────────────────────┴───────────────────────┐
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ Protocol Module A │ │ Protocol Module B │
│ (@shukoi/api) │ │ (@shukoi/mcp) │
│ • Hono REST Router │ │ • Scoped MCP Servers │
│ • OpenAPI 3.1.0 │ │ • Streamable HTTP │
│ • RFC 9457 Errors │ │ • Sterile STDIO │
│ • Stream OOM Defense │ │ • Tools/Resources/Prompts
└────────────┬────────────┘ └────────────┬────────────┘
│ │
└───────────────────────┬───────────────────────┘
▼
┌────────────────────────────────────────┐
│ 3 Runtime Adapters │
├───────────────────┬────────────────────┤
│ Cloudflare │ Edge V8 Isolates │
│ AWS Lambda │ Serverless Deadlines│
│ Self-Host │ Node/Bun + Draining│
└───────────────────┴────────────────────┘2. The Twelve Architectural Laws
- Zero-Guesswork Contracts: All action inputs, outputs, errors, and configurations are defined using
@sinclair/typeboxschemas. Input is validated at ingress; output is cleaned and validated at egress. - Zero-Hardcoding: Hardcoding timeouts, limits, URLs, or secrets is strictly forbidden. All parameters are injected via
ShukoiConfig. - Zero Memory Leaks: Unbounded global maps/sets are forbidden. Stores use bounded LRU and TTL eviction. Timers must use
.unref()or be cleared infinally. - Zero Race Conditions: Action contexts are deeply frozen (
Object.freeze). JWKS key discovery uses a Single-Flight Mutex (inFlightPromise). Concurrent mutations serialize via atomic Idempotency Locks. - Zero Zombie Processes: STDIO mode monitors
stdin(end/close),stdout(EPIPE), and parent PID. Self-host servers execute a Graceful Drain State Machine. - Strict
stdoutSterility: File Descriptor 1 (process.stdout) in STDIO mode is exclusively reserved for newline-delimited JSON-RPC 2.0 frames withdrainbackpressure handling. Application logs route toprocess.stderr. - Pure Web-Standard Core:
@shukoi/core,@shukoi/api,@shukoi/mcp/http, and@shukoi/cloudflarecontain 0node:*imports. - Isolate-Safe Adaptive Validation: Validator probes
new Functioncapability (SUPPORTS_JIT), using JITTypeCompilerin Node/Bun and falling back to ASTValue.Checkin Cloudflare Workers. - Stream-Level Defense-in-Depth: Bodies read via bounded stream byte-counter aborting immediately at
maxBodyByteswith HTTP 413. Inputs enforceadditionalProperties: false, prototype stripping, and depth limits. - Output Data Sanitization: Handler returns pass through
Value.Clean(outputSchema, result)before validation, stripping unexposed ORM fields. - Protocol-Agnostic Business Logic: Handlers interact only with typed input and
ActionExecutionContext. Never touch raw HTTP Request/Response or JSON-RPC envelopes inside action logic. - Composite Cancellation & Deadline Propagation: Every action receives a unified
AbortSignalcombining caller disconnect, timeout, and container deadline.
For deeper exploration of these design decisions, read the Architecture Decision Records (ADRs).