The Microship Protocol

MSP 0.1.1-beta.1 · Public beta

Copyright © 2026 Lucas Nicolás Masiero. Specification text, diagrams, and illustrative examples are licensed under CC BY 4.0.

What is MSP?

The Microship Protocol (MSP) defines how to design and implement software components called mships.

An mship’s I/O consists of input and output interfaces, also called ports. IN holds the interfaces the mship provides to callers. OUT holds the interfaces it requires from its environment.

Mship I/O pinout The mship provides interface I on IN and requires interface O on OUT. The adapter on each side points to the interface it binds. I O mship IN OUT Adapter Adapter Provided interface Required interface

The pinout shows what to connect. Its arrows point from adapters to the interfaces they bind. Schematic traces show runtime interactions.

How does MSP work?

The two phases of MSP 1. Mship Architecture 2. Mship Assembly Contracts Layout SVG Scaffold Implement Bind and start

1. Mship Architecture

Define what the mship provides and requires, then draw its components and the traces between them.

Grid space · proposed

Empty mship layout grid A package contains IN, CORE, and OUT grids. A nested grid G in CORE starts at row zero, column one, and spans two rows and two columns. The grid contains no component nodes. IN CORE OUT G 1 2 0 3 0 1 2

Area Responsibility
IN Provided ports, transport dispatch, and handlers
CORE Flows and domain logic
OUT Required interfaces, their implementations, and adapters

An area is a grid with an architectural role, and each child occupies a rectangle in its parent grid. Here GG starts at (0,1)(0,1) and spans 2×22 \times 2 cells.

Component toolkit

MSP schematic toolkit Interface or port i is a circle, concrete implementation c is a square, adapter a is a triangle, and controller ct is a diamond. The concrete roles use squares for implementation c, factory f, and builder b. Controller policies share the diamond. Solid traces are synchronous and dotted traces asynchronous. A head points to the receiver. On a headless trace either endpoint can initiate. Brackets show a timeout wrapping a rate limiter that wraps a concrete implementation. Component kinds Concrete roles Controller policies Flow traces Wrapper chain i c a ct c f b L C P B Q T LB BP D I T L c Interface (port) Concrete implementation Adapter Controller Concrete implementation Concrete factory Concrete builder Rate limiter Cache Worker pool Circuit breaker Queue Timeout Load balancer Backpressure Deduplication Isolation One initiator Either can initiate Synchronous Asynchronous

A direction u→vu\to v adds one to the out-degree of uu and the in-degree of vv. A headless trace contributes both directed edges.

Layout multiplicities · proposed

Layout multiplicities The root grid has no parent. Each other grid and each node has exactly one parent grid. A grid can contain zero or more child grids and nodes. Spatial containment Parent grid contains Grid Grid contains Node

Read each endpoint from the opposite entity. In crow’s-foot notation, a circle means zero, a bar means one, and a fork means many.

The root grid has zero parents. Every other grid and every node has exactly one parent.

Example · mship

Example mship on the MSP layout grid HTTP handler h invokes provided interface I. In CORE, timeout T wraps flow fl. The flow calls core cr and persistence interface O. Adapter a translates calls from O to SQL client interface S. The flow publishes events through interface E and RabbitMQ adapter R. IN CORE OUT G I h T fl cr O a S E R

Area Components
IN h HTTP handler, II records interface
CORE TT timeout, fl flow, cr domain rules
OUT OO Persistence interface, aa SQL adapter, SS SQL client interface, EE event interface, RR RabbitMQ adapter

For a read, fl calls Find through OO, and aa translates that call into a query on SS. Find returns matching records, an empty collection when nothing matches, or a storage error. The flow applies cr to the returned records and propagates storage errors. A write can also hand off an event through EE.

Geometry and validation · proposed

For a parent with RR rows and CC columns, a child starts at (r,c)(r,c) and spans (h,w)(h,w) cells.

