# memorithm/elasticxxx architecture

> Architecture diagram of the GitHub repository memorithm/elasticxxx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/memorithm/elasticxxx
- Repository: https://github.com/memorithm/elasticxxx

## Overview

ElasticXxx is a typed Rust model and runtime for declaring resource invariants, elastic dimensions, and objectives, then selecting admissible resource changes. The principal workflow runs from application declarations through EIR lowering and the runtime’s fail-closed observe-to-commit/rollback loop; adapters apply concrete changes. Separate product branches provide guarded Boolean planning, kernel realization planning, KV-cache representation contracts, and CLI operations and evidence. README statements support the high-level loop and capability links; source-index references support only the specific module relationships shown. Unsampled implementation details are not inferred.

Main entry points: [`crates/elastic-runtime/src/control_loop.rs`](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-runtime/src/control_loop.rs) (Control Loop), [`crates/elastic/src/lib.rs`](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic/src/lib.rs) (Public Facade), [`crates/elastic-kernel/src/planner.rs`](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/planner.rs) (Kernel Realization), [`crates/elastic-eir/src/document.rs`](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-eir/src/document.rs) (Validated EIR)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_declarations["Declarations and Model"]
  node_facade["Public Facade<br/>[lib.rs]"]
  node_typed_model["Resource Model<br/>[spec.rs]"]
  node_language["Declaration Language<br/>[lib.rs]"]
  node_macros["Derive and Macro<br/>[lib.rs]"]
  node_eir["Validated EIR<br/>[document.rs]"]
end

subgraph group_runtime["Planning and Runtime"]
  node_control["Control Loop<br/>[control_loop.rs]"]
  node_forecast["Forecasting"]
  node_planner["Resource Planning<br/>[plan.rs]"]
  node_guard["Boolean Eligibility<br/>[guard.rs]"]
end

subgraph group_integrations["Resource Integrations"]
  node_kernel["Kernel Realization<br/>[planner.rs]"]
  node_kernel_candidate["Kernel Candidates<br/>[candidate.rs]"]
  node_kernel_requirements["Kernel Requirements<br/>[requirements.rs]"]
  node_kernel_capability["Capability Snapshot<br/>[capability.rs]"]
  node_kv["KV Representation<br/>[lib.rs]"]
  node_kv_recompute["Recompute Candidates"]
  node_kv_cost["Cost Evidence"]
  node_kv_plan["Recompute Screening"]
  node_adapters["Actuation Adapters<br/>[actuation.rs]"]
end

subgraph group_operations["Operator Tools"]
  node_cli["CLI Commands<br/>[main.rs]"]
  node_cli_commands["Command Operations<br/>[commands.rs]"]
  node_cli_guard["Guard Operations<br/>[guard_cli.rs]"]
  node_evidence["Evidence Files<br/>[evidence.rs]"]
end

node_app(("Application"))
node_resource_state[("Managed Resources")]

node_app -->|"declares resources"| node_facade
node_facade -->|"exposes model"| node_typed_model
node_facade -->|"exposes language"| node_language
node_facade -->|"exposes lowering"| node_eir
node_language -->|"reuses semantics"| node_typed_model
node_macros -->|"lowers declarations"| node_typed_model
node_macros -->|"lowers documents"| node_eir
node_eir -.->|"enters runtime"| node_control
node_control -->|"observes"| node_resource_state
node_control -->|"forecasts"| node_forecast
node_control -->|"plans"| node_planner
node_control -->|"acts through"| node_adapters
node_control -->|"verifies then commits or rolls back"| node_resource_state
node_guard -->|"filters eligibility"| node_planner
node_kernel -->|"selects candidates"| node_kernel_candidate
node_kernel -->|"checks capabilities"| node_kernel_capability
node_kernel -->|"checks requirements"| node_kernel_requirements
node_kv -->|"exposes contracts"| node_kv_recompute
node_kv_plan -->|"screens candidates"| node_kv_recompute
node_kv_plan -->|"checks cost evidence"| node_kv_cost
node_cli -->|"dispatches commands"| node_cli_commands
node_cli -->|"dispatches guard commands"| node_cli_guard
node_cli_commands -->|"uses evidence"| node_evidence
node_cli_guard -->|"uses evidence"| node_evidence

