v2.0.0 • CodeUChain Edition

CodeUChain

The same elegant patterns, expressed in every programming language. A universal architecture that makes complex systems simple, beautiful, and maintainable across Python, Go, JavaScript, C#, Rust, and beyond.

Core Concepts

Four building blocks. Learn them once, use them in any language.

📦

State

Immutable key-value container that carries data through your pipeline.

ctx = State({ user_id: 101, role: "admin" })
ctx.get("role") // "admin"
ctx.set("status", "active") // returns new State

Thread-safe. Each .set() returns a new State — no mutation, no surprises.

🔗

Link

A single unit of work. Takes State in, returns State out. One job, done well.

Link("validate", ctx => {
  if (!ctx.get("email").includes("@"))
    throw Error("bad email");
  return ctx;
})

Each Link lives in its own file. Easy to test, reuse, and reason about.

⛓️

Chain

Composes Links into an ordered pipeline. Handles execution and error propagation.

chain = Chain()
  .add(validateEmail)
  .add(hashPassword)
  .add(saveUser)
result = chain.execute(state)

If any Link throws, the Chain stops and the error is available on the result.

🪝

Hook

Observes execution without modifying business logic. Runs alongside the Chain.

hook.before(ctx => log("starting"))
hook.after(ctx => log("done"))
hook.onError(err => alert(err))

Logging, metrics, caching — without touching your Link code.

How It Flows

State → Link 1 → Link 2 → Link 3 → Result
         ↑ Hook observes each step ↑

Developer Benefits

Practical advantages you get from day one

🧪

Testable by Default

Each Link is a pure function: State in, State out. Mock nothing — just pass test data.

result = myLink.call(State({ input: "test" }))
assert result.get("output") == expected
🔄

Reusable Components

Write a Link once, drop it into any Chain. Build a library of battle-tested building blocks.

orderChain.add(validateEmail) // reuse
signupChain.add(validateEmail) // reuse
🌍

One Pattern, Every Language

Same State → Link → Chain model in Python, Go, TypeScript, C#, Rust, Java, and C++.

// Learn once, apply everywhere
chain.add(link).execute(state)
🛡️

Contained Impact

Changes to one Link cannot break another. Errors stop the Chain without side effects.

// Link 2 fails? Links 3-5 never run.
// State stays immutable throughout.
📖

Self-Documenting

A Chain reads like a checklist. New developers understand the flow in seconds.

Chain: ValidateInput
  → EnrichData → Save → Notify

Opt-In Type Safety

Start untyped for speed. Add generics when you need compile-time guarantees.

Link[UserInput, UserOutput]
State[T].insertAs<U>(k, v)
🤖 Built for AI Agents

AI-Ready Architecture

The same structure that helps humans reason about code helps AI assistants generate, refactor, and extend it.

🎯

Predictable Patterns

AI models thrive on consistent structure. Every Link follows the same contract, so generation is reliable.

// AI immediately understands the flow:
ValidateInput → CheckCredentials → GenerateToken → LogSuccess
🔄

Incremental Generation

AI builds step by step, just like a developer:

Step 1: Generate ValidateEmail link
Step 2: Generate SaveToDatabase link
Step 3: Compose into UserRegistration chain
📚

Self-Documenting Structure

// The Chain tells the whole story:
const UserAuthChain = Chain
  .add(ValidateCredentials)  // Check username/password
  .add(GenerateJWT)        // Create auth token
  .add(LogAuthEvent)        // Record the login
  .add(HandleAuthFailure)    // Deal with failures

AI reads Chain composition the same way humans do: clear intent, clear order, clear error handling.

Why It Works

Consistent patterns for reliable AI output

Type contracts for safe AI collaboration

Clear structure for AI-assisted refactoring

Quick Start

Install and write your first chain in minutes

📦 Install

pip install codeuchain # Python npm install codeuchain # JavaScript cargo add codeuchain # Rust go get github.com/codeuchain/codeuchain/go # Go

🧠 Mental Model

State The data box flowing through your pipeline
Link One focused unit of work — receives State, returns State
Chain Ordered sequence of Links — runs them in order
Hook Parallel observer — logging, metrics, caching

⚡ Your First Chain

# Universal pattern — same in every language
state  = new State({ user_id: 101 })

chain = new Chain()
  .add(Link('fetch',   ctx -> fetch_user(ctx)))
  .add(Link('auth',    ctx -> check_role(ctx, 'admin')))
  .add(Link('process', ctx -> run_business_logic(ctx)))

result = chain.execute(state)

if result.error:
    handle_failure(result.error)
else:
    print(result.get('output'))

Explore Language Implementations

CodeUChain is available in multiple programming languages, each with full feature parity and native idioms.

/Users/jwink/Documents/github/codeuchain/docs/components/floating-navigation.html