# zenbakiak/skillet architecture

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

- Interactive diagram: https://gitdiagram.com/zenbakiak/skillet
- Repository: https://github.com/zenbakiak/skillet

## Overview

1. **What this repo is**
   - Skillet is a single Rust crate that combines a formula language library with command-line tools and server runtimes.
   - The core product boundary is: **expression engine library** vs. **transport/adapters** (CLI, HTTP, TCP, daemonization, plugin management).

2. **Front-end language pipeline**
   - Input expressions flow through `src/lexer.rs` → `src/parser.rs` → `src/ast.rs`.
   - This layer is responsible for tokenizing, syntax parsing, and building the AST for Excel-like formulas, method chaining, lambdas, arrays, JSON access, and safe navigation.

3. **Core evaluation engine**
   - `src/runtime/` contains the execution semantics for the language.
   - `src/runtime/evaluator.rs` and `src/runtime/evaluation/*` handle AST execution, including assignment handling, higher-order functions, and core node evaluation.
   - The runtime is split by domain: arithmetic, arrays, strings, logical ops, JSON, date/time, financial, statistical, type casting, and method dispatch.

4. **Built-in function and method dispatch**
   - Built-ins are centralized in `src/runtime/builtin_functions.rs` and routed through `src/runtime/function_dispatch.rs`.
   - Method chaining lives under `src/runtime/method_calls/`, with dedicated handlers for arrays, strings, conversion methods, lambdas, and predicates.
   - This means the language supports both classic function-call syntax and Ruby-style chained methods through the same execution core.

5. **Values, typing, and conversion boundaries**
   - `src/types.rs` defines the runtime `Value` model used across the library and servers.
   - `src/runtime/type_casting.rs` and related utilities manage coercion between numbers, strings, booleans, arrays, JSON, dates, and currency.
   - This typed value layer is the main boundary between parsed syntax and executable semantics.

6. **State, extensibility, and concurrency**
   - `src/custom.rs`, `src/js_plugin.rs`, and `src/concurrent_registry.rs` support runtime extensibility.
   - Custom functions can be registered/unregistered dynamically, and JavaScript plugins are treated as first-class runtime extensions.
   - `src/memory_pool.rs` suggests the engine optimizes object allocation to reduce per-evaluation overhead, which matters for the high-performance claims.

7. **Library API surface**
   - `src/lib.rs` exposes the public Rust API: parse, evaluate, evaluate-with-variables, JSON-backed evaluation, and custom function registration.
   - This is the embedding boundary for other Rust applications: they can use the engine directly without starting a server.

8. **HTTP server subsystem**
   - `src/bin/http_server/` is a full REST adapter around the evaluator.
   - Its submodules separate responsibilities:
     - `eval.rs` for evaluation endpoints
     - `auth.rs` for token protection
     - `js_management.rs` for plugin lifecycle
     - `multipart.rs` for upload handling
     - `cache.rs`, `stats.rs`, `daemon.rs`, `utils.rs`, `types.rs`
   - The HTTP server exposes both expression evaluation and JavaScript function management, making it the main network-facing control plane.

9. **TCP server and CLI tools**
   - `src/bin/sk_server.rs` is the TCP server entry point; it runs the evaluator behind a JSON-based socket protocol.
   - `src/bin/sk_client.rs` is the client for remote evaluation and benchmarking against the TCP server.
   - `src/bin/sk.rs` is the direct CLI evaluator for local one-shot formula execution.
   - `src/bin/sk_http_server.rs` and `src/bin/sk_http_bench.rs` wrap the HTTP server and its performance testing use cases.

10. **Operational and deployment surface**
   - The repo includes Dockerfiles, `docker-compose.yml`, Shuttle config, and CI workflows for release automation.
   - `openapi.yml` and the various docs/guide files indicate the HTTP API is a first-class deployable interface.
   - The `scripts/` and `benches/` directories show a strong emphasis on reproducible benchmarking and server performance validation.

11. **Testing and validation**
   - `tests/` covers parser behavior, built-ins, method chaining, JSONPath, null handling, safe navigation, concurrency, and performance-oriented scenarios.
   - `hook_examples/` and `examples/` provide integration samples for plugin behavior and embedding patterns.
   - The repository also tracks benchmark outputs in `performance_results/`, which supports the architecture’s performance-sensitive design goals.

12. **End-to-end data flow**
   - Typical flow: user input arrives via CLI, HTTP, TCP, or Rust API → lexer/parser build AST → runtime resolves variables/functions/methods/plugins → evaluator returns a typed `Value` → adapters serialize that result as text/JSON over the chosen transport.
   - The main architectural seam is therefore between the **pure evaluation engine** and the **I/O/runtime adapters** that expose it to external callers.

