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[8 issues](https://github.com/animagram-jp/context-engine/issues)Rust

Since Mar 3Pushed 1mo 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 1mo ago

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

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

[](#context-engine)

- renamed from state-engine

Declarative state data management system for a process. Structures state data on process and keeps it syncable using your store clients. It behaves as described in 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](#Background)).
- [also README(patch translation for ja-JP )](./docs/ja/README.md)

Version
-------

[](#version)

VersionStatusDatedescription0.1Released2026-2-12initial0.1.5Current2026-3-21improve #430.1.6Scheduled2026-4-5improve #49 #50Provided Functions
------------------

[](#provided-functions)

moddescriptionfn**State**operates state data following manifest YAMLs`get()`, `set()`, `delete()`, `exists()`Why state-engine?
-----------------

[](#why-state-engine)

**Before:**

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

**After:**

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

- ✅ Multi-tenant DB without junction tables
- ✅ Automatic KVS/DB synchronization
- ✅ No manual cache invalidation

Installation
------------

[](#installation)

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

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

[](#quick-start)

1. Write a yaml file.

```
# manifest/example.yml
session:
  user-key:
  _state:
    type: integer
  _store:
    client: InMemory
    key: "request-attributes-user-key"
  _load:
    client: InMemory
    key: "request-header-user-key"

user:
  _store:
    client: KVS
    key: "user:${example.session.user-key}"
  _load:
    client: Db
    table: "users"
    where: "id=${example.session.user-key}"
    map:
      name: "name"
  name:
    _state:
      type: string
```

casesamplecache in KVS[cache.yml](./examples/manifest/cache.yml)database connection config[connection.yml](./examples/manifest/connection.yml)request scope[session.yml](./examples/manifest/session.yml)2. Implement some Required Ports for your stores.

Interfaceexpected storefnsample`InMemoryClient`Local Process Memory`get()` / `set()` / `delete()`[InMemoryAdapter](./examples/adapters/in_memory.rs)`EnvClient`Environment Variablesas above[EnvAdapter](./examples/adapters/env_client.rs)`KVSClient`Key-Vlue Storeas above[KVSAdapter](./examples/adapters/kvs_client.rs)`DbClient`SQL Databaseas above[DbAdapter](./examples/adapters/db_client.rs)`HttpClient`Http Requestas above[HttpAdapter](./examples/adapters/http_client.rs)`FileClient`File I/Oas above[DefaultFileClient](./src/ports/default.rs)- FileClient.get is always used by State to read manifest YAMLs.
- It's not essential to implement all \*Client.

3. Initialize State with your adapters and use it.

```
use state_engine::State;
use std::sync::Arc;

// Create adapter instances
let in_memory = Arc::new(InMemoryAdapter::new());
let kvs = Arc::new(KVSAdapter::new()?);
let db = Arc::new(DbAdapter::new()?);

// Build State with adapters
let mut state = State::new("./manifest")
    .with_in_memory(in_memory)
    .with_kvs(kvs)
    .with_db(db);

// Use state-engine
let user = state.get("example.user.name")?;
```

Full working example: [examples/app/src/main.rs](./examples/app/src/main.rs)

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

[](#architecture)

```
  manifestDir/*.yml
         │ read via FileClient
         ▼
┌─────────────────────────────────────┐
│           State (Public API)        │
└───────┬─────────────────────────────┘
        │ depends on
        ▼
┌─────────────────────────────────────┐
│    Required Ports (App Adapters)    │
├─────────────────────────────────────┤
│  InMemory / KVS / DB / HTTP / File  │
└─────────────────────────────────────┘
        ▲
        │ implement
  Application

```

see for details [Architecture.md](./docs/en/Architecture.md)

tree
----

[](#tree)

```
./
  README.md
  Cargo.toml

  docs/               # guides
    en/
      Architecture.md
      YAML-guide.md
    ja/
      README.md
      Architecture.md
      YAML-guide.md

  src/
  examples/
    manifest/         # manifest YAML examples
      connection.yml  # sample 1
      cache.yml       # sample 2
      session.yml     # sample 3
    adapters/
    app/
      docker-compose.yml
      Cargo.toml
      Dockerfile
      db/
      src/
        main.rs
        adapters.rs

```

tests
-----

[](#tests)

unit tests, intergeration tests on example app (docker compose) passed

```
cargo test --features=logging -- --nocapture

cd examples/app && ./run.sh
```

Background
----------

[](#background)

**reimagined web architecture**

```
computer: "A network-capable node in the system."
  orchestrator: "A computer responsible for internal system coordination and maintenance. (optional)"
  server: "A computer that serves human users."
    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 keeps state data syncable between them. (optional)"
```

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance60

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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://www.gravatar.com/avatar/47414115dbec86b624ecb13fe26201035460e4fa8eecd0ad3acb03abed746e2f?d=identicon)[Andyou007](/maintainers/Andyou007)

---

Top Contributors

[![Andyou007](https://avatars.githubusercontent.com/u/206272576?v=4)](https://github.com/Andyou007 "Andyou007 (193 commits)")

---

Tags

animagramcratedeclarativedomain-specific-languageruststate-managementwasmwebassemblyyaml

### 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

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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