# hotragn/schemaport architecture

> Architecture diagram of the GitHub repository hotragn/schemaport, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hotragn/schemaport
- Repository: https://github.com/hotragn/schemaport

## Overview

#### Purpose and operating boundary
Schemaport is an offline Python preflight checker for AI-provider request JSON. It validates provider/model-specific request contracts and prompt-cache safety without sending requests, managing credentials, or calling external APIs. Its output is intended for developers, CI, and agent check-fix-recheck loops.

Core public package boundary: `src/schemaport/__init__.py`, `src/schemaport/contracts.py`, `src/schemaport/model.py`.

#### Entry points and invocation
The command-line entry point reads a JSON request file, requires a target model, optionally resolves an API surface, renders findings, and maps outcomes to process exit codes. Python callers use `check()` for parsed dictionaries or `check_file()` for files.

Paths: `src/schemaport/__main__.py`, `src/schemaport/cli.py`, `src/schemaport/__init__.py`.

#### Check orchestration
The engine is the central control-flow coordinator: load/select model profile and surface, run applicable analyzers against the immutable input request, aggregate structured findings into a report, and distinguish validation findings from operational errors (bad file/JSON/unknown model).

Paths: `src/schemaport/engine.py`, `src/schemaport/errors.py`, `src/schemaport/model.py`.

Primary flow is: request JSON + explicit model → profile/surface resolution → analyzer execution → report → text/JSON/SARIF serialization or Python result. The checker never crosses into provider transport.

#### Versioned contract-data layer
Rules are data-driven rather than hard-coded. The packaged dataset defines coverage, model/API-surface profiles, rule sets, severity/remediation, and evidence provenance. This separation lets provider-contract updates ship as audited package data while keeping analysis mechanics stable.

Paths: `src/schemaport/data/dataset.json`, `src/schemaport/data/profiles/openai-responses.json`, `src/schemaport/data/rule-sets/anthropic-messages.json`.

Profiles cover Anthropic Messages and OpenAI Responses/Chat Completions surfaces; ambiguous surface selection is an explicit safety boundary rather than silently applying potentially wrong rules.

#### Analysis stages
Structured-output analysis traverses provider request structures and applies supported-JSON-Schema and request-shape rules. Cache-safety analysis examines prompt/request ordering and detects content likely to disrupt prefix caching. Findings carry rule ID, severity, JSON path, explanation, remediation, and evidence basis.

Paths: `src/schemaport/analyzers/structured_output.py`, `src/schemaport/analyzers/cache_safety.py`, `src/schemaport/shapes.py`.

`shapes.py` likely centralizes traversal/path or schema-shape representation used to consistently pinpoint locations in arbitrary request JSON.

#### Findings and reporting interfaces
The internal report model is rendered through three stable consumer interfaces: human-readable terminal text, machine-readable JSON for scripts/agents, and SARIF for code-scanning systems. Output format and exit threshold make the same engine usable interactively and as a CI quality gate.

Paths: `src/schemaport/reporters/text.py`, `src/schemaport/reporters/json_report.py`, `src/schemaport/reporters/sarif.py`.

#### Runtime, packaging, and release integrity
Runtime is Python 3.10+ with no nonstandard dependencies. Contract data is bundled under the importable package, supporting deterministic offline execution. CI and release workflows protect the package; a dedicated contract-drift workflow plus data verifier indicate that contract-data correctness is a first-class release concern.

Paths: `pyproject.toml`, `.github/workflows/contract-drift.yml`, `tools/verify_contract_data.py`.

