OKHAM.org Documentación EnglishCastellano

Edición publicada en febrero de 2026

Documento original en inglés

OKHAM Implementer Guide

Target Audience: Developers, architects, and teams implementing OKHAM standards in production systems.


Overview

This guide provides implementation-grade guidance for adopting OKHAM standards. It assumes no specific runtime, framework, or language—OKHAM contracts are implementation-agnostic.

Key Principle: OKHAM defines what systems agree on (contracts), not how they implement it (code).


Minimal Compliance Requirements

To claim compliance with an OKHAM contract, you MUST:

  1. Implement the contract structure as defined in SPECIFICATION.md
  2. Validate artifacts against the contract's JSON Schema
  3. Preserve semantic meaning as specified in the contract
  4. Use correct versioning according to the contract's versioning rules

You do NOT need:

  • A specific runtime or framework
  • A specific programming language
  • A specific transport protocol
  • A specific storage backend

Golden Path: Implementation Sequence

This is the recommended order for implementing OKHAM standards. You can adopt incrementally—start with one contract and expand as needed.

Phase 1: Type Interoperability (OTC)

Goal: Establish shared type vocabulary across system boundaries.

Steps:

  1. Read OTC SPECIFICATION.md
  2. Identify types that cross system boundaries in your architecture
  3. Define types using OTC structure:
    • id: Unique type identifier (e.g., [email protected])
    • name: Human-readable type name
    • version: Semantic version
    • schema: JSON Schema definition
    • semantics: Semantic metadata (purpose, constraints, relationships)
  4. Validate types against OTC JSON Schema
  5. Publish types to a shared registry (optional but recommended)
  6. Implement type resolution in your services

Minimal Viable Implementation:

{
  "id": "[email protected]",
  "name": "User",
  "version": "1.0.0",
  "schema": {
    "type": "object",
    "properties": {
      "id": { "type": "string" },
      "email": { "type": "string", "format": "email" }
    },
    "required": ["id", "email"]
  },
  "semantics": {
    "purpose": "Represents a user account in the system"
  }
}

Compliance Checklist:

  • [ ] Types have unique IDs with semantic versioning
  • [ ] Types include JSON Schema definitions
  • [ ] Types include semantic metadata
  • [ ] Types validate against OTC schema
  • [ ] Type references use full IDs (not just names)

Phase 2: Event-Driven Observability (OEC)

Goal: Standardize events as immutable facts with causality chains.

Steps:

  1. Read OEC SPECIFICATION.md
  2. Identify events in your system (domain events, integration events, system events)
  3. Define events using OEC structure:
    • id: Unique event identifier
    • type: Event type (semantic classification)
    • timestamp: ISO 8601 timestamp
    • source: Event source (capability, service, component)
    • data: Event payload (typed using OTC)
    • causation: Causality chain (parent event IDs)
    • correlation: Correlation ID for tracing
  4. Validate events against OEC JSON Schema
  5. Implement event emission in your services
  6. Implement event consumption with causality tracking

Minimal Viable Implementation:

{
  "id": "evt_123456",
  "type": "[email protected]",
  "timestamp": "2024-01-16T10:30:00Z",
  "source": "user-service",
  "data": {
    "userId": "user_789",
    "email": "[email protected]"
  },
  "causation": [],
  "correlation": "corr_abc123"
}

Compliance Checklist:

  • [ ] Events have unique IDs
  • [ ] Events have semantic types (not generic "event")
  • [ ] Events include ISO 8601 timestamps
  • [ ] Events include source identification
  • [ ] Events include causation chains
  • [ ] Events validate against OEC schema
  • [ ] Event data uses OTC-defined types

Phase 3: Declarative Governance (OPC)

Goal: Define engine-independent policies for governance and compliance.

