From 8535d390128f082ffebf91856a8e272ca3ff5a77 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Mar 2026 16:51:53 +0000 Subject: [PATCH] Refactor: untangle framework library from todo example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The codebase is now split into two clear layers: Framework library (src/): - lib.rs — public API surface, re-exports all framework types - signal.rs — SignalOpts, Signal, SignalStore, mangle/global/client_only helpers - query.rs — Query trait, CacheKey, query_one!/query_all! macros (macro paths updated from $crate::framework::* to $crate::*) - context.rs — RenderContext, ComponentTree, ComponentNode - connection.rs — ConnectionManager, SubscriptionRegistry, ConnectionState - sse.rs — format_patch_elements, format_patch_signals - server.rs — AppState, SharedState, sse_handler (pure framework plumbing) Todo example (examples/todo/): - main.rs — SQLite setup, seeding, server bootstrap - app.rs — router, document_shell, resolve_and_render, render_page, action_then_render, and all HTTP handlers - queries.rs — Todo model, ListTodos/GetTodo queries, mutation helpers - todo_list.rs — TodoList page component - about.rs — About page component Run the example independently with: cargo run --example todo https://claude.ai/code/session_01JThiQbp3Bn9J1VhBpRuz4u --- Cargo.toml | 2 + {src/app => examples/todo}/about.rs | 2 +- src/app/mod.rs => examples/todo/app.rs | 102 +++--------------------- {src => examples/todo}/main.rs | 11 +-- {src/app => examples/todo}/queries.rs | 6 +- {src/app => examples/todo}/todo_list.rs | 5 +- src/{framework => }/connection.rs | 2 +- src/{framework => }/context.rs | 6 +- src/{framework/mod.rs => lib.rs} | 2 + src/{framework => }/query.rs | 10 +-- src/server.rs | 85 ++++++++++++++++++++ src/{framework => }/signal.rs | 0 src/{framework => }/sse.rs | 0 13 files changed, 122 insertions(+), 111 deletions(-) rename {src/app => examples/todo}/about.rs (97%) rename src/app/mod.rs => examples/todo/app.rs (78%) rename {src => examples/todo}/main.rs (87%) rename {src/app => examples/todo}/queries.rs (96%) rename {src/app => examples/todo}/todo_list.rs (96%) rename src/{framework => }/connection.rs (99%) rename src/{framework => }/context.rs (97%) rename src/{framework/mod.rs => lib.rs} (85%) rename src/{framework => }/query.rs (95%) create mode 100644 src/server.rs rename src/{framework => }/signal.rs (100%) rename src/{framework => }/sse.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index e109ffc..242bf96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,8 @@ name = "livevue-rs" version = "0.1.0" edition = "2021" +# Run the todo example with: cargo run --example todo + [dependencies] axum = { version = "0.7", features = ["macros"] } tokio = { version = "1", features = ["full"] } diff --git a/src/app/about.rs b/examples/todo/about.rs similarity index 97% rename from src/app/about.rs rename to examples/todo/about.rs index c696b5b..10edea8 100644 --- a/src/app/about.rs +++ b/examples/todo/about.rs @@ -1,4 +1,4 @@ -use crate::framework::context::RenderContext; +use livevue_rs::RenderContext; use maud::{html, Markup}; /// Second page component: a simple "About" page. diff --git a/src/app/mod.rs b/examples/todo/app.rs similarity index 78% rename from src/app/mod.rs rename to examples/todo/app.rs index 20d8894..554fa0f 100644 --- a/src/app/mod.rs +++ b/examples/todo/app.rs @@ -1,37 +1,15 @@ -pub mod about; -pub mod queries; -pub mod todo_list; - -use crate::framework::connection::{ConnectionManager, SubscriptionRegistry}; -use crate::framework::context::{ComponentTree, RenderContext}; -use crate::framework::signal::SignalStore; -use crate::framework::sse::{format_patch_elements, format_patch_signals}; +use livevue_rs::{ + AppState, CacheKey, ComponentTree, RenderContext, SharedState, SignalStore, + format_patch_elements, format_patch_signals, sse_handler, +}; use axum::extract::{Query as AxumQuery, State}; use axum::http::header; -use axum::response::sse::{Event, KeepAlive, Sse}; use axum::response::{Html, IntoResponse}; use axum::routing::{get, post}; use axum::{Json, Router}; -use std::convert::Infallible; -use std::sync::Arc; -use tokio::sync::mpsc; -use tokio_stream::wrappers::ReceiverStream; use uuid::Uuid; -// --------------------------------------------------------------------------- -// Shared application state -// --------------------------------------------------------------------------- - -/// All shared state, wrapped in Arc for axum's State extractor. -pub struct AppState { - pub db: sqlx::SqlitePool, - pub connections: ConnectionManager, - pub subscriptions: SubscriptionRegistry, -} - -pub type SharedState = Arc; - // --------------------------------------------------------------------------- // Router // --------------------------------------------------------------------------- @@ -83,7 +61,7 @@ fn document_shell(conn_id: Uuid, initial_signals: &str, inner_html: &str) -> Str - LiveVue.rs Demo + LiveVue.rs — Todo