Nativa PHP Core

Article

Rust and Lekalo ... part 5: semantic application models, describing an app without describing code

Article cover illustration: Architecture, rust, lekalo, semantic-model

Four parts in, everything we've discussed has been about the language:
what Rust is, how ownership works, how its tooling and quality machinery behave. Now we step one level up, to the layer that makes the final part possible: semantic application models.

Here's the core claim, and it's worth sitting with for a moment: a model of an application is not the application's source code. And a tool that works with models does not parse source code. Lekalo's effect engine is documented as "never detection from source and never inference from names".
Everything it knows, it knows because somebody declared it, in YAML or JSON documents that describe the application on a semantic level.

What a model describes

If source code answers how, a semantic model answers what. Lekalo's model vocabulary has fourteen definition kinds, and they map neatly onto how a PHP module like this kit's Users actually behaves:

KindWhat it declaresExample from this repo
entitya thing with identity and fieldsUser, Role, Permission, Session
scalar / enum / value-objectfield typesemail, password, account_state
commandan action with inputs and effectsregister, login, reset_password
querya read with declared readsfind_user_by_email, current_user
policya rule on a command (allow/deny)password_min_length, admin_only_rbac
eventsomething that happeneduser_registered, session_started
effectcreate/update/delete on an entityeffect_user_created
endpointHTTP surface invoking a command/queryPOST /login → login
scenarioa user-visible flow covering symbolsregister → login, password reset

Notice what's absent: no classes, no packages, no framework concepts, no implementation details. The model contract is explicit that it "contains no target-language class, package, framework or runtime concepts", the same vocabulary describes a TypeScript, PHP or Go application. That's what language-neutral means: you model the application, and the implementation language is an afterthought.

The fixed homes

Because the model is documents, not code, its location is a contract.
Lekalo projects follow a fixed layout:

lekalo/
├── project.yaml                 # exactly one project definition
├── modules/<module>/
│   ├── module.yaml              # exactly one module definition
│   ├── entities.yaml            # scalar, enum, value-object, entity
│   ├── commands.yaml            # command, effect
│   ├── queries.yaml             # query
│   ├── policies.yaml            # policy
│   ├── events.yaml              # event
│   ├── scenarios.yaml           # scenario
│   └── bindings.yaml            # endpoint, target-binding
└── targets/<target>.yaml        # target configuration

Every definition is a closed object with a schema_version: and the loader accepts exactly two literals: 0.1.0 and 1.0.0. Anything else is unsupported-version, exit 5. A definition in the wrong file (an entity in commands.yaml, say) is rejected. The model is strict because it's a contract: if the documents are ambiguous, every downstream consumer, including an AI agent, pays the price.

You can open this repo's own lekalo/ directory and see all of this in the flesh: the nativa project, the users module, 53 definitions describing auth, RBAC and password reset, JSON content inside .yaml files (the loader accepts a strict JSON frontend), validated by lekalo validate with 23 rules and zero errors. It's a working example of the format, committed next to the PHP code it describes.

Why model an application at all?

If the model doesn't parse code, keeping it in sync is manual work. So why bother? Three answers, all aimed at the tool's real audience, AI-assisted development:

Determinism. An AI agent can't safely read your whole codebase; it can safely consume a validated model with byte-identical canonical output. The agent's facts come from a contract, not from guessing at source files.

Context. lekalo context projects the minimal-but-sufficient context capsule for one symbol under a token budget, protected semantic facts as typed records, never collapsed into prose, with no source bytes, secrets or absolute paths leaking into the capsule. For an agent with a token window, that's precisely the shape of useful context.

Traceability. The model connects requirements → symbols → tests → gates in a neutral trace manifest, so "does this change have evidence?" is a query, not an archaeology project.

The honest cost is the one you've spotted: the model must be maintained. The counterargument is that this kit already maintains a canonical spec in openspec/specs/ and a roadmap, the project's conventions treat "describe the intent separately from the code" as normal practice. Lekalo takes the same instinct and makes it machine-readable.

The finale is one part away

You now have every ingredient: the language (parts 1-2), the tooling and quality (parts 3-4), and the model layer (this part). Part 6 runs the whole thing end-to-end on the Users model in this repository, validation, dependency graphs, impact analysis and context capsules, live:

next: Lekalo deep dive, the finale

Sources

Comments (0)

No comments yet — be the first to react.

Reader questions (0)

No questions yet — be the first to ask.

Stuck on something in this article? Ask below. Your name is shown publicly; your email is never stored. A question appears here once a moderator approves it.