Steps:

  1. Read OPC SPECIFICATION.md
  2. Identify governance requirements (access control, validation, rate limiting, compliance)
  3. Define policies using OPC structure:
    • id: Unique policy identifier
    • name: Human-readable policy name
    • version: Semantic version
    • effect: Policy effect (allow, deny, condition)
    • rules: Policy rules (conditions and actions)
    • scope: Policy scope (resources, capabilities, events)
  4. Validate policies against OPC JSON Schema
  5. Implement policy evaluation engine (or use existing engine)
  6. Integrate policy enforcement in your services

Minimal Viable Implementation:

{
  "id": "[email protected]",
  "name": "Admin Only Policy",
  "version": "1.0.0",
  "effect": "deny",
  "rules": [
    {
      "condition": "user.role != 'admin'",
      "action": "deny",
      "message": "Only admins can perform this action"
    }
  ],
  "scope": {
    "capabilities": ["com.example.DeleteUser"]
  }
}

Compliance Checklist:

  • [ ] Policies have unique IDs with semantic versioning
  • [ ] Policies have clear effects (allow/deny/condition)
  • [ ] Policies include explicit rules
  • [ ] Policies define scope (what they apply to)
  • [ ] Policies validate against OPC schema
  • [ ] Policy evaluation is deterministic

Phase 4: UI Component Portability (OUCC)

Goal: Preserve UI component semantics across rendering engines.

Steps:

  1. Read OUCC SPECIFICATION.md
  2. Identify UI components that need portability
  3. Define components using OUCC structure:
    • id: Unique component identifier
    • name: Human-readable component name
    • version: Semantic version
    • props: Component properties (typed using OTC)
    • slots: Component slots (children, content)
    • semantics: Semantic metadata (purpose, accessibility)
  4. Validate components against OUCC JSON Schema
  5. Implement component rendering in your UI framework
  6. Implement component composition

Minimal Viable Implementation:

{
  "id": "[email protected]",
  "name": "Button",
  "version": "1.0.0",
  "props": {
    "label": { "type": "string", "required": true },
    "variant": { "type": "string", "enum": ["primary", "secondary"] }
  },
  "slots": {
    "icon": { "optional": true }
  },
  "semantics": {
    "purpose": "Interactive button for user actions",
    "accessibility": {
      "role": "button",
      "keyboard": true
    }
  }
}

Compliance Checklist:

  • [ ] Components have unique IDs with semantic versioning
  • [ ] Components define typed props
  • [ ] Components define slots (if applicable)
  • [ ] Components include semantic metadata
  • [ ] Components include accessibility metadata
  • [ ] Components validate against OUCC schema

Phase 5: Business Flow Composition (OBC) — Optional

Goal: Define declarative business flows with semantic meaning.

Steps:

  1. Read OBC SPECIFICATION.md (when available)
  2. Identify business processes that need orchestration
  3. Define flows using OBC structure (specification pending)
  4. Validate flows against OBC JSON Schema
  5. Implement flow execution engine
  6. Integrate flow monitoring and observability

Status: OBC is currently PLANNED. Check documentation for updates.


Phase 6: Accessibility Obligations (OAC) — Optional

Goal: Define normative accessibility requirements and evidence.

Steps:

  1. Read OAC SPECIFICATION.md (when available)
  2. Identify accessibility requirements for your UI components
  3. Define obligations using OAC structure (specification pending)
  4. Validate obligations against OAC JSON Schema
  5. Implement accessibility testing and evidence collection
  6. Integrate accessibility compliance reporting

Status: OAC is currently PLANNED. Check documentation for updates.


Reference Resolution Rules

OKHAM contracts use fully qualified identifiers for references. Follow these rules:

ID Format

{namespace}.{name}@{version}

Examples:

Versioning Rules

OKHAM uses semantic versioning (MAJOR.MINOR.PATCH):

  • MAJOR: Breaking changes (incompatible API changes)
  • MINOR: Backward-compatible additions
  • PATCH: Backward-compatible bug fixes

Version Resolution:

  • Exact match: [email protected] (specific version)
  • Major version: com.example.User@1 (latest 1.x.x)
  • Latest: com.example.User (latest version, not recommended for production)

Cross-Contract References