0≤r<r+h≤R,0≤c<c+w≤C 0\le r<r+h\le R,\qquad 0\le c<c+w\le C
  • Keep sibling allocations disjoint. Every component outline and label fits its allocation.
  • Use a 32×3232 \times 32 node bounding box in SVG units before stroke. Labels use one or two characters.
  • Route traces between node outlines and around unrelated nodes. A crossing alone carries no connection.
  • Keep controller nesting explicit and acyclic.

One grid overrides the stroke width inherited by its nodes H Stroke width 3 X Inherits 3 from H R Stroke width 2 Y Inherits 2 from R

For child vv with parent aa, local position q(v)q(v) adds to the parent’s absolute position. Drawing properties inherit through SVG groups unless overridden.

p(v)=p(a)+q(v) p(v)=p(a)+q(v)

MSP defines the schematic model. MSN is planned as a declarative way to author it. Its status as a normative interchange format is open.

2. Mship Assembly

In this proposed assembly, startup supplies the OUT interfaces, wires the CORE flows and IN handlers, then starts accepting traffic.

Connected mship architecture In IN, multiplexer m registers routes r. Each route is paired one-to-one with an entry flow fl in CORE through its handler h. A flow can use domain rules cr and required interface i independently. In OUT, the selected concrete implementation c supplies i. IN CORE OUT m r fl cr i c registers via h uses uses implemented by

IN · Provided interfaces

Each IN interface declares one fixed transport, HTTP or gRPC. Multiplexer m dispatches by method and path for HTTP or by service method for gRPC. Each route entry r is paired one-to-one with an entry flow fl. Handler h translates the request into the flow’s input and maps its result back to the transport.

CORE · Flows and domain rules

Each entry flow fl runs a use case. It calls cr for domain rules and uses OUT interfaces i for infrastructure. Flows can share domain rules and OUT implementations. The read flow, for example, obtains records through Persistence and passes them to cr.

OUT · Required interfaces

Supplying an OUT interface Each factory f supplies one interface i. An interface can have zero or more factories. A factory registers one or more choices of concrete implementation c. Each registered choice belongs to one factory. The profile selects one c for the factory to build and return as i. i f c Interface (port) Factory Concrete implementation returns as i registers choices

At startup, factory f reads the selection and parameters for its key in the active profile. It selects one registered concrete implementation c, delegates construction to builder b, and returns the result as i for the flow. The f–c crow’s feet count the available choices.

For Persistence, the in-memory choice implements i directly. The SQLite choice builds an adapter that presents i and calls the SQL client interface.

cfg=map[fKey]fValuefValue=(cKey, cParams) \begin{aligned} \texttt{cfg} &= \texttt{map[fKey]fValue}\\ \texttt{fValue} &= (\texttt{cKey},\ \texttt{cParams}) \end{aligned}
Example profile and startup

The loader uses .config/init.toml to select a profile and rejects duplicate factory entries. Each factory looks up its settings by fKey.

.config/init.toml

profile = "local"

.config/profiles/local.toml

[out.store]
cKey = "sqlite"

[out.store.cParams]
file = "records.db"

[out.events]
cKey = "rabbit"

[out.events.cParams]
exchange = "mship.events"
urlEnv = "MSHIP_AMQP_URL"

In the Go-style pseudocode, try propagates an error. f switches on cKey and passes the decoded cParams to the selected builder b.

func (fl ReadFlow) Run(q Query) (Result, error) {
    records := try fl.store.Find(q.Filter)
    return fl.cr.Evaluate(q, records), nil
}

type fValue struct {
    cKey    string
    cParams Raw
}

type Config map[string]fValue

func f(cfg Config, fKey string) (Persistence, Close, error) {
    choice := try cfg.Require(fKey)

    switch choice.cKey {
    case "sqlite":
        p := try Decode[SQLiteParams](choice.cParams)
        return bSQLite(p)
    case "memory":
        p := try Decode[MemoryParams](choice.cParams)
        return bMemory(p)
    default:
        return nil, nil, UnknownImplementation(fKey, choice.cKey)
    }
}