click node_facade "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic/src/lib.rs"
click node_typed_model "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-core/src/resource/spec.rs"
click node_language "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-language-syntax/src/lib.rs"
click node_macros "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-macros/src/lib.rs"
click node_eir "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-eir/src/document.rs"
click node_control "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-runtime/src/control_loop.rs"
click node_forecast "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-runtime/src/forecast_runtime.rs"
click node_planner "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-runtime/src/plan.rs"
click node_guard "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-core/src/guard.rs"
click node_kernel "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/planner.rs"
click node_kernel_candidate "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/candidate.rs"
click node_kernel_requirements "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/requirements.rs"
click node_kernel_capability "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/capability.rs"
click node_kv "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/lib.rs"
click node_kv_recompute "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/storage_recompute.rs"
click node_kv_cost "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/storage_recompute_cost.rs"
click node_kv_plan "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/storage_recompute_plan.rs"
click node_adapters "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-adapters/src/actuation.rs"
click node_cli "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/main.rs"
click node_cli_commands "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/commands.rs"
click node_cli_guard "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/guard_cli.rs"
click node_evidence "https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/evidence.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_facade,node_typed_model,node_language,node_macros,node_eir toneBlue
class node_control,node_forecast,node_planner,node_guard,node_resource_state toneAmber
class node_kernel,node_kernel_candidate,node_kernel_requirements,node_kernel_capability,node_kv,node_kv_recompute,node_kv_cost,node_kv_plan,node_adapters toneMint
class node_cli,node_cli_commands,node_cli_guard,node_evidence toneRose
class node_app toneIndigo
```

## Components

### Declarations and Model

- [Public Facade](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic/src/lib.rs): `crates/elastic/src/lib.rs`
- [Resource Model](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-core/src/resource/spec.rs): `crates/elastic-core/src/resource/spec.rs`
- [Declaration Language](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-language-syntax/src/lib.rs): `crates/elastic-language-syntax/src/lib.rs`
- [Derive and Macro](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-macros/src/lib.rs): `crates/elastic-macros/src/lib.rs`
- [Validated EIR](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-eir/src/document.rs): `crates/elastic-eir/src/document.rs`

### Planning and Runtime

- [Control Loop](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-runtime/src/control_loop.rs): `crates/elastic-runtime/src/control_loop.rs`
- [Forecasting](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-runtime/src/forecast_runtime.rs): `crates/elastic-runtime/src/forecast_runtime.rs`
- [Resource Planning](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-runtime/src/plan.rs): `crates/elastic-runtime/src/plan.rs`
- [Boolean Eligibility](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-core/src/guard.rs): `crates/elastic-core/src/guard.rs`

### Resource Integrations

- [Kernel Realization](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/planner.rs): `crates/elastic-kernel/src/planner.rs`
- [Kernel Candidates](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/candidate.rs): `crates/elastic-kernel/src/candidate.rs`
- [Kernel Requirements](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/requirements.rs): `crates/elastic-kernel/src/requirements.rs`
- [Capability Snapshot](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kernel/src/capability.rs): `crates/elastic-kernel/src/capability.rs`
- [KV Representation](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/lib.rs): `crates/elastic-kv/src/lib.rs`
- [Recompute Candidates](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/storage_recompute.rs): `crates/elastic-kv/src/storage_recompute.rs`
- [Cost Evidence](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/storage_recompute_cost.rs): `crates/elastic-kv/src/storage_recompute_cost.rs`
- [Recompute Screening](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-kv/src/storage_recompute_plan.rs): `crates/elastic-kv/src/storage_recompute_plan.rs`
- [Actuation Adapters](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-adapters/src/actuation.rs): `crates/elastic-adapters/src/actuation.rs`

### Operator Tools

- [CLI Commands](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/main.rs): `crates/elastic-cli/src/main.rs`
- [Command Operations](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/commands.rs): `crates/elastic-cli/src/commands.rs`
- [Guard Operations](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/guard_cli.rs): `crates/elastic-cli/src/guard_cli.rs`
- [Evidence Files](https://github.com/memorithm/elasticxxx/blob/main/crates/elastic-cli/src/evidence.rs): `crates/elastic-cli/src/evidence.rs`

### Other components

- **Application**
- **Managed Resources**

## Connections

- Application → Public Facade: declares resources (evidence: `README.md`)
- Public Facade → Resource Model: exposes model (evidence: `crates/elastic/src/lib.rs`)
- Public Facade → Declaration Language: exposes language (evidence: `crates/elastic/src/lib.rs`)
- Public Facade → Validated EIR: exposes lowering (evidence: `crates/elastic/src/lib.rs`)
- Declaration Language → Resource Model: reuses semantics (evidence: `README.md`)
- Derive and Macro → Resource Model: lowers declarations (evidence: `README.md`)
- Derive and Macro → Validated EIR: lowers documents (evidence: `README.md`)
- Validated EIR → Control Loop: enters runtime
- Control Loop → Managed Resources: observes (evidence: `README.md`)
- Control Loop → Forecasting: forecasts (evidence: `README.md`)
- Control Loop → Resource Planning: plans (evidence: `README.md`)
- Control Loop → Actuation Adapters: acts through (evidence: `README.md`)
- Control Loop → Managed Resources: verifies then commits or rolls back (evidence: `README.md`)
- Boolean Eligibility → Resource Planning: filters eligibility (evidence: `README.md`)
- Kernel Realization → Kernel Candidates: selects candidates (evidence: `crates/elastic-kernel/src/planner.rs`)
- Kernel Realization → Capability Snapshot: checks capabilities (evidence: `crates/elastic-kernel/src/planner.rs`)
- Kernel Realization → Kernel Requirements: checks requirements (evidence: `crates/elastic-kernel/src/planner.rs`)
- KV Representation → Recompute Candidates: exposes contracts
- Recompute Screening → Recompute Candidates: screens candidates (evidence: `crates/elastic-kv/src/storage_recompute_plan.rs`)
- Recompute Screening → Cost Evidence: checks cost evidence (evidence: `crates/elastic-kv/src/storage_recompute_plan.rs`)
- CLI Commands → Command Operations: dispatches commands (evidence: `crates/elastic-cli/src/main.rs`)
- CLI Commands → Guard Operations: dispatches guard commands (evidence: `crates/elastic-cli/src/main.rs`)
- Command Operations → Evidence Files: uses evidence (evidence: `crates/elastic-cli/src/commands.rs`)
- Guard Operations → Evidence Files: uses evidence (evidence: `crates/elastic-cli/src/guard_cli.rs`)
