How parth3930/threadloom works
Purpose and Entry Points
Threadloom is a Rust workspace for building reactive web/WASM UIs, native/serverless APIs, desktop apps, and Android apps. Consumers normally depend on the façade crate at crates/threadloom/src/lib.rs; application development and builds flow through the distaff CLI at crates/distaff/src/main.rs. The generated-project baseline is crates/distaff/template/src/main.rs, with an optional desktop binary at crates/distaff/template/src/bin/desktop.rs.
Public Framework Surface
threadloom re-exports the framework’s primary API and prelude, hiding most workspace-level composition from apps: crates/threadloom/src/lib.rs. The compile-time UI language is implemented by the procedural macro crate at crates/threadloom-macro/src/lib.rs. Reusable layout and presentation primitives such as Container, Row, Column, and Section belong to crates/threadloom-ui/src/lib.rs and crates/threadloom-ui/src/components/layout.rs.
Reactive Core
The framework’s state and execution model is centered in crates/threadloom-core/src/signal.rs, which provides fine-grained reactive signals. Shared rendering/context types and resource support reside in crates/threadloom-core/src/context.rs and crates/threadloom-core/src/resource.rs. Async work is separated into crates/threadloom-scheduler/src/lib.rs, forming a boundary between reactive UI updates and scheduled/background tasks.
Browser/WASM Rendering
Browser applications compile Rust to WebAssembly and use threadloom-dom as the runtime integration layer. Its public entry point is crates/threadloom-dom/src/lib.rs; rendering and DOM mutation are handled in crates/threadloom-dom/src/render.rs and crates/threadloom-dom/src/patch.rs. Browser-facing boundaries include events, persistence, and development WebSocket support in crates/threadloom-dom/src/events.rs, crates/threadloom-dom/src/storage.rs, and crates/threadloom-dom/src/ws.rs.
Server and API Boundary
Server capabilities are abstracted behind crates/threadloom-server/src/lib.rs, supporting native Actix Web execution and Vercel-oriented serverless deployment as described by the project. Apps define API endpoints separately from pages; the template demonstrates route aggregation in crates/distaff/template/src/api_routes.rs and an endpoint implementation in crates/distaff/template/src/api/hello/route.rs. Core RPC/client-related primitives are in crates/threadloom-core/src/rpc.rs.
Tooling, Build, and Live Development
distaff owns project scaffolding, execution, build orchestration, hot reload, and production patching: crates/distaff/src/init.rs, crates/distaff/src/hot_reload.rs, and crates/distaff/src/hot_patch.rs. Its internal server and plugin orchestration are in crates/distaff/src/server.rs and crates/distaff/src/plugins.rs. The CLI bridges Cargo/Rust compilation, WASM/browser assets, and platform-specific launch flows rather than requiring an application-managed JavaScript build pipeline.
Native Targets and Reference Application
Desktop support is exposed through crates/threadloom-desktop/src/lib.rs; Android Rust integration is exposed by crates/threadloom-android/src/lib.rs, with Android WebView/activity bridge code packaged under crates/distaff/android_java/com/threadloom/app/. The examples/whiteboard app is the end-to-end reference: its app entry is examples/whiteboard/src/main.rs, its collaborative board UI is examples/whiteboard/src/pages/board/page.rs, and its WebSocket handling is examples/whiteboard/src/ws/handler.rs. It also demonstrates route-based APIs and a database boundary via examples/whiteboard/src/api_routes.rs and examples/whiteboard/src/db.rs.
Main entry points: src/lib.rs threadloom façade · main.rs distaff CLI · signal.rs Reactive signals · src/lib.rs DOM runtime
Components 22
Framework crates
Public UI, reactive, and platform runtime layers.
- threadloom façade · Consumer-facing framework API and prelude.
crates/threadloom/src/lib.rs - UI macro · Compile-time UI language implementation.
crates/threadloom-macro/src/lib.rs - UI primitives · Reusable layout and presentation components.
crates/threadloom-ui/src/lib.rs - Reactive signals · Fine-grained state and update model.
crates/threadloom-core/src/signal.rs - Context and resources · Shared rendering context and resource support.
crates/threadloom-core/src/context.rs - Scheduler · Separates background work from reactive updates.
crates/threadloom-scheduler/src/lib.rs - RPC primitives · Client and RPC-related primitives.
crates/threadloom-core/src/rpc.rs - DOM runtime · Browser runtime integration.
crates/threadloom-dom/src/lib.rs - DOM render and patch · Rendering and DOM mutation pipeline.
crates/threadloom-dom/src/render.rs - Browser boundaries · Browser events, persistence, and development WebSocket support.
crates/threadloom-dom/src/events.rs - Server runtime · Native Actix and Vercel-oriented serverless execution.
crates/threadloom-server/src/lib.rs - Desktop runtime
crates/threadloom-desktop/src/lib.rs - Android integration · Rust-side Android integration.
crates/threadloom-android/src/lib.rs
Tooling
Project lifecycle and live-development orchestration.
- distaff CLI · Scaffolds, builds, runs, and coordinates platform launches.
crates/distaff/src/main.rs - Live development · Hot reload and production patching workflow.
crates/distaff/src/hot_reload.rs - Tool server and plugins · Internal server and plugin orchestration.
crates/distaff/src/server.rs
Applications
Generated and reference application entry points.
- Generated app baseline · Default application entry generated by the CLI.
crates/distaff/template/src/main.rs - Template API routes · Aggregates generated-app endpoints.
crates/distaff/template/src/api_routes.rs - Whiteboard app · End-to-end collaborative reference app.
examples/whiteboard/src/main.rs - Collaborative board UI
examples/whiteboard/src/pages/board/page.rs - Board WebSocket handler
examples/whiteboard/src/ws/handler.rs - Whiteboard database
examples/whiteboard/src/db.rs
Connections 23
- threadloom façade → UI macro: re-exports
- threadloom façade → UI primitives: re-exports
- threadloom façade → Reactive signals: re-exports
- threadloom façade → DOM runtime: selects for browser
- Reactive signals → Context and resources: uses render context
- Reactive signals → Scheduler: schedules async work
- DOM runtime → DOM render and patch: renders through
- DOM render and patch → Reactive signals: reacts to updates
- DOM runtime → Browser boundaries: integrates
- RPC primitives → Server runtime: connects clients to APIs
- distaff CLI → Generated app baseline: scaffolds
- distaff CLI → Tool server and plugins: orchestrates
- distaff CLI → Live development: drives
- Live development → Browser boundaries: uses development WebSocket
- Generated app baseline → threadloom façade: depends on
- Generated app baseline → Template API routes: defines APIs
- Template API routes → Server runtime: runs on
- Whiteboard app → threadloom façade: uses
- Whiteboard app → Collaborative board UI: hosts
- Collaborative board UI → Board WebSocket handler: collaborates via
- Board WebSocket handler → Whiteboard database: persists data
- distaff CLI → Desktop runtime: launches desktop target
- distaff CLI → Android integration: launches Android target