PHPackages                             animagram/state-engine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. animagram/state-engine

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

animagram/state-engine
======================

00[3 issues](https://github.com/animagram-jp/context-engine/issues)Rust

Since Mar 3Pushed 2w agoCompare

[ Source](https://github.com/animagram-jp/context-engine)[ Packagist](https://packagist.org/packages/animagram/state-engine)[ RSS](/packages/animagram-state-engine/feed)WikiDiscussions main Synced today

READMEChangelog (6)DependenciesVersions (1)Used By (0)

context-engine
==============

[](#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](#background)).

- [See original text(ja)](#original-text-ja)

---

Version
-------

[](#version)

VersionStatusDateDescription0.1Released2026-2-12-0.1.5Previous2026-3-21improve #430.1.6Current2026-4-23improve #57---

Provided Functions
------------------

[](#provided-functions)

ModDescriptionfn`Context`operates context`new/get/set/delete/exists`---

Why context-engine?
-------------------

[](#why-context-engine)

**Before:**

```
// Manual cache management
let session_key = format!("user:{}", id);
let user = redis.get(&session_key).or_else(|| {
    let user = db.query("SELECT id, email, name FROM users WHERE id=?", id)?;
    redis.set(&session_key, &user, 3600);
    Some(user)
})?;
```

**After:**

```
let user = state.get("session.user.name")?;
```

---

Quick Start
-----------

[](#quick-start)

1. Add to dependencies.

```
# Cargo.toml
[dependencies]
context-engine = "0.1"
```

2. 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"
```

CaseExamplemulti-tenant app[tenant.yml](./examples/tenant.yml)3. Implement `Store` and `StoreRegistry` for your stores.

TraitDescriptionExample`Store``get()` `set()` `delete()`[TenantDbClient](./examples/implements.rs)`Stores`maps YAML store names to `Store`s[MyStore](./examples/implements.rs)4. Precompile your yaml to a rs file.

```
cargo run --example precompile --features precompile -- examples/mine.yml src/dsl_compiled.rs
# --
```

5. Initialize Context with your registry.

```
use context_engine::{Context, Index};
use std::sync::Arc;

// Include the precompiled static data
include!("generated.rs");

let index = Arc::new(Index::new(
    Box::from(PATHS),
    Box::from(CHILDREN),
    Box::from(LEAVES),
    Box::from(INTERNING),
    Box::from(INTERNING_IDX),
));

let registry = MyRegistry::new();
let mut context = Context::new(index, &registry);

// --- setup completed ---

let user_name = context.get("session.user.name")?;
```

---

Architecture
------------

[](#architecture)

```
┌─────────────┐        ┌─────────────────────────────────┐
│ DSL YAML    │------->│ Index (app global instance)     │
└─────────────┘compile └──────────┬──────────────────────┘
                                  │
                                  ▼
┌─────────────┐        ┌─────────────────────────────────┐
│ Application ││ Stores (required to impl)       │
└─────────────┘register└─────────────────────────────────┘

```

See for details [Architecture.md](./docs/Architecture.md)

Test
----

[](#test)

Passed unit and integration tests

```
# unit test
cargo test

# integration test (includes precompile path verification)
RUST_LOG=debug cargo run --example precompile --features precompile -- examples/tenant.yml src/dsl_compiled.rs && RUST_LOG=debug cargo run --example integration_tests --features precompile
```

---

License
-------

[](#license)

SPDX-License-Identifier: Apache-2.0 Copyright (c) 2026 Andyou

---

Background
----------

[](#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)
------------------

[](#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内のデータ取得方法によって、適切に解決されます。このライブラリは、[背景](#%E8%83%8C%E6%99%AF)記載の、再構成されたwebシステムアーキテクチャの基盤技術に位置付けられています。

### 背景

[](#背景)

**webシステムの構成再定義**

人々の営みの一部を、ネットワーク機能を持ったコンピューターのデータ処理で代替することで、検証可能性の保証や物理的制約の緩和といった恩恵を受けます。これを実現する、ハードウェアを通して電気信号として入力を受け取り、処理後、所定のハードウェア群に出力する仕組みのことをwebシステムと呼びます。webシステムの実現には、まず、システムに必要な概念体系を、人間言語とコンピューターのビット列それぞれで定義する必要があります。

```
# computers structure of web system
computer:       "(ネットワーク通信機能を要する)コンピューター"
  server:       "人間(ユーザー・開発者)に処理能力を提供する"
    fixture:    "継続的な待機により、ネットワーク機能を提供する"
    terminal:   "人間とのインターフェースを提供する。端末。"
  orchestrator: "サーバー群の維持を管理する(optional)"
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance63

Regular maintenance activity

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 95.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/206272576?v=4)[Andyou](/maintainers/Andyou007)[@Andyou007](https://github.com/Andyou007)

---

Top Contributors

[![Andyou007](https://avatars.githubusercontent.com/u/206272576?v=4)](https://github.com/Andyou007 "Andyou007 (289 commits)")[![Qebju007](https://avatars.githubusercontent.com/u/207797756?v=4)](https://github.com/Qebju007 "Qebju007 (13 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (1 commits)")

---

Tags

bit-packingcratedeclarativedomain-specific-languagelibraryno-stdossruststate-managementwasm-compatiblewebyaml

### Embed Badge

![Health badge](/badges/animagram-state-engine/health.svg)

```
[![Health](https://phpackages.com/badges/animagram-state-engine/health.svg)](https://phpackages.com/packages/animagram-state-engine)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M47](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9843.5k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

45153.1k6](/packages/jstewmc-rtf)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

113.2k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
