typed-service-contracts

Enforce TypeScript service contracts with Spec-and-Handler patterns.

Updated May 5, 2025
One-click install
npx skills add https://github.com/yopitek/Obsidian --skill typed-service-contracts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typed-service-contracts
Source: https://github.com/yopitek/Obsidian/tree/main/HQ/10_resources/03_writing_prompts/stittch_design_md/.agents/skills/typed-service-contracts
Command: npx skills add https://github.com/yopitek/Obsidian --skill typed-service-contracts

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Architecture standard for building robust, type-safe TypeScript services by applying the Spec and Handler pattern, enabling clear boundaries between input parsing, business logic, and error handling.

Core Features & Use Cases

  • Vertical Slice Architecture with Design by Contract (DbC) principles that treat each user request as a unit of work.
  • The Spec (spec.ts) defines input parsing, output contracts, error schemas, a Result type, and the capability interface.
  • The Handler (handler.ts) implements the contract, performs side effects, and maps errors into the Result pattern for deterministic behavior.

Quick Start

Define the Contract (spec.ts), implement the Handler (handler.ts), and write contract and logic tests to verify behavior.

Frequently Asked Questions about typed-service-contracts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors as values instead of exceptions in TypeScript services?

To handle errors as values in TypeScript, define a discriminated Result type within a Spec and implement a Handler that catches parsing or business logic failures and maps them into the Result. This ensures the Handler never throws exceptions, returning deterministic outputs.

What is the Spec and Handler pattern for building type-safe TypeScript apps?

The Spec and Handler pattern is an architecture standard that separates input parsing, business logic, and error handling. A Spec defines schemas and a Result type, while a Handler implements the contract and maps errors into the Result for deterministic behavior.

How do I enforce a strict contract between input parsing and business logic in TypeScript?

Enforce a strict contract by creating a Spec that defines explicit input, output, and error schemas alongside a capability interface. The Handler then implements this contract, ensuring side effects strictly follow the defined Result type boundaries.

Does this Spec and Handler pattern work for both CLI tools and libraries?

Yes, the Spec and Handler pattern applies to CLIs, libraries, and complex business logic where inputs must be parsed. It treats each user request as a unit of work, making it suitable for various TypeScript application types.

What is the best way to structure TypeScript services for deterministic error handling?

The best way to structure deterministic error handling is using Design by Contract principles. Define a vertical slice architecture where a Spec outlines error schemas and the Handler maps failures into a discriminated Result type rather than throwing exceptions.

When should I not use error-as-value patterns in TypeScript architecture?

Avoid error-as-value patterns when your application relies on simple, linear logic where exception throwing is sufficient. This Spec and Handler architecture targets complex business boundaries requiring strict input parsing and deterministic Result mapping.