Skip to content

High-performance, deterministic MVU for TypeScript. Effect-safe, replayable, and battle-tested.

License

Notifications You must be signed in to change notification settings

bitkojine/causaloop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

46 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

      ___           ___
     /\  \         /\  \
    /::\  \       /::\  \
   /:/\:\  \     /:/\:\  \    CAUSALOOP
  /:/  \:\  \   /:/  \:\  \   DETERMINISM = TRUE
 /:/__/ \:\__\ /:/__/ \:\__\  ENTROPY = 0.0%
 \:\  \ /:/  / \:\  \ /:/  /  [LIVE-SRC]
  \:\  /:/  /   \:\  /:/  /
   \:\/:/  /     \:\/:/  /
    \::/  /       \::/  /
     \/__/         \/__/

Causaloop

A production-grade TypeScript ecosystem for deterministic, effect-safe MVU applications.

CI E2E Tests Stress Tests License: MIT


๐Ÿง What is Causaloop?

In modern web development, managing state and side effects often leads to unpredictable "butterfly effects" in your UI. Causaloop provides the architectural gravity to keep your app grounded.

By strictly enforcing The Elm Architecture (TEA) in TypeScript, Causaloop ensures that your business logic remains pure, your side effects are manageable data, and your bugs are 100% reproducible via time-travel replay.

The Three Laws of Causaloop

  1. ๐Ÿ“ฆ Effects & Subscriptions as Data: One-shot side effects (Fetch, Workers) are pure data structures. Ongoing processes (Timers, Animation Frames) are declarative subscriptions managed by the runtime.
  2. ๐Ÿ“ผ Deterministic Replay: Any UI state can be reconstructed exactly from a serializable message log. Non-deterministic operations (Time, Random) are provided via a managed context and recorded for perfect playback.
  3. ๐Ÿ›ก๏ธ Atomic Processing: Messages are processed one at a time via a FIFO queue, eliminating race conditions by design.

๐Ÿ—๏ธ Architecture

Causaloop is built on a unidirectional data flow with two managed side-effect channels: Effects for one-shot operations and Subscriptions for ongoing processes.

graph TD
    UI[View/UI] -- dispatch Msg --> D[Dispatcher]
    D -- Msg --> Q[FIFO Queue]
    Q -- Msg --> U[Update Function]
    U -- next Model --> D
    U -- Effects --> D
    D -- Commit --> S[Snapshot]
    S --> UI
    D -- Run Effects --> R[Platform Runners]
    R -- result as Msg --> D
    D -- Reconcile --> SUB[Subscriptions]
    SUB -- subscribe/unsubscribe --> R
Loading

Effects vs Subscriptions

Effects Subscriptions
Purpose One-shot async operations Ongoing processes
Lifecycle Fire-and-forget Runtime-managed start/stop
Examples Fetch, Worker compute Timer ticks, animation frames
Restore Not restarted (state normalized) Automatically resumed
Emitted by update() return value subscriptions(model) function

๐Ÿ“‚ Monorepo Map

Causaloop is split into three primary layers, ensuring strict separation of concerns.

Package Description Status
@causaloop/core Platform-agnostic engine. Dispatcher, Subscriptions, Replay, and VDOM types. Stable
@causaloop/platform-browser Browser runners (Fetch, Workers, Timer, RAF) and Snabbdom renderer. Stable
@causaloop/app-web Demo application showcasing search, workers, subscriptions, and devtools. Ready

๐Ÿงช "Battle-Tested" Reliability

We don't just claim stability; we prove it. Causaloop is continuously benchmarked against extreme conditions:

  • โšก High Throughput: The Core Dispatcher handles over 1,000,000 messages/sec in CPU-bound stress tests.
  • ๐Ÿ•’ Timer Storms: The Browser Runner manages 1,000+ concurrent timers with zero starvation.
  • ๐Ÿ’ Monkey Testing: Chaotic E2E simulations verify resilience against rapid-fire user interactions and navigation spam.
  • ๐Ÿ“ผ Replay Torture: Verified deterministic reconstruction of session state across 100,000+ log entries.
  • ๐Ÿ”„ Session Restore: Subscriptions automatically resume after replay, eliminating stuck "phantom pending" states.

๐ŸŽฎ Featured Showcase: Causal Factory

Causal Factory is a high-performance industrial logistics simulation built to stress test Causaloop.

It demonstrates:

  • Massive Entity Scaling: 100,000+ autonomous bots moving in a single tick.
  • Complex Logistics: Dynamic supply/demand re-routing and state transition bursts.
  • The "Live-Link" Architecture: A developer setup that hard-wires the game directly to the engine source for zero-build, instant-feedback development.

Quick One-Line Setup

To clone the engine and the showcase game in the required sister-folder structure:

git clone https://github.com/bitkojine/causal-factory.git causal-factory && git clone https://github.com/bitkojine/causaloop.git causaloop-repo && cd causaloop-repo && pnpm install && cd ../causal-factory && pnpm install && pnpm run dev

๐Ÿš€ Getting Started

Prerequisites

Quick Setup

pnpm install
pnpm run build
pnpm run dev

Quality Suite

pnpm test          # Unit & Integration tests
pnpm test:stress   # Performance & Race condition stress tests
pnpm test:e2e      # Playwright E2E suite
pnpm lint          # ESLint boundary enforcement

๐Ÿ”ญ Roadmap

  • Monorepo Foundation: pnpm workspaces + TS Project References.
  • Browser Runner: Robust Fetch, Timers, RAF, and Workers.
  • Subscriptions: Declarative lifecycle for ongoing processes (Timer, Animation, Stress).
  • Session Restore: Automatic subscription resumption + state normalization.
  • Stress Suite: 1M+ throughput verification.
  • Context Injection: Updates receive explicit UpdateContext for deterministic now() and random().
  • SSR Support: Node.js effect runners for server-side rendering.
  • Worker Validation: Add zod schema validation for worker messages.
  • CLI Tool: create-causaloop-app scaffolder for easy setup.

๐Ÿค Zero Comment Policy

This repository enforces a radical "No Comments" rule for all source code.

The codebase is intended to be purely functional and readable without inline narratives.

๐Ÿ›ก๏ธ Enforcement

This rule is strictly enforced by both local and remote guardrails:

  1. Local Pre-Push Hook: A git hook runs scripts/check-thinking-comments.sh before you can push.
  2. CI Pipeline: The GitHub Actions workflow fails if any comments (// or /*) are detected in packages/*/src.

๐Ÿค– Directive for AI Agents

If you are an AI coding assistant working on this repo, follow these instructions precisely:

  • โŒ Low-Value Thoughts: "I think...", "Maybe...", "TODO:..." -> Do NOT write these.
  • โœ… High-Value Insights: Architectural decisions, complex invariants, or critical "gotchas". -> Document these in docs/notes/ideas.md.

Do not pollute the source code with your internal monologue.


๐Ÿค Contributing

Contributions are welcome! Please review our ARCHITECTURE.md to understand the project laws before submitting a PR.

โš–๏ธ License

MIT ยฉ bitkojine

About

High-performance, deterministic MVU for TypeScript. Effect-safe, replayable, and battle-tested.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published