state-engine 0.1.0
Declarative state data management for multi-tenant, multi-service systems. Synchronizes process memory, KVS, and databases using YAML DSL.
-
Automates complex state lifecycles through developer-defined YAML manifests.
-
Enables multi-tenant DB apps without junction tables.
-
Built on a reimagined web architecture (see ## Background).
Version
| Version | Status | Date | description |
|---|---|---|---|
| 0.1.0 | Released | 2026-2-12 | 1st |
Provided Functions
| Module | description | methods |
|---|---|---|
| Manifest | reads static YAMLs and returns processed obj | get(), getMeta() |
| State | operates state data following Manifest | get(), set(), delete(), exists() |
Why state-engine?
Before:
// Manual cache management
let cache_key = format!;
let user = redis.get.or_else?;
After:
let user = state.get?;
- ✅ Multi-tenant DB without junction tables
- ✅ Automatic KVS/DB synchronization
- ✅ No manual cache invalidation
Installation
# Cargo.toml
[]
= "0.1"
Quick Start
- Write a yaml file.
# manifest/cache.yml
some-state:
_state:
type: integer
_store:
client: KVS
key: "some"
_load:
client: DB
table: some
where: 'id=1' # Please update this '$(user.id)' to use this library effectively after.
columns:
| case | sample |
|---|---|
| cache in KVS | cache.yml |
| database connection config | connection.yml |
| request scope | session.yml |
- Implement some Required Ports for your stores.
| Interface | expected store | methods | sample |
|---|---|---|---|
InMemoryClient |
Local Process Memory | get() / set() / delete() |
InMemoryAdapter |
KVSClient |
Key-Vlue Store | get() / set() / delete() |
InMemoryAdapter |
DBClient |
SQL Database | fetch() |
InMemoryAdapter |
ENVClient |
Environment Variables | get() |
InMemoryAdapter |
'DB' and 'Env' will be used only in Loading(Read) It's not essential to implement all *Client.
- Initialize State with your adapters and use it.
use ;
// Initialize Manifest
let mut manifest = new;
// Create adapter instances
let mut in_memory = new;
let mut kvs = new?;
let db = new?;
// Build Load with adapters
let load = new
.with_in_memory
.with_kvs_client
.with_db_client;
// Build State with adapters
let mut state = new
.with_in_memory
.with_kvs_client;
// Use state-engine
let user = state.get?;
Full working example: examples/app/src/main.rs
Architecture
┌─────────────┐ ┌───────────────────┐
│ Application │ │ manifestDir/*.yml │
└──────┬──────┘ └───────────────────┘
│ uses ▲ read
▼ │
┌─────────────────────────┴───────────┐
│ Provided Ports (Public API) │
├─────────────────────────────────────┤
│ │
│ State --> Manifest │
│ │
└───────┬─────────────────────────────┘
│ depends on
▼
┌─────────────────────────────────────┐
│ Required Ports (App Adapters) │
├─────────────────────────────────────┤
│ InMemory, KVS, DB, ENV clients │
└─────────────────────────────────────┘
see for details Architecture.md
tree
./
README.md # this file
Cargo.toml
docs/ # guide documents
en/
Architecture.md
YAML-guide.md
ja/
README.md
Architecture.md
YAML-guide.md
src/
ports/ # library external interface traits
provided.rs # library provides
required.rs # Library requires
common/ # library common (pure logic modules)
dot_array_accessor.rs
placeholder_resolver.rs
log_format.rs
manifest/ # Manifest impl
state/ # State impl
load/ # Load module (internal module)
examples/
manifest/ # manifest YAML examples
connection.yml # sample 1
cache.yml # sample 2
session.yml # sample 3
adapters/
app/
db/
src/
Cargo.toml
Dockerfile
docker-compose.yml
tests/
mocks/
integration/
tests
39 unit tests, 49 intergeration tests and example application test passed
- cargo test:
- example application test:
Background
reimagined web architecture
- computer: A network-capable node in the system.
- server: A computer that serves human users.
- orchestrator: A computer responsible for internal system coordination and maintenance. (optional)
- database: A server that persists data without an inherent expiration and accepts CRUD operations.
- terminal: A server that provides a direct human-facing interface.
- conductor: A server that communicates independently with both a database and terminals, and maintains a synchronized state between them. (optional)
# terms relationship
computer:
orchestrator:
server:
database:
terminal:
conductor:
License
MIT