func Run() error {
    cfg := try sdk.LoadConfig(".config")
    store, closeStore := try f(cfg, "out.store")
    defer closeStore()

    events, closeEvents := try BindEvents(cfg, "out.events")
    defer closeEvents()

    cr := NewRules()
    read := NewReadFlow(cr, store)
    write := NewWriteFlow(cr, store, events)
    m := NewMux()
    m.GET("/records", ReadHandler(read))
    m.POST("/records", WriteHandler(write))
    return ServeUntilShutdown(m)
}

Each builder cleans up its own partial resources on failure. If a later binding fails, Run closes the bindings it already constructed.

Assembly notation and Go scaffold
Symbol Meaning
i Interface (port)
c Concrete implementation
f Factory that selects and builds one c to supply i
a Adapter that exposes an interface by translating calls to another interface or concrete implementation
b Builder for a concrete implementation
m Multiplexer
r Route entry
h Handler
fl Entry flow
cr Core domain rules
ct Controller
Role Path Owns
— design/ Schematic and port contracts
— bin/entry Profile loading, construction, and startup
in in/ Transport dispatch and handlers for HTTP or gRPC
fl · flow internal/flow/ Use-case orchestration across core and OUT
cr · core internal/core/ Domain rules
out out/<capability>/ Required interfaces, concrete implementations, and adapters
— .config/ Profile selection and binding parameters

Beta conformance

An mship claiming conformance with this edition must meet four requirements.

  1. Publish the contracts. Identify the mship release and MSP edition. Name the provided and required interfaces. Document their operations or messages, inputs, outputs, and failures. Specify synchronous or asynchronous interactions, any delivery, ordering, or timing guarantees, and the transport mappings callers use.
  2. Show the architecture. Map schematic interfaces to their contracts. Show interactions through IN, CORE, and OUT. CORE uses interfaces defined by the mship to access infrastructure.
  3. Bind before serving. Supply a compatible implementation for every required interface before IN accepts traffic.
  4. Clean up failed startup. If assembly fails, stop before IN accepts traffic and release resources acquired during that attempt, including resources from partial construction.

Checks for the first implementation · proposed

Exercise Expected behavior
Run the same reads through the SQLite and in-memory implementations with matching data, no matches, and a storage failure. Equivalent cases give the same result or documented failure through the provided interface.
Start with missing factory settings, a duplicate factory entry, an unknown choice, or invalid parameters. Startup fails before IN accepts traffic.
Fail event adapter construction after opening storage. Startup fails before IN accepts traffic and cleans up storage and any partially acquired event resources.

Open decisions

Glossary and schematic labels
Term Meaning
MSP Microship Protocol
mship Microship, a software component with explicit provided and required ports
MSN Microship Schematic Notation
SVG Scalable Vector Graphics, the schematic output format
IN / CORE / OUT Provided interfaces and transport / flows and domain / required interfaces and infrastructure
Interface / port Contract an mship provides or requires
Adapter Component that exposes one interface by translating calls to another interface or concrete implementation
Controller / wrapper Operational policy applied around a component, such as a timeout
Binding / profile Supplying a required interface with an implementation / a named collection of implementation selections and settings
Multiplicity The number of instances allowed at one end of a relationship for one instance at the other end
TOML Tom’s Obvious, Minimal Language, the example profile format
HTTP / RPC / gRPC Hypertext Transfer Protocol / remote procedure call / the gRPC framework for RPC
AMQP Advanced Message Queuing Protocol
SQL / SQLite / RabbitMQ Structured Query Language / an embedded SQL database / a message broker
CLI / SDK Command-line interface / software development kit
Symbol Meaning
I, O, S, E, R, TI,\ O,\ S,\ E,\ R,\ T Provided interface, storage interface, SQL client interface, event interface, RabbitMQ adapter, timeout wrapper
G, (r,c), (h,w)G,\ (r,c),\ (h,w) Grid, origin, row and column spans
cfg, fKey Loaded configuration map, key for a factory entry
fValue Profile settings for one factory entry
cKey, cParams Concrete implementation key and its parameters
Close, Raw Cleanup function, undecoded adapter settings