Cross-Repository API Contract Skill
Purpose
When implementing or consuming APIs that span multiple repositories, ensure type safety and contract adherence by working with locally available contract definitions.
Contract Discovery
Before implementing any API endpoint or client, check for contract definitions in these locations (in order of precedence):
api-contract/— This repo is the source of truth for the contract.contracts/— Synced copy from an external source repo (typically via CI)
If neither exists and you are implementing API endpoints, propose creating an api-contract/ directory following the standard structure.
Standard Contract Structure
api-contract/ (or .contracts/)
├── README.md # Purpose, sync instructions, change process
├── version.ts # Contract version and changelog
├── types.ts # TypeScript interfaces for all request/response/error shapes
└── endpoints.md # Human-readable endpoint documentation
Implementation Guidelines
When Implementing API Endpoints (Backend)
- Read
.contracts/types.ts(orapi-contract/types.ts) before writing handler code - Import or reference the types directly — do not redefine them
- Validate that Lambda/function request and response shapes match the contract exactly
- If the contract is missing fields you need, document as an OPEN QUESTION — do not add fields unilaterally
When Implementing API Clients (Extension/Frontend)
- Read
api-contract/types.tsbefore writing client code - Import types directly from the contract location
- Handle all error codes defined in the contract
- If the API behaves differently than the contract specifies, flag this as a bug
When Proposing Contract Changes
- Additive changes (new optional fields, new endpoints): Safe to propose inline
- Breaking changes (removing fields, changing types): Document as OPEN QUESTION with migration notes
- Always bump the version in
version.tswhen modifyingtypes.ts - Note that breaking changes require coordinated releases across repos
Contract Sync (For Consumer Repos)
If this repo consumes an external contract (indicated by .contracts/ existing):
- The contract is synced automatically via GitHub Actions
- Check
.github/workflows/sync-contract.ymlfor sync frequency - If contract seems stale, trigger the sync workflow manually
- Do not edit files in
.contracts/directly — they will be overwritten
Type Validation
When a repo has .contracts/ synced from an external source:
- Include a test that imports
.contracts/types.tsand validates handler I/O shapes - CI should fail if types don't match
- This catches contract drift before it causes runtime errors