When one contract references another:

  1. Use full IDs: Always include namespace, name, and version
  2. Validate references: Ensure referenced contracts exist and are accessible
  3. Track dependencies: Maintain dependency graphs for impact analysis

Example: OEC event referencing OTC type

{
  "id": "evt_123",
  "type": "[email protected]",
  "data": {
    "$type": "[email protected]",
    "id": "user_789",
    "email": "[email protected]"
  }
}

Compatibility Expectations

Backward Compatibility

Within a MAJOR version, implementations MUST maintain backward compatibility:

  • MINOR version changes: Add new optional fields, do not remove or change existing fields
  • PATCH version changes: Fix bugs, do not change behavior

Breaking Changes

MAJOR version changes indicate breaking changes:

  • Removing fields
  • Changing field types
  • Changing field semantics
  • Changing validation rules

Migration Path: Provide migration guides for MAJOR version changes.


Validation Strategy

Schema Validation

All OKHAM contracts include JSON Schema definitions. Use standard JSON Schema validators:

Languages:

  • JavaScript/Node.js: ajv, jsonschema
  • Python: jsonschema, pydantic
  • Go: gojsonschema, jsonschema
  • Java: everit-org/json-schema, networknt/json-schema-validator
  • Rust: jsonschema-rs

Example (JavaScript):

const Ajv = require('ajv');
const ajv = new Ajv();

const otcSchema = require('./otc-schema.json');
const validate = ajv.compile(otcSchema);

const type = {
  id: "[email protected]",
  name: "User",
  version: "1.0.0",
  schema: { /* ... */ },
  semantics: { /* ... */ }
};

const valid = validate(type);
if (!valid) {
  console.error(validate.errors);
}

Semantic Validation

Beyond schema validation, validate semantic correctness:

  • Type references: Ensure referenced types exist
  • Event causation: Ensure parent events exist
  • Policy scope: Ensure scoped resources exist
  • Component props: Ensure prop types are valid

Artifact Management

Storage

OKHAM contracts can be stored in:

  • File system: JSON/YAML files in version control
  • Database: Document store (MongoDB, PostgreSQL JSONB)
  • Registry: Dedicated contract registry (OCC-compliant)
  • Key-Value Store: Redis, etcd, NATS KV

Recommendation: Use version control (Git) as the source of truth.

Discovery

Implement contract discovery mechanisms:

  • Registry API: HTTP API for querying contracts
  • File-based discovery: Scan directories for contract files
  • Service mesh: Integrate with service mesh metadata
  • NATS KV: Use NATS Key-Value store for distributed discovery

Versioning

Store multiple versions of contracts:

contracts/
  types/
    [email protected]
    [email protected]
    [email protected]
  events/
    [email protected]
  policies/
    [email protected]

Testing Strategy

Unit Tests

Test contract validation:

describe('OTC Type Validation', () => {
  it('should validate a valid type', () => {
    const type = { /* valid OTC type */ };
    expect(validateOTC(type)).toBe(true);
  });

  it('should reject an invalid type', () => {
    const type = { /* invalid OTC type */ };
    expect(validateOTC(type)).toBe(false);
  });
});

Integration Tests

Test cross-contract references:

describe('OEC Event with OTC Type', () => {
  it('should validate event with valid type reference', () => {
    const event = {
      id: "evt_123",
      type: "[email protected]",
      data: {
        $type: "[email protected]",
        id: "user_789"
      }
    };
    expect(validateEvent(event)).toBe(true);
  });
});

Compliance Tests

Test OKHAM compliance:

describe('OKHAM Compliance', () => {
  it('should have unique IDs', () => {
    const types = loadAllTypes();
    const ids = types.map(t => t.id);
    expect(new Set(ids).size).toBe(ids.length);
  });

  it('should use semantic versioning', () => {
    const types = loadAllTypes();
    types.forEach(t => {
      expect(t.version).toMatch(/^\d+\.\d+\.\d+$/);
    });
  });
});

Common Pitfalls

❌ Pitfall 1: Mixing Implementation with Contracts

