This fork adds a few layers on top of Jeremey's original. I have tried to extensively document the changes so I can give back as much as I can. Hope someone finds it as useful as I found Jeremy's rust-web-app
- Rust Web App Architecture documentation
- Rust Web App Refactoring lib_rpc and lib_web which has been merged upstream into Jeremy's code base
- Rust Web App evolve into Worker Architecture which describes changes to make so it supports a worker architecture. POC with a llm-worker which is based on
rust-genai
Original README follows:
- More info at: https://rust10x.com/web-app
- Discord: https://discord.gg/XuKWrNGKpC
- There is a small change in the
SeaField::new(iden, value)
where the value is nowimpl Into<SimpleExpr>
.so change:
SeaField::new(UserIden::Pwd, pwd.into())
to:
SeaField::new(UserIden::Pwd, pwd)
You can find this change in the . update to modql 0.4.0-rc.4
This update (GitHub tag: E06) is significant in many respects:
-
1) Data Model Change
- We are transitioning from the simple
Project / Task
model to a more intricate one centered around AI chat, specificallyAgent, Conv / ConvMsg
. - Subsequently, we'll introduce
Org / Space
constructs to demonstrate multi-tenancy and a "workspace" type of container, common in many use cases (like GitHub repositories, Discord servers, etc.). - The
examples/quick_dev
has been updated to reflect the new data model. - IMPORTANT - While
Agent
andConv
concepts exist, the blueprint's purpose isn't to develop a complete AI chat system. Instead, it aims to illustrate the common structures needed to build such an application and others. The Agents are merely examples of entities and might later exhibit some "Echo" capability to demonstrate the integration of long-running, event-based services.
- We are transitioning from the simple
-
2) ModelManager DB Transaction Support
- There's a significant enhancement to the
ModelManager
, which now contains alib_core::model::store::Dbx
implementing an on-demand database transaction support. - By default, the ModelManager operates non-transactionally; each query executes as its own DB command. However, Bmc functions can transform a ModelManager into a transactional one and initiate/commit a transaction
- Search for
mm.dbx().begin_txn()
for an example inUserBmc::create
.
- Search for
- There's a significant enhancement to the
-
3) Declarative Macros
- To reduce boilerplate, this Rust10x blueprint now supports flexible declarative macros (i.e.,
macro_rules
) at thelib_rpc
andlib_core::model
levels. These create the common basic CRUD JSON-RPC functions and the common BMC CRUD methods.- Search for
generate_common_bmc_fns
orgenerate_common_rpc_fns
to see them in actions.
- Search for
- It's important to note that these declarative macros are additive and optional. In fact, entities can introduce additional behavior as needed or opt out of using these macros if custom logic is required, even for common behaviors.
- To reduce boilerplate, this Rust10x blueprint now supports flexible declarative macros (i.e.,
-
4) Code Update
- All JSON-RPC responses now include a
.data
field asresult.data
to represent the requested data. This adds flexibility to later include metadata at the root of theresult
object (the JSON-RPC specification prohibits adding anything at the root of the JSON response).- This is in the
lib_rpc::response
crate/module.
- This is in the
- The introduction of a
conv_id
in theCtx
paves the way for a futureAccess Control System
, which will be privilege-based and tied to key container constructs (e.g.,Org
,Space
,Conv
).
- All JSON-RPC responses now include a
-
Episode 02 - Sea-Query (sql builder) & modql (mongodb like filter)
-
Episode 06 coming upon request on discord
-
Other Related videos:
# Start postgresql server docker image:
docker run --rm --name pg -p 5432:5432 \
-e POSTGRES_PASSWORD=welcome \
postgres:16
# (optional) To have a psql terminal on pg.
# In another terminal (tab) run psql:
docker exec -it -u postgres pg psql
# (optional) For pg to print all sql statements.
# In psql command line started above.
ALTER DATABASE postgres SET log_statement = 'all';
NOTE: Install cargo watch with
cargo install cargo-watch
.The
.cargo/dev-services.toml
contains resolution information for the various worker services involved. That is how the gateway knows how to hit the llm-worker service for instance.
web-gateway
is built withfeatures dev-utils
and this enables code which handles service name resolution via the supplieddev-services.toml
file.
# Terminal 1 - To run the gateway server.
cargo watch -q -c -w crates/services/web-gateway/src/ -w crates/libs/ -w .cargo/ -x "run --config .cargo/dev-services.toml --features dev-utils -p web-gateway"
# Terminal 2 - To run the llm-worker server
cargo watch -q -c -w crates/services/llm-worker/src/ -w crates/libs/ -w .cargo/ -x "run -p llm-worker"
# Terminal 3 - To run the quick_dev.
cargo watch -q -c -w crates/services/web-gateway/examples/ -x "run -p web-gateway --example quick_dev"
# Terminal 1 - To run the gateway server.
cargo run --config .cargo/dev-services.toml --features dev-utils -p web-gateway
# Terminal 2 - To run the llm-worker server
cargo run -p llm-worker
# Terminal 3 - To run the quick_dev.
cargo run -p web-gateway --example quick_dev
cargo watch -q -c -x "test -- --nocapture"
# Specific test with filter.
cargo watch -q -c -x "test -p lib-core test_create -- --nocapture"
cargo test -- --nocapture
cargo watch -q -c -x "test -p lib-core model::task::tests::test_create -- --nocapture"
cargo run -p gen-key
More resources for Rust for Production Coding