Repository navigation
Contracts
For developers and architects: which contracts Compass is built against, where each one lives, how tests hold the code to them and how to change one safely.
Compass is contract first. Every boundary between parts has a written contract, and the code on both sides is generated from it or checked against it:
| Boundary | Contract | Where |
|---|---|---|
| MCP server and Pass service | The Compass API, OpenAPI 3.0.1 | contracts/compass-api.openapi.yaml |
| Compass and AWS | The official Events API, OpenAPI 3.1.0 | packages/contracts/events-api.openapi.json |
| MCP client and MCP server | The input and output schema of each of the 24 tools | packages/contracts/src/mcp-tools.ts |
| Every package | Shared zod schemas and types | packages/contracts |
flowchart LR
SRC[contracts/compass-api.openapi.yaml] -->|gen:copy| C1[packages/contracts/openapi.yaml]
SRC -->|gen:copy| C2[infra/modules/api/openapi.yaml]
C1 -->|gen:types| T1[src/generated/compass-api.ts]
EV[events-api.openapi.json] -->|gen:types| T2[src/generated/events-api.ts]
C2 -->|templatefile| APIGW[API Gateway REST API]
T1 --> Z[zod response schemas]
contracts/compass-api.openapi.yaml is the single source for the pass API. It defines all 16 operations, their parameters, request bodies, responses and errors. Pass API lists them.
It is OpenAPI 3.0.1 on purpose: the API Gateway REST import accepts Swagger 2.0 and OpenAPI 3.0, not 3.1. The same file also carries the API Gateway bindings, so the deployed API is built from the contract and cannot drift from it:
- every operation has an
x-amazon-apigateway-integrationof typeaws_proxyto one of two Lambda functions, written as one of exactly two Terraform placeholders,${api_lambda_invoke_arn}and${passkit_lambda_invoke_arn}; - two request validators,
all(body and parameters) andparams-only, and each operation names one; - the binary media types for Apple passes, pass bundles and calendar files;
- the API key read from the
x-api-keyheader.
Errors use application/problem+json with one Problem schema of exactly four fields: type, title, status and code. No field carries request input, so a bad request is never echoed back.
npm run gen:copy copies the source byte for byte to two places:
| Copy | Used for |
|---|---|
| packages/contracts/openapi.yaml | The input for the generated TypeScript types. |
| infra/modules/api/openapi.yaml | The body of the API Gateway REST API. infra/modules/api/main.tf reads it with templatefile(), passing only the two Lambda invoke values. |
Two checks guard the copies, both in CI:
-
npm run check:hashproves the three files have the same SHA-256. -
npm run check:placeholdersfails on anything account-specific in any of the three files: a twelve-digit run,arn:aws, a Terraform percent-brace marker, or a dollar-brace marker other than the two allowed placeholders.templatefile()evaluates every such marker, comments included, so a stray one would break the deploy.
A Terraform native test in infra/modules/api/tests also checks that main.tf reads the copy with exactly those two variables.
npm run gen:types runs openapi-typescript on both OpenAPI documents:
| Input | Output |
|---|---|
| packages/contracts/openapi.yaml | src/generated/compass-api.ts |
| packages/contracts/events-api.openapi.json | src/generated/events-api.ts |
Each file starts with a "Generated by openapi-typescript. Do not edit by hand." banner. Generated files are excluded from coverage and from type-aware lint. They are committed, so a clone builds without running the generator.
packages/contracts (@compass/contracts) has one public entry, src/index.ts, which re-exports every member by name:
| Part | What it holds |
|---|---|
| src/wire | zod schemas for the Events API wire shapes (session, schedule, event, personal time, bulk result), written to match the Events API document. Plain z.object strips unknown fields, so a new field from AWS never breaks parsing. |
| src/domain | Compass shapes: Commitment (a reserved session or personal time), NormalisedSession, Venue, Verdict. |
| src/mcp-tools.ts |
mcpTools: the input and output zod schema for each of the 24 tools. The server registers exactly these keys and parses every call with them. See MCP tools. |
| src/compass-api-schemas.ts | Strict zod schemas for the Compass API responses, each typed against the generated types, so a schema that drifts from the contract fails to compile. Both the pass service and the client import them. |
| src/pass-fields.ts, src/problem.ts | The pass content shape and the problem error shape. |
| events-api.openapi.json | The official Events API document. |
The Events API document is the one AWS publishes at https://api.awsevents.com/v1/openapi.json. The operator-run script packages/contracts/scripts/fetch-events-api.mjs fetches it and writes the exact response bytes atomically; on any failure it writes nothing. No test or CI job runs the fetch. The committed copy was last refreshed on 31 October 2026. A test in packages/contracts/test checks that the SHA-256 recorded for the document in the project's decision record (see Key decisions) matches the committed file, so a silent edit fails the build.
| Test | What it proves |
|---|---|
| openapi-conformance.test.ts | For all 12 Events API operations, the method, the path template and the query parameter names the client sends match the official document exactly. Every expectation is read from the document, keyed by operation id. |
| contract.test.ts | The two Lambda routers serve exactly the methods and paths in the Compass API contract, and every response to a generated request conforms to it. Bodies are checked with ajv against contracts/compass-api.openapi.yaml through openapi-validator.ts. |
| bulk-failure-codes.ts | A compile-time check in both directions: the nine known bulk failure codes must equal the BulkFailureCode enum in the generated Events API types. If AWS adds or removes a code, the build fails. |
| The contracts package tests | Schemas accept and strip unknown fields, reject malformed input without coercion, keep unknown enum values, and enforce the tool bounds (for example 1 to 10 session ids). |
At run time the same contracts are enforced:
- Every 2xx Events API response is parsed with its zod schema before use. A failure throws a
ValidationErrorthat names the operation only, never the body (validate.ts). - Every MCP tool call is parsed with its contract input schema before the handler runs.
- API Gateway validates request bodies and parameters against the contract before a Lambda runs, and each Lambda validates again.
- Write the change in the Kiro spec that owns the behaviour first. See Contributing.
- Edit contracts/compass-api.openapi.yaml only. Never edit the two copies.
- Run
npm run gen:copy, thennpm run gen:types. - Update the response schemas in compass-api-schemas.ts until
npx tsc -bcompiles, then the handlers and the client. - Run
npm run check:hash,npm run check:placeholdersandnpm test. The contract test fails until the pass service matches. - Commit the source, both copies and the generated file together.
The API Gateway body changes on the next deploy of the api module. See Release.
- Run
node packages/contracts/scripts/fetch-events-api.mjs. - Run
npm run gen:typesandnpx tsc -b. The bulk failure code check and the zod wire schemas show what changed. - Update the wire schemas, the recorded SHA-256 and the fixtures, then run
npm test.
Edit mcp-tools.ts. The tool registry in the MCP server is typed against its keys, so a tool that is added or removed without a matching handler fails to compile.
re:Invent Compass is an independent community project and is not affiliated with, endorsed by, or sponsored by Amazon Web Services. Boarding passes are unofficial: your re:Invent badge is your ticket. Licensed under Apache-2.0. Disclaimer · Repository · Project board
Get started
User guide
Architecture
- Overview
- Kiro Power
- MCP server
- Pass service
- Showcase site
- Flows
- AWS architecture
- Security
- Data and privacy
- Quality
Key decisions
- Index
- Product and scope
- Architecture
- Infrastructure
- Passes and wallets
- Security and privacy
- Delivery and tooling
Developer guide
Operations
Runbooks
How it was built
Reference
Links