Main entry points: [`src/schemaport/engine.py`](https://github.com/hotragn/schemaport/blob/main/src/schemaport/engine.py) (Check engine), [`src/schemaport/contracts.py`](https://github.com/hotragn/schemaport/blob/main/src/schemaport/contracts.py) (Public contracts), [`src/schemaport/model.py`](https://github.com/hotragn/schemaport/blob/main/src/schemaport/model.py) (Profile selection), [`src/schemaport/analyzers/structured_output.py`](https://github.com/hotragn/schemaport/blob/main/src/schemaport/analyzers/structured_output.py) (Structured-output analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Invocation"]
  node_cli["CLI<br/>command entry<br/>[cli.py]"]
  node_main["Module entry point<br/>python entry<br/>[__main__.py]"]
  node_python_api["Python API<br/>public package<br/>[__init__.py]"]
end

subgraph group_core["Checking Engine"]
  node_engine{{"Check engine<br/>orchestrator<br/>[engine.py]"}}
  node_model["Profile selection<br/>model resolver<br/>[model.py]"]
  node_errors["Operational errors<br/>error model<br/>[errors.py]"]
  node_contracts_api["Public contracts<br/>result contracts<br/>[contracts.py]"]
  node_structured["Structured-output analysis<br/>analyzer"]
  node_cache["Cache-safety analysis<br/>analyzer<br/>[cache_safety.py]"]
  node_shapes["Request shape traversal<br/>shape utilities<br/>[shapes.py]"]
end

subgraph group_contracts["Contract Data"]
  node_dataset[("Coverage dataset<br/>package data<br/>[dataset.json]")]
  node_openai_profile["OpenAI surface profile<br/>profile data"]
  node_anthropic_rules["Anthropic rule set<br/>rule data"]
end

subgraph group_reporting["Results"]
  node_text_reporter["Terminal text<br/>reporter<br/>[text.py]"]
  node_json_reporter["JSON output<br/>reporter<br/>[json_report.py]"]
  node_sarif_reporter["SARIF output<br/>reporter<br/>[sarif.py]"]
end

subgraph group_release["Release Integrity"]
  node_packaging["Package definition<br/>packaging<br/>[pyproject.toml]"]
  node_contract_verifier["Contract-data verifier<br/>verification tool"]
  node_drift_workflow["Contract-drift CI<br/>workflow<br/>[contract-drift.yml]"]
end

node_main -->|"launches"| node_cli
node_cli -->|"checks request file"| node_engine
node_python_api -->|"checks dictionaries/files"| node_engine
node_engine -->|"resolves model and surface"| node_model
node_engine -->|"runs"| node_structured
node_engine -->|"runs"| node_cache
node_engine -->|"returns operational errors"| node_errors
node_engine -->|"produces report contracts"| node_contracts_api
node_model -->|"loads coverage"| node_dataset
node_model -->|"selects surface profile"| node_openai_profile
node_structured -->|"applies rules"| node_anthropic_rules
node_structured -->|"traverses request"| node_shapes
node_cache -->|"locates findings"| node_shapes
node_contracts_api -->|"renders"| node_text_reporter
node_contracts_api -->|"serializes"| node_json_reporter
node_contracts_api -->|"serializes"| node_sarif_reporter
node_packaging -->|"bundles"| node_dataset
node_contract_verifier -->|"verifies"| node_dataset
node_drift_workflow -->|"runs"| node_contract_verifier

click node_cli "https://github.com/hotragn/schemaport/blob/main/src/schemaport/cli.py"
click node_main "https://github.com/hotragn/schemaport/blob/main/src/schemaport/__main__.py"
click node_python_api "https://github.com/hotragn/schemaport/blob/main/src/schemaport/__init__.py"
click node_engine "https://github.com/hotragn/schemaport/blob/main/src/schemaport/engine.py"
click node_model "https://github.com/hotragn/schemaport/blob/main/src/schemaport/model.py"
click node_errors "https://github.com/hotragn/schemaport/blob/main/src/schemaport/errors.py"
click node_contracts_api "https://github.com/hotragn/schemaport/blob/main/src/schemaport/contracts.py"
click node_structured "https://github.com/hotragn/schemaport/blob/main/src/schemaport/analyzers/structured_output.py"
click node_cache "https://github.com/hotragn/schemaport/blob/main/src/schemaport/analyzers/cache_safety.py"
click node_shapes "https://github.com/hotragn/schemaport/blob/main/src/schemaport/shapes.py"
click node_dataset "https://github.com/hotragn/schemaport/blob/main/src/schemaport/data/dataset.json"
click node_openai_profile "https://github.com/hotragn/schemaport/blob/main/src/schemaport/data/profiles/openai-responses.json"
click node_anthropic_rules "https://github.com/hotragn/schemaport/blob/main/src/schemaport/data/rule-sets/anthropic-messages.json"
click node_text_reporter "https://github.com/hotragn/schemaport/blob/main/src/schemaport/reporters/text.py"
click node_json_reporter "https://github.com/hotragn/schemaport/blob/main/src/schemaport/reporters/json_report.py"
click node_sarif_reporter "https://github.com/hotragn/schemaport/blob/main/src/schemaport/reporters/sarif.py"
click node_packaging "https://github.com/hotragn/schemaport/blob/main/pyproject.toml"
click node_contract_verifier "https://github.com/hotragn/schemaport/blob/main/tools/verify_contract_data.py"
click node_drift_workflow "https://github.com/hotragn/schemaport/blob/main/.github/workflows/contract-drift.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_main,node_python_api toneBlue
class node_engine,node_model,node_errors,node_contracts_api,node_structured,node_cache,node_shapes toneAmber
class node_dataset,node_openai_profile,node_anthropic_rules toneMint
class node_text_reporter,node_json_reporter,node_sarif_reporter toneRose
class node_packaging,node_contract_verifier,node_drift_workflow toneIndigo
```

## Components

### Invocation

- [CLI](https://github.com/hotragn/schemaport/blob/main/src/schemaport/cli.py): command entry · Reads request files, selects output, and maps outcomes to exit codes. · `src/schemaport/cli.py`
- [Module entry point](https://github.com/hotragn/schemaport/blob/main/src/schemaport/__main__.py): python entry · `src/schemaport/__main__.py`
- [Python API](https://github.com/hotragn/schemaport/blob/main/src/schemaport/__init__.py): public package · Exposes check() and check_file() callers. · `src/schemaport/__init__.py`

### Checking Engine

- [Check engine](https://github.com/hotragn/schemaport/blob/main/src/schemaport/engine.py): orchestrator · Separates validation findings from operational errors. · `src/schemaport/engine.py`
- [Profile selection](https://github.com/hotragn/schemaport/blob/main/src/schemaport/model.py): model resolver · Resolves explicit model and API surface, rejecting ambiguity. · `src/schemaport/model.py`
- [Operational errors](https://github.com/hotragn/schemaport/blob/main/src/schemaport/errors.py): error model · `src/schemaport/errors.py`
- [Public contracts](https://github.com/hotragn/schemaport/blob/main/src/schemaport/contracts.py): result contracts · `src/schemaport/contracts.py`
- [Structured-output analysis](https://github.com/hotragn/schemaport/blob/main/src/schemaport/analyzers/structured_output.py): analyzer · Checks request shape and supported JSON Schema. · `src/schemaport/analyzers/structured_output.py`
- [Cache-safety analysis](https://github.com/hotragn/schemaport/blob/main/src/schemaport/analyzers/cache_safety.py): analyzer · Detects prompt ordering and content that disrupt prefix caching. · `src/schemaport/analyzers/cache_safety.py`
- [Request shape traversal](https://github.com/hotragn/schemaport/blob/main/src/schemaport/shapes.py): shape utilities · Provides consistent JSON-path location handling. · `src/schemaport/shapes.py`

### Contract Data

Versioned package data drives provider-specific validation.

- [Coverage dataset](https://github.com/hotragn/schemaport/blob/main/src/schemaport/data/dataset.json): package data · Defines coverage, rules, severity, remediation, and evidence. · `src/schemaport/data/dataset.json`
- [OpenAI surface profile](https://github.com/hotragn/schemaport/blob/main/src/schemaport/data/profiles/openai-responses.json): profile data · `src/schemaport/data/profiles/openai-responses.json`
- [Anthropic rule set](https://github.com/hotragn/schemaport/blob/main/src/schemaport/data/rule-sets/anthropic-messages.json): rule data · `src/schemaport/data/rule-sets/anthropic-messages.json`

### Results

- [Terminal text](https://github.com/hotragn/schemaport/blob/main/src/schemaport/reporters/text.py): reporter · `src/schemaport/reporters/text.py`
- [JSON output](https://github.com/hotragn/schemaport/blob/main/src/schemaport/reporters/json_report.py): reporter · Machine-readable output for scripts and agents. · `src/schemaport/reporters/json_report.py`
- [SARIF output](https://github.com/hotragn/schemaport/blob/main/src/schemaport/reporters/sarif.py): reporter · Code-scanning interchange output. · `src/schemaport/reporters/sarif.py`

### Release Integrity

- [Package definition](https://github.com/hotragn/schemaport/blob/main/pyproject.toml): packaging · Bundles offline Python runtime and contract data. · `pyproject.toml`
- [Contract-data verifier](https://github.com/hotragn/schemaport/blob/main/tools/verify_contract_data.py): verification tool · `tools/verify_contract_data.py`
- [Contract-drift CI](https://github.com/hotragn/schemaport/blob/main/.github/workflows/contract-drift.yml): workflow · Guards contract-data correctness during release. · `.github/workflows/contract-drift.yml`

## Connections

- Module entry point → CLI: launches
- CLI → Check engine: checks request file
- Python API → Check engine: checks dictionaries/files
- Check engine → Profile selection: resolves model and surface
- Check engine → Structured-output analysis: runs
- Check engine → Cache-safety analysis: runs
- Check engine → Operational errors: returns operational errors
- Check engine → Public contracts: produces report contracts
- Profile selection → Coverage dataset: loads coverage
- Profile selection → OpenAI surface profile: selects surface profile
- Structured-output analysis → Anthropic rule set: applies rules
- Structured-output analysis → Request shape traversal: traverses request
- Cache-safety analysis → Request shape traversal: locates findings
- Public contracts → Terminal text: renders
- Public contracts → JSON output: serializes
- Public contracts → SARIF output: serializes
- Package definition → Coverage dataset: bundles
- Contract-data verifier → Coverage dataset: verifies
- Contract-drift CI → Contract-data verifier: runs
