context-engine
Data labels used by a web system's runtime within a single processing cycle should have their session-context-dependent variations resolved outside of code (e.g., system_context["session.user"] rather than users[session[user_id]]). context-engine processes the data retrieval methods that application developers define as a DSL in YAML files, for each label. This allows server/store differences in system_context["session.user.preference"] and multi-tenant differences in context["session.user.tenant"] to be resolved appropriately through the methods defined in YAML. This library is a foundational technology for the reconstructed web system architecture (see Background).
Version
| Version | Status | Date | Description |
|---|---|---|---|
| 0.1 | Released | 2026-2-12 | - |
| 0.1.5 | Previous | 2026-3-21 | improve #43 |
| 0.1.6 | Current | 2026-4-23 | improve #57 |
Provided Functions
| Mod | Description | fn |
|---|---|---|
Context |
operates context | new/get/set/delete/exists |
Why context-engine?
Before:
// Manual cache management
let session_key = format!;
let user = redis.get.or_else?;
After:
let user = state.get?;
Quick Start
- Add to dependencies.
# Cargo.toml
[]
= "0.1"
- Write a yaml file.
# mine.yml
session:
user:
id:
_get:
store: Memory
key: "request.authorization.user.id"
name:
_get:
store: Db
key: "users.${session.user.id}.name"
| Case | Example |
|---|---|
| multi-tenant app | tenant.yml |
- Implement
StoreandStoreRegistryfor your stores.
| Trait | Description | Example |
|---|---|---|
Store |
get() set() delete() |
DbClient |
StoreRegistry |
maps YAML store names to Stores |
MyRegistry |
- Precompile your yaml to a rs file.
# -- <input.yml: required> <output.rs: optional>
- Initialize Context with your registry.
use ;
use Arc;
// Include the precompiled static data
include!;
let index = new;
let registry = new;
let mut context = new;
// --- setup completed ---
let user_name = context.get?;
Architecture
┌─────────────┐ ┌─────────────────────────────────┐
│ DSL YAML │------->│ Index (app global instance) │
└─────────────┘compile └──────────┬──────────────────────┘
│
▼
┌─────────────┐ ┌─────────────────────────────────┐
│ Application │<-------│ Context (request scope instance)│
└─────────────┘ provide└─────────────────────────────────┘
▲
│
┌─────────────┐ ┌──────────┴──────────────────────┐
│ StoreImpls │------->│ Stores (required to impl) │
└─────────────┘register└─────────────────────────────────┘
See for details Architecture.md
Test
Passed unit and integration tests
# unit test
# integration test (includes precompile path verification)
RUST_LOG=debug && RUST_LOG=debug
License
SPDX-License-Identifier: Apache-2.0 Copyright (c) 2026 Andyou andyou@animagram.jp
Background
reimagined web architecture
By substituting a portion of human activities with data processing on network-capable computers, we gain benefits such as assurance of verifiability and reduction of physical constraints. The mechanism that realizes this — receiving input as electrical signals through hardware, processing it, and outputting to designated hardware — is called a web system. To realize a web system, it is first necessary to define the conceptual framework it requires in both human language and the language of computer.
# computers structure of web system
computer: "Network-capable nodes in the system."
server: "Computers that serves human users."
fixture: "Servers that provides continuous network."
terminal: "Servers that provides human interfaces."
orchestrator: "Computers responsible for maintenance of servers. (optional)"
Original Text (ja)
概要
webシステムのランタイムが1回の処理の中で使用するデータのラベルは、セッションコンテクストによる変動を、コード外で処理するべきです(例: users[session[user-id]]では無く、system_context["session.user"]で呼び出せるべき)。context-engineは、アプリ開発者がYAMLファイルにDSLとして定義したデータの取得方法を、ラベルごとに処理します。これにより、例えばsystem_context["session.user.preference"]のサーバー/クライアント差異が、context[session.user.tenant]のマルチテナント差異が、YAML内のデータ取得方法によって、適切に解決されます。このライブラリは、背景記載の、再構成されたwebシステムアーキテクチャの基盤技術に位置付けられています。
背景
webシステムの構成再定義
人々の営みの一部を、ネットワーク機能を持ったコンピューターのデータ処理で代替することで、検証可能性の保証や物理的制約の緩和といった恩恵を受けます。これを実現する、ハードウェアを通して電気信号として入力を受け取り、処理後、所定のハードウェア群に出力する仕組みのことをwebシステムと呼びます。webシステムの実現には、まず、システムに必要な概念体系を、人間言語とコンピューターのビット列それぞれで定義する必要があります。
# computers structure of web system
computer: "(ネットワーク通信機能を要する)コンピューター"
server: "人間(ユーザー・開発者)に処理能力を提供する"
fixture: "継続的な待機により、ネットワーク機能を提供する"
terminal: "人間とのインターフェースを提供する。端末。"
orchestrator: "サーバー群の維持を管理する(optional)"