Skip to content

Typed codec port pattern — domain never touches raw bytes for serde #480

Description

@flyingrobots

Migrated from Method backlog

GitHub Issues are now the live work tracker. Repository docs remain Method evidence.

Field Value
Source backlog docs/method/backlog/cool-ideas/PROTO_typed-codec-port-pattern.md
Archived source docs/archive/backlog/github-issue-migration-2026-06-01/docs/method/backlog/cool-ideas/PROTO_typed-codec-port-pattern.md
Original lane cool-ideas
Original id PROTO_typed-codec-port-pattern
Original legend PROTO
Original feature runtime-boundaries

Original backlog card

Typed codec port pattern — domain never touches raw bytes for serde

The ShardPort pattern (domain works with typed shard objects, port
adapter owns Uint8Array ↔ object conversion) generalizes to ALL ports.

Instead of ports returning Uint8Array and the domain decoding:

// Current — domain does serde
const raw: Uint8Array = await port.read(key);
const decoded = codec.decode(raw);  // domain is doing serde

Every port returns typed domain objects directly:

// Clean — port adapter owns serde
const shard: MetaShard = await shardPort.loadMeta(key);
// MetaShard is a typed domain object. Port decoded it.

This is SSTS P5 ("serialization is the codec's problem") taken to
its logical conclusion. The domain layer never imports a codec. Never
calls encode/decode. Never touches Uint8Array for serde purposes.
Bytes enter and leave through port adapters.

The domain can still work with Uint8Array when bytes ARE the domain
value (content blobs, binary attachments). The distinction: domain
bytes are content; adapter bytes are encoding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:architecturePrimary work area: architecture.priority:nextNext in line after active work.status:availableOpen and available for prioritization; not blocked or actively in progress.type:featureNew capability or product behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions