Algebraic code generation from domain schemas

Write a .morph schema once. Generate branded types, REST APIs, CLIs, MCP servers, VS Code extensions, web UIs, and more — all mechanically correct.

Quick Start

bunx @morphdsl/cli generation:new-project pastebin --schema-file pastebin.morph
cd pastebin && bun install
bun run --filter '@pastebin/api' start

Example Schema

domain Pastebin

extensions {
  storage [memory, sqlite, redis] default memory
}

context pastes "Simple pastebin for sharing text snippets." {

  @root
  entity Paste "A text snippet shared via URL." {
    content: string "The paste content"
    createdAt: string "When the paste was created"
    title: string "Optional title for the paste"
  }

  @cli @api @ui
  command createPaste "Create a new paste."
    writes Paste
    input {
      content: string "The paste content"
      title?: string "Optional title"
    }
    output Paste
    emits PasteCreated "Emitted when a new paste is created"

  @cli @api @ui
  query listPastes "List all pastes."
    reads Paste
    input {}
    output Paste[]
}

Open in Playground →

Features

One Schema, 13 Targets

REST API, CLI, MCP server, VS Code extension, web UI, HTTP client, protocol buffers, property tests, formal verification — all from a single .morph file.

Deterministic Generation

No LLMs in the pipeline. Every transformation is mechanical and structure-preserving. If the core is correct, derived apps are correct by construction.

Algebraic Foundations

Built on Lawvere's functorial semantics. A .morph schema defines an algebraic theory; each generator is a structure-preserving functor.

Pure Business Logic

You write only domain handlers and scenario tests. Everything else — types, routes, commands, UI, client code — is generated.

Pluggable Extensions

5 storage backends (memory, JSON, SQLite, Redis, event-sourced), multiple auth strategies, domain events — all swappable via environment variables.

Property-Based Testing

Scenarios run as algebraic laws across multiple targets. If core passes but API fails, the natural transformation has a bug — the diagram doesn't commute.

Generation Targets

TargetWhat it produces
dslBranded IDs, Effect schemas, operation descriptors
coreHandler interfaces, repository ports, DI layers
apiREST routes, OpenAPI spec, SSE event streams
cliInteractive REPL and one-off commands
mcpMCP server exposing operations as LLM tools
uiServer-rendered web UI (Pico CSS)
vscodeVS Code extension with DSL language support
clientType-safe HTTP client library
protoProtocol buffer definitions
verificationSMT-LIB2 formal verification (Z3)