Main entry points: [`src/runtime/evaluator.rs`](https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluator.rs) (Evaluator), [`src/bin/http_server/mod.rs`](https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/mod.rs) (HTTP server), [`src/runtime/function_dispatch.rs`](https://github.com/zenbakiak/skillet/blob/main/src/runtime/function_dispatch.rs) (Dispatch), [`src/lib.rs`](https://github.com/zenbakiak/skillet/blob/main/src/lib.rs) (Library API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core engine"]
  node_lib["Library API<br/>public api<br/>[lib.rs]"]
  node_lexer["Lexer<br/>tokenizer<br/>[lexer.rs]"]
  node_parser["Parser<br/>[parser.rs]"]
  node_ast["AST<br/>syntax tree<br/>[ast.rs]"]
  node_types[("Values<br/>runtime value model<br/>[types.rs]")]
  node_eval["Evaluator<br/>execution engine<br/>[evaluator.rs]"]
  node_core_eval["Core eval<br/>node execution<br/>[core.rs]"]
  node_assignments["Assignments<br/>stateful eval<br/>[assignments.rs]"]
  node_higher_order["Higher-order<br/>call semantics<br/>[higher_order.rs]"]
  node_dispatch["Dispatch<br/>builtin router"]
  node_builtins["Built-ins<br/>stdlib"]
  node_methods["Method calls<br/>method dispatch<br/>[mod.rs]"]
  node_casting["Type casting<br/>coercion<br/>[type_casting.rs]"]
end

subgraph group_adapters["Adapters"]
  node_http["HTTP server<br/>rest adapter<br/>[mod.rs]"]
  node_http_eval["HTTP eval<br/>endpoint set<br/>[eval.rs]"]
  node_http_js["JS admin<br/>endpoint set<br/>[js_management.rs]"]
  node_http_ops["HTTP ops<br/>support modules<br/>[utils.rs]"]
  node_tcp["TCP server<br/>socket server<br/>[sk_server.rs]"]
  node_cli["CLI<br/>command tool<br/>[sk.rs]"]
  node_client["TCP client<br/>client tool<br/>[sk_client.rs]"]
end

subgraph group_extensibility["Extensibility"]
  node_custom["Custom funcs<br/>runtime extensibility<br/>[custom.rs]"]
  node_js_plugin["JS plugins<br/>plugin bridge<br/>[js_plugin.rs]"]
  node_registry["Registry<br/>concurrent state"]
  node_mem_pool["Memory pool<br/>allocator<br/>[memory_pool.rs]"]
end

subgraph group_ops["Ops"]
  node_bench_http["HTTP bench<br/>benchmark tool<br/>[sk_http_bench.rs]"]
  node_scripts["Scripts<br/>ops tooling"]
end

node_lib -->|"parse"| node_lexer
node_lib -->|"parse"| node_parser
node_lib -->|"evaluate"| node_eval
node_lexer -->|"tokens"| node_parser
node_parser -->|"builds"| node_ast
node_ast -->|"executes"| node_eval
node_eval -->|"delegates"| node_core_eval
node_eval -->|"delegates"| node_assignments
node_eval -->|"delegates"| node_higher_order
node_core_eval -->|"routes"| node_dispatch
node_dispatch -->|"resolves"| node_builtins
node_dispatch -->|"resolves"| node_methods
node_dispatch -->|"coerces"| node_casting
node_builtins -->|"returns"| node_types
node_methods -->|"returns"| node_types
node_casting -->|"normalizes"| node_types
node_custom -->|"stores"| node_registry
node_js_plugin -->|"registers"| node_registry
node_mem_pool -->|"optimizes"| node_eval
node_http -->|"serves"| node_http_eval
node_http -->|"serves"| node_http_js
node_http -->|"supports"| node_http_ops
node_http -->|"uses"| node_eval
node_http_js -->|"loads"| node_js_plugin
node_tcp -->|"uses"| node_eval
node_cli -->|"uses"| node_eval
node_client -->|"calls"| node_tcp
node_bench_http -->|"measures"| node_http
node_scripts -->|"operates"| node_tcp
node_scripts -->|"operates"| node_http

click node_lib "https://github.com/zenbakiak/skillet/blob/main/src/lib.rs"
click node_lexer "https://github.com/zenbakiak/skillet/blob/main/src/lexer.rs"
click node_parser "https://github.com/zenbakiak/skillet/blob/main/src/parser.rs"
click node_ast "https://github.com/zenbakiak/skillet/blob/main/src/ast.rs"
click node_types "https://github.com/zenbakiak/skillet/blob/main/src/types.rs"
click node_eval "https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluator.rs"
click node_core_eval "https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluation/core.rs"
click node_assignments "https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluation/assignments.rs"
click node_higher_order "https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluation/higher_order.rs"
click node_dispatch "https://github.com/zenbakiak/skillet/blob/main/src/runtime/function_dispatch.rs"
click node_builtins "https://github.com/zenbakiak/skillet/blob/main/src/runtime/builtin_functions.rs"
click node_methods "https://github.com/zenbakiak/skillet/blob/main/src/runtime/method_calls/mod.rs"
click node_casting "https://github.com/zenbakiak/skillet/blob/main/src/runtime/type_casting.rs"
click node_custom "https://github.com/zenbakiak/skillet/blob/main/src/custom.rs"
click node_js_plugin "https://github.com/zenbakiak/skillet/blob/main/src/js_plugin.rs"
click node_registry "https://github.com/zenbakiak/skillet/blob/main/src/concurrent_registry.rs"
click node_mem_pool "https://github.com/zenbakiak/skillet/blob/main/src/memory_pool.rs"
click node_http "https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/mod.rs"
click node_http_eval "https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/eval.rs"
click node_http_js "https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/js_management.rs"
click node_http_ops "https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/utils.rs"
click node_tcp "https://github.com/zenbakiak/skillet/blob/main/src/bin/sk_server.rs"
click node_cli "https://github.com/zenbakiak/skillet/blob/main/src/bin/sk.rs"
click node_client "https://github.com/zenbakiak/skillet/blob/main/src/bin/sk_client.rs"
click node_bench_http "https://github.com/zenbakiak/skillet/blob/main/src/bin/sk_http_bench.rs"
click node_scripts "https://github.com/zenbakiak/skillet/tree/main/scripts"

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_lib,node_lexer,node_parser,node_ast,node_types,node_eval,node_core_eval,node_assignments,node_higher_order,node_dispatch,node_builtins,node_methods,node_casting toneBlue
class node_http,node_http_eval,node_http_js,node_http_ops,node_tcp,node_cli,node_client toneAmber
class node_custom,node_js_plugin,node_registry,node_mem_pool toneMint
class node_bench_http,node_scripts toneRose
```

## Components

### Core engine

Parsing, AST, values, and execution semantics for the formula language.

- [Library API](https://github.com/zenbakiak/skillet/blob/main/src/lib.rs): public api · Embedding surface for parsing, evaluation, variable binding, JSON-backed evaluation, and custom function registration. · `src/lib.rs`
- [Lexer](https://github.com/zenbakiak/skillet/blob/main/src/lexer.rs): tokenizer · Converts formula text into tokens. · `src/lexer.rs`
- [Parser](https://github.com/zenbakiak/skillet/blob/main/src/parser.rs): syntax parser · Builds syntax structure from tokens for formulas, chaining, lambdas, arrays, and JSON access. · `src/parser.rs`
- [AST](https://github.com/zenbakiak/skillet/blob/main/src/ast.rs): syntax tree · Defines the expression tree consumed by the runtime. · `src/ast.rs`
- [Values](https://github.com/zenbakiak/skillet/blob/main/src/types.rs): runtime value model · Typed value boundary shared by engine and adapters. · `src/types.rs`
- [Evaluator](https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluator.rs): execution engine · Orchestrates AST execution and dispatch into runtime semantics. · `src/runtime/evaluator.rs`
- [Core eval](https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluation/core.rs): node execution · Primary AST node evaluation and execution flow. · `src/runtime/evaluation/core.rs`
- [Assignments](https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluation/assignments.rs): stateful eval · Handles variable assignment and update semantics during evaluation. · `src/runtime/evaluation/assignments.rs`
- [Higher-order](https://github.com/zenbakiak/skillet/blob/main/src/runtime/evaluation/higher_order.rs): call semantics · Evaluates lambdas and other higher-order language behaviors. · `src/runtime/evaluation/higher_order.rs`
- [Dispatch](https://github.com/zenbakiak/skillet/blob/main/src/runtime/function_dispatch.rs): builtin router · Routes function calls to built-ins and method handlers. · `src/runtime/function_dispatch.rs`
- [Built-ins](https://github.com/zenbakiak/skillet/blob/main/src/runtime/builtin_functions.rs): stdlib · Central catalog of built-in formula functions. · `src/runtime/builtin_functions.rs`
- [Method calls](https://github.com/zenbakiak/skillet/blob/main/src/runtime/method_calls/mod.rs): method dispatch · Ruby-style chained methods for arrays, strings, conversions, lambdas, and predicates. · `src/runtime/method_calls/mod.rs`
- [Type casting](https://github.com/zenbakiak/skillet/blob/main/src/runtime/type_casting.rs): coercion · Coerces between numbers, strings, booleans, arrays, JSON, dates, and currency. · `src/runtime/type_casting.rs`

### Adapters

CLI, HTTP, TCP, and server-facing entry points that expose the engine.

- [HTTP server](https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/mod.rs): rest adapter · REST adapter exposing evaluation and plugin management over HTTP. · `src/bin/http_server/mod.rs`
- [HTTP eval](https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/eval.rs): endpoint set · Evaluation endpoints for HTTP requests. · `src/bin/http_server/eval.rs`
- [JS admin](https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/js_management.rs): endpoint set · Plugin lifecycle management endpoints. · `src/bin/http_server/js_management.rs`
- [HTTP ops](https://github.com/zenbakiak/skillet/blob/main/src/bin/http_server/utils.rs): support modules · Auth, cache, multipart upload, daemon, stats, types, and utility support for the server. · `src/bin/http_server/utils.rs`
- [TCP server](https://github.com/zenbakiak/skillet/blob/main/src/bin/sk_server.rs): socket server · JSON-over-socket server entry point for remote evaluation. · `src/bin/sk_server.rs`
- [CLI](https://github.com/zenbakiak/skillet/blob/main/src/bin/sk.rs): command tool · Direct one-shot local formula evaluator. · `src/bin/sk.rs`
- [TCP client](https://github.com/zenbakiak/skillet/blob/main/src/bin/sk_client.rs): client tool · Remote evaluation and benchmarking client for the TCP server. · `src/bin/sk_client.rs`

### Extensibility

Custom functions, plugins, and shared runtime state.

- [Custom funcs](https://github.com/zenbakiak/skillet/blob/main/src/custom.rs): runtime extensibility · Registers and unregisters user-defined functions at runtime. · `src/custom.rs`
- [JS plugins](https://github.com/zenbakiak/skillet/blob/main/src/js_plugin.rs): plugin bridge · Loads JavaScript-backed extensions into the runtime. · `src/js_plugin.rs`
- [Registry](https://github.com/zenbakiak/skillet/blob/main/src/concurrent_registry.rs): concurrent state · Shared concurrent storage for runtime extensions and callable state. · `src/concurrent_registry.rs`
- [Memory pool](https://github.com/zenbakiak/skillet/blob/main/src/memory_pool.rs): allocator · Optimizes object allocation and reuse during evaluation. · `src/memory_pool.rs`

### Ops

Packaging, benchmarks, and deployment tooling around the core crate.

- [HTTP bench](https://github.com/zenbakiak/skillet/blob/main/src/bin/sk_http_bench.rs): benchmark tool · Performance wrapper for the HTTP server. · `src/bin/sk_http_bench.rs`
- [Scripts](https://github.com/zenbakiak/skillet/tree/main/scripts): ops tooling · Benchmarking, daemon, and build automation scripts. · `scripts`

## Connections

- Library API → Lexer: parse · Public API starts by tokenizing input.
- Library API → Parser: parse · Public API exposes parsing.
- Library API → Evaluator: evaluate · Public API evaluates parsed expressions.
- Lexer → Parser: tokens · Parser consumes lexer output.
- Parser → AST: builds · Parser produces AST nodes.
- AST → Evaluator: executes · AST is executed by the runtime evaluator.
- Evaluator → Core eval: delegates · Evaluator delegates to core node execution.
- Evaluator → Assignments: delegates · Evaluator handles assignment semantics.
- Evaluator → Higher-order: delegates · Evaluator handles lambdas and higher-order behavior.
- Core eval → Dispatch: routes · Core execution routes functions and methods.
- Dispatch → Built-ins: resolves · Dispatch resolves built-in functions.
- Dispatch → Method calls: resolves · Dispatch resolves chained method calls.
- Dispatch → Type casting: coerces · Dispatch uses coercion boundaries during execution.
- Built-ins → Values: returns · Built-ins operate on and return typed values.
- Method calls → Values: returns · Method handlers consume and emit typed values.
- Type casting → Values: normalizes · Type casting normalizes runtime values.
- Custom funcs → Registry: stores · Custom functions are tracked in shared registry state.
- JS plugins → Registry: registers · JavaScript plugins are registered in shared state.
- Memory pool → Evaluator: optimizes · Memory pool supports execution performance.
- HTTP server → HTTP eval: serves · HTTP server exposes evaluation endpoints.
- HTTP server → JS admin: serves · HTTP server exposes plugin management endpoints.
- HTTP server → HTTP ops: supports · Server support modules provide auth, caching, uploads, daemonization, and stats.
- HTTP server → Evaluator: uses · HTTP adapter invokes the evaluator.
- JS admin → JS plugins: loads · HTTP management controls JavaScript plugin lifecycle.
- TCP server → Evaluator: uses · TCP server invokes the evaluator.
- CLI → Evaluator: uses · CLI evaluates formulas through the core engine.
- TCP client → TCP server: calls · Client talks to the TCP server.
- HTTP bench → HTTP server: measures · Benchmark tool exercises the HTTP server.
- Scripts → TCP server: operates · Operational scripts manage server processes and benchmarks.
- Scripts → HTTP server: operates · Operational scripts support HTTP deployment and testing.