Wrong:

{
  "id": "[email protected]",
  "runtime": "nodejs",
  "database": "postgresql"
}

Right:

{
  "id": "[email protected]",
  "name": "User",
  "schema": { /* ... */ },
  "semantics": { /* ... */ }
}

Reason: OKHAM contracts define meaning, not implementation details.


❌ Pitfall 2: Using Generic Names

Wrong:

{
  "id": "[email protected]"
}

Right:

{
  "id": "[email protected]"
}

Reason: Use fully qualified namespaces to avoid collisions.


❌ Pitfall 3: Skipping Semantic Metadata

Wrong:

{
  "id": "[email protected]",
  "schema": { /* ... */ }
}

Right:

{
  "id": "[email protected]",
  "schema": { /* ... */ },
  "semantics": {
    "purpose": "Represents a user account",
    "constraints": ["email must be unique"]
  }
}

Reason: Semantic metadata preserves meaning beyond structure.


❌ Pitfall 4: Breaking Backward Compatibility

Wrong (MINOR version change):

// v1.1.0 - BREAKING CHANGE in MINOR version
{
  "id": "[email protected]",
  "schema": {
    "properties": {
      "id": { "type": "number" } // Changed from string to number
    }
  }
}

Right (MAJOR version change):

// v2.0.0 - Breaking change in MAJOR version
{
  "id": "[email protected]",
  "schema": {
    "properties": {
      "id": { "type": "number" }
    }
  }
}

Reason: Breaking changes require MAJOR version bumps.


Performance Considerations

Caching

Cache validated contracts to avoid repeated validation:

const contractCache = new Map();

function getContract(id) {
  if (contractCache.has(id)) {
    return contractCache.get(id);
  }
  const contract = loadContract(id);
  validateContract(contract);
  contractCache.set(id, contract);
  return contract;
}

Lazy Loading

Load contracts on-demand, not at startup:

// Bad: Load all contracts at startup
const allContracts = loadAllContracts(); // Slow startup

// Good: Load contracts on-demand
function getContract(id) {
  return loadContract(id); // Fast startup
}

Batch Validation

Validate multiple contracts in parallel:

const contracts = [contract1, contract2, contract3];
const results = await Promise.all(
  contracts.map(c => validateContract(c))
);

Monitoring & Observability

Contract Usage Metrics

Track contract usage:

  • Type usage: Which types are most referenced
  • Event frequency: Which events are most emitted
  • Policy evaluations: Which policies are most evaluated
  • Component renders: Which components are most rendered

Validation Failures

Monitor validation failures:

  • Schema validation errors: Track which contracts fail validation
  • Reference errors: Track broken references
  • Version conflicts: Track version mismatches

Compliance Reporting

Generate compliance reports:

  • Coverage: Which contracts are implemented
  • Versioning: Which versions are in use
  • Dependencies: Which contracts depend on others

Migration Strategy

Migrating Existing Systems

  1. Audit existing contracts: Identify types, events, policies, components
  2. Map to OKHAM contracts: Define OKHAM-compliant versions
  3. Implement adapters: Create adapters for legacy systems
  4. Gradual rollout: Migrate one contract at a time
  5. Deprecate legacy: Mark legacy contracts as deprecated
  6. Remove legacy: Remove legacy contracts after migration period

Coexistence

OKHAM contracts can coexist with legacy systems:

  • Adapters: Convert legacy formats to OKHAM contracts
  • Dual-write: Write to both legacy and OKHAM formats
  • Gradual migration: Migrate services incrementally

Next Steps

  1. Choose a contract: Start with OTC (types) or OEC (events)
  2. Read the specification: Study the normative requirements
  3. Implement validation: Set up JSON Schema validation
  4. Define contracts: Create your first OKHAM-compliant contracts
  5. Test compliance: Validate contracts against schemas
  6. Integrate: Use contracts in your services
  7. Monitor: Track usage and compliance

Additional Resources


Remember: OKHAM is implementation-agnostic. Adopt what you need, when you need it.