Mesh

Describe your domain once. Mesh builds the rest.

Your domain is what your program keeps, what can be done to it, and who may do it. In Mesh you write it down as one small .mesh.mx file per entity.

From those files Mesh builds your core domain and business logic as a module of typed TypeScript functions, with the input validation, the authorization, the database tables and the migrations. Connect that module to anything: an HTTP API, a command line, a worker, a user interface, an agent. Change a file and the module is rebuilt from it, so nothing drifts.

Read the introductionQuick start

Mesh is not released yet. These pages describe Mesh 1.0.

src/domain/todo/todo.mesh.mx
                                                                                                                                                
mesh build

Your app

Types todo.types.ts

from attributes, relationships

interface Todo { id: string; title: string; done: boolean; listId: string; insertedAt: Date } interface CreateTodoInput { title: string; list: List["id"] }

Functions todo.actions.ts

one per action, from actions, imported from #mesh

createTodo(input, context) pendingTodo(input, context) renameTodo, readTodo, destroyTodo

Input validation todo.validators.ts

Every input is checked before your code runs: no empty title, and no field the action does not accept.

from attributes, actions

Authorization in every function

A write is checked before it runs; a read gets the policy in its query. canCreateTodo asks first.

from policies

The database

The table schema.ts

The todos table, its columns and the foreign key to List, written by the data adapter.

from the entity line, attributes, relationships

Migrations migrations/*.sql

Plain SQL from mesh migrate generate when the table changes; applied by mesh migrate apply.

from the table

For your tools

Rules for agents rules.md

from the whole file

entity :Todo table="todos" actions auto=[:read, :destroy] create :create input &title &list

The model model.json

Every declaration with its source position: what mesh inspect prints.

from the whole file

Connect it to anything

Mesh is not a server and does not assume one. The module is your domain, and whatever you build around it calls the same functions, with the same checks.

  • An HTTP API. A route handler turns the request into an input and an actor, and calls the function. The HTTP layer stays yours.
  • A command line or a worker. A task calls the same function a request handler would, with the same validation and the same policies.
  • A user interface. The server side of your UI calls the functions directly; there is no client to generate and keep in step.
  • An agent. Give an agent's tool a function to call. The policies still decide what the agent's actor may do.

Ready for your agent

The less your agent writes, the less it can get wrong. With Mesh it writes one small declarative file per entity; everything else is built from that file by Mesh's own generators.

  • Fewer places to make a mistake. The types, functions, validators and checks are generated, the same for every project and the same on every build, instead of written fresh by the agent each time.
  • A smaller diff to review. You read the change to the entity file, the part that carries the intent. The generated code is committed beside it, but it follows from the file.
  • Less to write, less to read. One file is the whole truth about an entity, so an agent changing a rule reads and writes that file, not a model, a schema and a service layer.
  • Mistakes stop at build time, with a fix. A misspelled member in input is an error at that name, with the line, the column and a suggestion, which an agent can act on in one step.
  • Tools that answer instead of guessing. mesh build writes a rules file for the agent to read; mesh inspect prints the model with the source position of every declaration; mesh explain prints the plan a call will follow.

What the agent writes, and what it does not

It writes the 28 lines of todo.mesh.mx above. It does not write the types, the action functions, the input validators, the authorization checks, the table schema, the migration SQL, the rules file or the model: the diagram above shows where each comes from.

src/domain/todo/todo.mesh.mx:16:9 error &titel is not a member of :Todo.
Did you mean &title?

More in Working with AI agents: the rules file, mesh inspect, mesh explain, and what Mesh does not solve for an agent.

Mesh is open source under the MIT licence. It is modelled on Ash, the declarative resource framework for Elixir, and runs on Bun.