v2.0.0 β€’ Java Edition

Java

Robust, scalable chains for enterprise applications. The power of Java's ecosystem meets modern architectural patterns.

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

io.codeuchain codeuchain 0.3.0

🧠 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

Chain chain = new Chain()
  .addLink(new Link("parse", ctx -> {
    ctx.set("body", "{ data: ... }");
    return ctx;
  }))
  .addLink(new Link("validate", ctx -> {
    String body = (String) ctx.get("body");
    if (body == null) ctx.error = new Exception("No body");
    return ctx;
  }));

State result = chain.execute(new State().set("raw", "..."));
System.out.println(result.error != null ? "Failed" : "Success");

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